Thinking in Java [Java programming mechanism] learning notes-variables and objects

Source: Internet
Author: User
Thinking in Java [Java programming mechanism] learning notes -- variables and objects

The book says "You manipulate all objects with references". In Java, the object exists in heap, and all operations on the object are represented by reference in the stack.

In Java, Object Instantiation operations are performed usingNewBut there are also some situations such as string S = "ABC"; also created an object, and S is a reference to the string object "ABC.

One thing to note about the string object is that it is immutable objects. That is to say, modifications to the string will only create a new string and will not modify the original string object.

Why immutable objects?

Immutable objects are only useful in concurrent applications. Since they cannot change state, they cannot be upted by thread interference or observed in an inconsistent state.

There is also a class of variables in Java. They are not created using new, they are not referenced but a real variable. They are called primitive data type.

The following table defines these variables in Java:

If you want to create them in the heap and use them to reference them, you can use their corresponding class to create them.

The following table lists the default values of each variable:

Data Type Default Value (for fields)
Byte 0
Short 0
Int 0
Long 0l
Float 0.0f
Double 0.0d
Char 'U000000 ′
Boolean False
Object (any object) Null
String (is a object) Null
Array (is a object) Null

Uninstantiated variables are a warning in C ++ and an error is reported in Java.

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.