Java Data types

Source: Internet
Author: User

First, about the content or key points about the data.

1, the procedure in the process of execution, the data needs to be calculated, also need to store data. This data can be entered by the user, either from a file or from a network.

This data is stored in memory by variables during the program's run so that the program is ready to use.

2, if you need to find data stored in memory, you need to assign the data to the variable, and named, through the variable name (memory space to store data) to find the relevant data.

3, a variable represents a memory space, the data is stored in this space, however, because the data in the storage needs of different capacity, the different data must be allocated to the memory of various sizes to store, so the different data with different data types to distinguish.

4, the data of the basic data type occupies a fixed memory space, the memory is stored in the value itself, and the reference data type is to point to the data point to the address, often consists of a variety of basic data types, the reference data type of data used as the object of the citation Is also called a composite data type.

Second, Java data types can be basically divided into 8 basic data types and reference data types.

Data type Key words Number of bytes occupied Default value Range of values
Logic type Boolean 1 False True;false
BYTE type Byte 1 0 -27~27-1
Short-integer Short 2 0 -215~215-1
Integral type Int 4 0 -231~231-1
Long integer type Long 8 0L -263~263-1
Single-precision floating-point type Float 4 0.0f

Negative Range: -3.4028235e+38~-1.4e-45

Positive range: 1.4e-45~3.4028235e+38

Double-precision floating-point type Double 8 0.0d

Negative Range: -1.7976931348623157e+380~-4.9e-324

Positive range: 4.9e-324~1.7976931348623157e+308

Character type Char 2 ' \u0000 ' ' \u0000 ' ~ ' \uffff '

Third, discuss the location of data type storage in Java

    Basic data type storage location, depending on where the base type is declared:         1. When a base data type is declared in a method, its variable name and value are stored in the Java stack;                Declare basic type data in the method:                &NBSP ;   example: int  a = 10                     ①  to declare a variable named a in the stack References;                     ②  in the stack to find if there is a literal value of 10 address, if not on the opening of a deposit literal is 10 address;                     ③  a reference to a variable named A is directed to an address with a literal value of 10;  &nbs P        2. Basic data types are stored in heap memory when declared in a class;                     ①  basic data types declared in a class are stored in the method area when the class is loaded;                     ②&NB SP; In the Java heap, generate the Java.lang.Class object representing this class as the access entry for the method area data;                    The  ③ static keyword-decorated data isbelonging to the class itself, stored in the method area;                     ④ final keyword-modified data represents the invariant, stored stored in a constant pool;          3. Wrapper classes for basic data types:                     ① integer i = 10; The declaration process with i = 10.                      ② integer i = new Integer;   data 10 is the;   reference data type stored in the heap must be lost stored in the heap?         1. Special String class                     Example: string str = "abc";                   ①  to declare a reference to a variable named str in the stack;            &NBSP ;      ②  Find a String object with "ABC" in a constant pool, and if not, create a string object that stores a value of "ABC" in a constant pool;                   ③  link str references to string objects "ABC";                &NBS P  ④ when declaring the String St againR1 = "ABC", there is already an "ABC" object in the constant pool, so str1 directly points to the address of ABC;                   ⑤STR = St R1, reference data type comparison, compare app address;            NOTE: String str = "ABC" did not create or create an object       &NBS P 2. Other reference types                   STIRNG str = new String ("abc");                   ① declaring a reference to a variable named str in the stack;              &NBS P    ②  Create a String object in the heap "ABC";                   ③  Checks if there is a string object "ABC" in the constant pool, and if it does not create a string object in the constant pool that stores a value of "ABC";                    ④ link The string Object "ABC" in the heap to the string object "ABC" in the constant pool, you can use the Intern method to return references to objects in the constant pool;                   ④ the reference to STR to the string object in the heap "ABC";        NOTE: string str = new String ("abc") creates one or two objects;

Java data type

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.