Home Java javaTutorial Summary of Java programming ideas

Summary of Java programming ideas

Jul 17, 2017 pm 01:57 PM
java Summarize notes

This chapter introduces the basic components of Java programs and realizes that almost everything in Java is an object.

Everything is an object

##Directory:

  • 2.1 Manipulate objects with references

  • 2.2 All objects must be created by you

  • 2.3 Never need to destroy objects

  • 2.4 Create new data types: classes

  • 2.5 Methods, parameters and return values

  • 2.6 Building a Java program

  • 2.7 Your first Java program

  • 2.8 Comments and embedded documentation

  • 2.9 Coding style

2.1 Manipulating objects with references

Everything is regarded as an object, and the manipulated identifier is actually a "reference" of the object. The remote control (reference) controls the TV (object). If you want to control the TV, you only need to use the remote control, and the remote control exists independently.

2.2 All objects must be created by you

Once you create a reference, you want it to be associated with a new Objects are associated, and the new operator is usually used to achieve this purpose.

String s = new String("Jiancheng");
Copy after login

 

五个不同的地方可以存储数据:

  • 寄存器:位于CPU内部,寄存器的数量极其有限,所以寄存器根据需求进行分配,速度最快。

  • 堆栈:位于通用RAM(随机访问寄存器)中,Java编译器必须知道存储在堆栈内所有数据的大小和生命周期,“堆栈指针”向下移动则分配新内存,向上移动则释放内存,速度仅次于寄存器,基本数据类型和引用存放在此。

  • 堆:位于RAM区,用于存放所有Java对象,编译器不用知道数据大小和生命周期.

  • 常量存储:常量值通常直接存放在程序代码内部。

  • 非RAM存储:完全存活在程序之外,不受程序的任何控制,例子是流对象持久化对象,在流对象中,对象转换成字节流,通常被发送到另一台机器。在"持久化"对象中,对象被存放于硬盘上,即使程序终止,它们仍可以保持自己的状态。

 9种基本类型:

 

boolean类型所占内存储空间的大小没有明确指定,仅定义为能够取字面值true或false。

高精度数字:

  • BigInteger:支持任意精度的整数

  • BigDecimal:支持任意精度的定点数

操作与对基本类型所能执行的操作相似,但必须以方法调用方式取代运算符方式来实现。

Java中的数组:
数组会被初始化,而且不能在它的范围之外被访问。这种范围检查,是以每个数组上少量的内存开销及运行时的下标检查为代价(换来安全性和效率)。

 2.3 永远不需要销毁对象

作用域:

------------------------------------------------------------------

对象的作用域:

Java的作用和基本类型差别很大,new创建一个Java对象后,它可以存活于作用域之外。只要你需要这个对象,就会一直保留下去,直到垃圾回收器辨别到该对象不会再被引用并释放该对象的内存空间,这样就消除了内存泄漏的问题。

2.4 创建新的数据类型:类

类决定了某一对象的外观与行为,确定了对象的类型。

基本成员默认值:

当变量作为类的成员使用时,Java才确保给定其默认值,来确保基本类型成员变量得到初始化(初始值可能不是你想要的,最好自己初始化)。注意默认初始化的方法不适用于非某个类的字段变量,忘记初始化,Java会在编译时给你返回一个错误。

2.6 构建一个Java程序

static关键字:

下面两种情况需要使用static

  • 只想为某特定域分配单一存储空间,而不去考虑究竟要创建多少对象。

  • 某个方法不与包含它的类的任何对象关联在一起,就是没有创建对象,也能够调用这个方法。

class StatiTest{  static i = 47; //可以直接StatiTest.i这样调用
}
Copy after login

StatiTest st1 = new StatiTest();
StatiTest st2 = new StatiTest();
where st1.i and st2.i point to the same storage space, so they have the same value.

static acts on a method. The difference is that it can be called without creating any object, class.method().

2.9 Coding style

## Camel case style:

  • class, the first letter of each word is capitalized

  • Methods, fields and objects, etc., the first letter of the first word is capitalized Lower case, the remaining first letters are capitalized

Summary:

This chapter is easy to understand and is useful for Java I have an overall understanding of language and some of its basic ideas, and I have been exposed to most knowledge points, but it is easy to forget the details, so it is okay to read more.


The above is the detailed content of Summary of Java programming ideas. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

How to Run Your First Spring Boot Application in Spring Tool Suite? How to Run Your First Spring Boot Application in Spring Tool Suite? Feb 07, 2025 pm 12:11 PM

Spring Boot simplifies the creation of robust, scalable, and production-ready Java applications, revolutionizing Java development. Its "convention over configuration" approach, inherent to the Spring ecosystem, minimizes manual setup, allo

See all articles