Java data types are divided into basic data types and reference data types.
Basic data types are of numeric, character (char), Boolean (Boolean)
Numeric type variable
1. Integer type
|
Type |
Occupy Storage space |
Representation Range |
|
Byte |
1 byte byte |
-128~127 |
|
Short |
2 bytes |
-2~2-1 |
|
Int |
4 bytes |
-2~2-1 |
|
Long |
8 bytes |
-2~2-1 |
Three representations of the integral type constants of Java:
-decimal integers, such as 12,-31
-Eight binary integers, starting with 0, such as 012
-16 in number, beginning with 0x or 0X, such as 0x12
The Java integer constant defaults to the int type, declares the long type constant, plus l,
eg
Long a=10l;
2, floating point type
|
Type |
Occupy Storage space |
Representation Range |
|
Float |
4 bytes |
-3.403e38~3.403e38 |
|
Double |
8 bytes |
-1.798e308~1.798e308 |
Character type variable
Used to represent and store a character, Java uses the Unicode character set.
A character is a single character that is included in single quotes
eg
Char c= ' B ';
What is a Unicode character set? Speaking from the ASCII character set ...
1, in the computer all the data in binary notation, but similar to a, B and other letters can not be directly expressed in binary.
2, standard ASCII code for common symbols, numbers and uppercase and lowercase letters, such as using a 7-bit binary number http://baike.baidu.com/view/15482.htm
But there are only English characters in the ASCII character set, in order to facilitate computer processing of characters in other languages, Unicode sets a uniform, unique binary code for each character of each language, satisfies the need for cross-language text conversion and processing, and uses numeric 0-0x10ffff to represent characters, Up to 1,114,112 characters are allowed.
The generation of garbled characters
When writing data to a file, a character set is used to convert the binary data to the computer, and the B character set is used when the data is read from the computer, and garbled characters are generated.
Because Java uses the Unicode character set, Unicode encoding consumes two bytes, so variables of type char are also two bytes, so a char variable in Java can store a Chinese character.
Boolean variable
Applies to logical operations and program flow control, in Java only true and false two values
eg
Boolean a=true;