Java Data Type

Source: Internet
Author: User
Tags float double

Java data type: a strong type language. The first time a variable is declared, it must indicate the data type. The first value assignment is called the initialization of the variable.

 

Category: 8 basic types (native type): INTEGER: byte Byte type 1 byte = 8bit 256 medium status-128 ~ + 127
Short integer 2 Byte = 16bit 64436-32768 ~ 32767
Int integer 4 Btye = 32bit 2 ^ 32-2147483648 ~ + 2147483647
2 ^ 31 = 2 ^ 10*2 ^ 10*2 ^ 10*2
About k 2 = 2G between plus and minus 2.1 billion
Long integer 8 Byte = 64bit-2 ^ 63 ~ 2 ^ 63-1
Char character type 2 Byte = 16bit 0 ~ 65535
1 + 2 + 'A' + 1 + 2 is equivalent to 1 + 2 + 97 + 1 + 2

Float Type/real type: float single precision 4 Byte = 32bit is actually 3 + 1 (1 bit) f1 = 5.0F or f
Double precision 8 Byte = 64bit is actually 6 + 2 (2 bit weights)
Boolean Type: boolean
Note: floating point data is stored with non-precision, and integer data is stored with precision. The literal value of the data type has the default value: int for the integer type and double for the real type.
The difference between double and BigDecimal: double, suitable for scientific operations
BigDecimal, suitable for commercial operations
BigDecimal b1 = new BigDecimal ("5.0 ");
BigDecimal b2 = new BigDecimal ("3.1 ");
B1.subtract (b2); minus
B1.divide (b2, 4); Division

BigInteger is used for big data .. For example, calculate 99 of 9.

Five reference types (object types): Class interface array enumeration Annotation
Null type: void type


Data type conversion: Only boolean is not involved in data type conversion.
(1). Automatic type conversion: a. constants can be automatically converted within the range of the number of tables.
B. automatic conversion of large data types with a small data range (special cases should be noted)
Int to float, long to float, long to double will not be automatically converted, otherwise the precision will be lost
C. The reference type can be automatically converted to the parent class
D. The basic types and their packaging types can be converted to each other.
(2). Forced type conversion: Enclose the target type in parentheses before the variable.


8. Basic packaging class: Byte Short Integer Long Character Float Double Boolean
Advantages of basic types: relatively simple data storage and high computing efficiency
Advantages of the packaging class: some are easy. For example, the element of the set must be of the object type, satisfying the idea that java is an object.


Reference Type: the underlying structure and basic type are significantly different.
First, we will introduce the JVM memory space: (1). Heap space: allocated object new Student ()
(2). Stack space: temporary variable Student stu
(3). Code area: class definition, static resource Student. class

Eg: Student stu = new Student ();
Stu. study ();
// New creates an object in the heap space of the memory
// Assign the object address to the stu reference variable

Implementation steps of the above example: a. JVM loads Student. class to the Code Area
B. new Student () allocates space in the heap space and creates a Student instance
C. Assign the address of this instance to the reference stu, stack space

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.