Java Programming Thought summary Note Chapter 2

Source: Internet
Author: User

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

Chapter II Everything is the object

Directory:

    • 2.1 Manipulating objects with references
    • 2.2 All objects must be created by you
    • 2.3 Never need to destroy objects
    • 2.4 Creating a new data type: Class
    • 2.5 methods, parameters, and return values
    • 2.6 Building a Java program
    • 2.7 Your first Java program
    • 2.8 Notes and embedded documents
    • 2.9 Coding Style

2.1 Manipulating objects with references

Everything is considered an object, the manipulated identifier is actually a "reference" to the object, the remote control (reference) manipulates the TV (object), wants to regulate the television, just through the remote control, and the remote control is independent.

2.2 All objects must be created by you

Once you have created a reference, you want it to be associated with a new object, which is usually accomplished with the new operator.

New String ("jiancheng");

Five different places to store your data:

    • Register: Within the CPU, the number of registers is extremely limited, so the register is allocated according to the requirements, the fastest.
    • Stack: in Universal RAM (Random Access Register), the Java compiler must know the size and life cycle of all data stored in the stack, the "stack pointer" moves down the allocation of new memory, move up to free memory, speed second only to register, basic data types and references are stored here.
    • Heap: Located in the Ram area for storing all Java objects, the compiler does not have to know the data size and life cycle.
    • Constant storage: Constant values are usually stored directly inside the program code.
    • Non-RAM storage: Completely live outside of the program, not under any control of the program, examples are stream objects and persisted objects , in the Stream object, the object is converted into a byte stream, which is usually sent to another machine. In the Persistence object, objects are stored on the hard disk, and they can remain in their own state even if the program terminates.

9 Basic types:

The size of the storage space occupied by the Boolean type is not explicitly specified and is defined only to be able to take the literal value true or false.

High-precision numbers:

    • BigInteger: Integer that supports arbitrary precision
    • BigDecimal: Fixed-point number with arbitrary precision support

Operations are similar to what can be performed on a basic type, but must be implemented in a method invocation instead of an operator.

Arrays in Java:
The array is initialized and cannot be accessed outside of its scope. This range check is at the expense of a small amount of memory overhead on each array and the runtime's subscript check (for security and efficiency).

2.3 Never need to destroy objects

Scope:

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

Scope of the object:

Java has a large difference in its role and basic type, and new creates a Java object that can survive outside the scope. As long as you need this object, it will persist until the garbage collector recognizes that the object is no longer referenced and frees the object's memory space, eliminating the problem of memory leaks.

2.4 Creating a new data type: Class

class determines the appearance and behavior of an object, and determines the type of the object.

Basic member Default value:

When a variable is used as a member of a class, Java ensures that its default value is given to ensure that the base type member variable is initialized (the initial value may not be what you want, preferably initialized yourself). Note that the default initialization method does not apply to field variables that are not a class, forget initialization, and Java will return an error to you at compile time.

2.6 Building a Java program

Static keyword:

The following two scenarios require the use of static

    • Just want to allocate a single storage space for a particular domain, without thinking about how many objects to create.
    • A method is not associated with any object that contains its class, or it can be called without creating an object.
class statitest{  static i =// can be called directly statitest.i such a call}

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, except that the usage can invoke it without creating any objects, class. Method ().

2.9 Coding Style

Hump Style:

    • class, with uppercase letters in the first letter of each word
    • Methods, fields, and objects, the first letter in lowercase, the remaining first letter capitalized

Summarize:

This chapter is easy to understand, the Java language and some of its basic ideas have a general understanding, most of the knowledge point has also been exposed, but easy to forget the details of the place, look no more.

Reprint Annotated: http://www.cnblogs.com/wujiancheng/

Java Programming Thought summary note the first chapter

Java Programming Thought summary Note Chapter 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.