Data types in Java(integer, float, character and boolean, String, Date and array objects)

Lionsure 2020-09-06 Original by the website

No matter which programming language you learn, you must start with basic knowledge, and data types are undoubtedly the most basic knowledge. Learning Java is the same, starting with data types. Only by mastering the basic knowledge of Java and further studying can you understand; otherwise, as the learning progresses, you will lose your interest and motivation in learning because you don't understand too much.

Data types in Java are divided into two categories, namely basic data types and object data types. The basic data types can be divided into "integer, floating point, character and boolean", and the object data types can be divided into "String, Date, and array objects, etc.".

 

Data types in Java(integer, float, character and boolean, String, Date and array objects)

One, Java basic data types

1) Integer

1. byte(shortest)

 It occupies one byte (8 bits), and the value range is -128 to 127.

 

2. short (short integer)

It occupies 2 bytes, a total of 16 bits, and the value range is -32678 to 32677.

 

3. int (integer)

The more frequently used integer type is int, which occupies 4 bytes, a total of 32 bits, and the value range is -21,4748,3648 to 21,4748,3647.

 

4. long(long integer)

It occupies 8 bytes, a total of 64 bits, the value range is -263~263-1(-922,3372,0368,5477,5808 ~ 922,3372,0368,5477,5807), it can represent the largest type in the integer type.

 

 

2) Floating point type(real number)

1. float (single precision floating point type)

 It occupies 4 bytes, a total of 32 bits, the value range is -21,4748,3648 to 21,4748,3647, and 7 significant digits can be reserved after the decimal point.

 Note: There is an F at the end, such as 56.80F, without F, the default is double type.

 

2. double(double precision floating point type)

It occupies 8 bytes, a total of 64 bits, the value range is -263~263-1(-922,3372,0368,5477,5808 ~ 922,3372,0368,5477,5807), 15 significant digits can be reserved after the decimal point.

 

 

3) Character type

char (character type)

It occupies 2 bytes, a total of 16 bits, and the value range is -32678 to 32677, which is used to define characters.

 

4) Boolean type

boolean

It occupies 1 byte, a total of 8 bits, the value range is true, false, used to indicate true or false.

 

 

Two, object data type

 Object-oriented programming language, the defined variable can be regarded as an object. The defined String(character type), Date(date type), array, etc. can all be regarded as objects ln Java, such as:

String userName = "Java"; //Character object

Date d = new Date(); //Date object

int[] arr = new int[10]; //integer array object

The above are the data types in Java. If you have learned a programming language, you will understand it very well. The data types of each programming language have similarities. They may have different definition methods or different representations, but the meanings are the same, so naturally they are imperceptible has become the basis of learning Java, which is probably the benefit of interoperability.