We have started studying for the Oracle Java Programmer, Silver SE11 certification. I would like to summarize the data types that came out in that. We would appreciate it if you could let us know if you have any suggestions, such as mistakes.
Mold | Classification | |
---|---|---|
boolean | Logical type | True/False |
char | Character type | 16-bit Unicode,¥u0000~¥uFFFF |
byte | Integer type | 8-bit integer,-128~127 |
short | Integer type | 16-bit integer,-32768~32767 |
int | Integer type | 32-bit integer,-2147483648~2147483647 |
long | Integer type | 64-bit integer,-9223372036854775808~9223372036854775807 |
float | Floating point type | 32ビット単精度Floating point type |
float | Floating point type | 64ビット倍精度Floating point type |
Reference types include class types, interface types, and array types.
Literals are the values you write in your source code. By default, Java literals are int for integers, double for floating point numbers, boolean for booleans, and char for characters.
If you want to specify the data type, use the suffix at the end of the value or the prefix at the beginning of the value.
--Long type: Add L or l after the value. --Float type: Add F or f after the value.
It's a notation method rather than a type ...
--Write in binary ... Add 0b to the beginning of the value. --Write in octal number ... Add 0 to the beginning of the value. --Describe in hexadecimal ... Add 0x to the beginning of the value.
Not in byte type or short type.
It seems that it was introduced from Java SE 7. This is just to improve visibility. However,
-Cannot be written at the beginning and end of literals -Cannot be written before or after the symbol
Cannot be written at the beginning and end of a literal Cannot be written before or after the symbol
Concrete example
Main.java
double a = 123_4567.89;
System.out.println(a);
If you do, it will be displayed as 1234567.89. It seems to be okay at all even if it is not separated by 3 digits.
Main.java
double a = 123_4567_.89;
System.out.println(a);
If you do, an error will occur.
The char type is a data type that represents one character, and must be enclosed in single quotation marks such as'a'. By the way, the character string must be enclosed in double quotation marks like "neko".
In Unicode notation, it is written in 4 hexadecimal digits after the \ u prefix.
Main.java
char a = '\u1111';
System.out.println(a);
ᄑ
Was output. I can't read w
It is a form that uses the java.lang.String class that belongs to the java.lang package. As a special case, you can use a String instance by enclosing it in "" without using the new operator.
A refreshing introduction to Java Thorough capture Java SE11 Silver problem collection
Recommended Posts