Java data type,

Source: Internet
Author: User

Java data type,

1. First, let's take a look at the data content or key points.

1. During the execution of a program, you must perform operations on the data and store the data. The data can be obtained from user input, files, or networks.

During the running process, the data is stored in the memory through variables so that the program can be used at any time.

2. If you need to find the data stored in the memory, you need to specify the data to the variable and name it. You can find the relevant data by using the variable name (memory space for storing the data.

3. If a variable represents a memory space, the data is stored in the space. However, because the data needs different capacities during storage, different data must be stored in different sizes of memory. Therefore, different data types are used to differentiate data.

4. the memory space occupied by data of the basic data type is fixed. The memory stores the value itself, and the referenced data type stores the address pointing to the data, it is usually composed of multiple basic data types.Is also called the composite data type.

2. Java data types can be basically divided into eight basic data types and reference data types.

Data Type Keywords Bytes occupied Default Value Value Range
Logical type Boolean 1 False True; false
Byte type Byte 1 0 -27 ~ 27-1
Short integer Short 2 0 -215 ~ 215-1
Integer Int 4 0 -231 ~ 231-1
Long Integer Long 8 0L -263 ~ 263-1
Single precision floating point type Float 4 0.0f

Negative number range:-3.4028235E + 38 ~ -1.4E-45

Positive Value Range: 1.4E-45 ~ 3.4028235E + 38

Dual-precision floating point Double 8 0.0d

Negative value range:-1.7976931348623157E + 380 ~ -4.9E-324

Positive Value Range: 4.9E-324 ~ 1.7976931348623157E + 308

Character Type Char 2 '\ U000000' '\ U000000 '~ '\ Uffff'

 

Iii. Discuss the location of data-type storage in java

The location 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; ④ data modified by the final keyword indicates that the reference remains unchanged and is stored in the constant pool. 3. the packaging class of the basic data type: ① Integer I = 10; The Declaration process is the same as that 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.