Java data type,

Source: Internet
Author: User

Java data type,
The basic types of java have not been written to a blog for a long time, so I forget the original intention of registering a blog. The basic types of data in java are: basic data types and reference data types, which are not described here; next, we will discuss where the data type is stored in java, and where the basic data type is stored depends on where the basic type is declared: 1. when the basic data type is declared in the method, its variable names and values are stored in the java stack; declare the basic data type in the method: for example: int a = 10 ① declare a reference variable named a in the stack; ② check whether there is an address with a nominal value of 10 in the stack, if not, open an address that stores the nominal value of 10; ③ point the reference of variable name a to the address with the nominal value of 10; 2. when the basic data type is declared in the class, it is stored in the heap memory; ① The basic data type declared in the class will be stored in the Method Area during class loading; ② In the java heap, the java. lang. class Object, used as the access entry to the data in the method area. ③ The data modified by the static keyword belongs to the Class and is stored in the method area.; ④ Final keyword-modified data indicates that the reference remains unchanged and is stored in the constant pool; 3. Basic data type packaging class: ① Integer I = 10; same as the Declaration process of I = 10. ② Integer I = new Integer (10); Data 10 is stored in the heap; must the referenced data type be stored in the heap? 1. special String class example: String str = "abc"; ① declare a reference to the variable 'str' in the stack; ② search for a String object with "abc" in the constant pool, if not, create a String object storing "abc" in the constant pool; ③ point the reference of str to the string object "abc "; ④ When String str1 = "abc" is declared again, the constant pool already has an "abc" object, so str1 points directly to the abc address; ⑤ str = str1, reference data type comparison, the application address is compared. Note: String str = "abc" is not created or an object is created. 2. other reference types: Stirng str = new String ("abc"); ① declare a reference variable named str in the stack; ② create and store a String object "abc" in the heap "; ③ check whether there is a string object "abc" in the constant pool. If not, create a String object storing the value "abc" in the constant pool; ④ associate the string object "abc" in the heap with the string object "abc" in the constant pool. the reference of the object in the constant pool can be returned using the intern method; ④ point the reference of str to the String object "abc" in the heap. Note: String str = new String ("abc") creates one or two objects;

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.