Unlike Ruby, when using variables, you have to declare the type I had a lot of things to remember about modifiers, so let's look back on ourselves. I came up with the idea. Also, to learn Markdown notation ...
It is divided into ** primitive type ** and ** reference type **. Among them, primitive types are classified into integer types, floating point types, and so on. Reference types are divided into wrapper classes and string classes.
Model name | Type classification | size(bit) | initial value | value |
---|---|---|---|---|
long | integer | 64 | 0L | -9223372036854775808 ~ 9223372036854775807 |
int | integer | 32 | 0 | -2147483648 ~ 2147483647 |
short | integer | 16 | 0 | -32768 ~ 32767 |
byte | integer | 8 | 0 | -128 ~ 127 |
double | Floating point | 64 | 0.0d | Double precision floating point number |
float | Floating point | 32 | 0.0f | Single precision floating point number |
boolean | logic | 1 | false | true / false |
char | letter | 16 | \u0000 | Unicode single character(¥u0000~¥uFFFF) |
When declaring variables, be careful to use the appropriate type so as not to waste memory.
** Integer type ** Normally, the [int] type is used. Use [long] type for large values Integer values are treated as [int] type in the program. When dealing with integers that come out of the [int] type range, write [L] or [l (lowercase L)] at the end of the number. Must be shown to be of type [long].
** Floating point type ** Normally, use the [double] type. When dealing with the [float] type, it is necessary to write [F] or [f] at the end of the value.
** Logical type ** Only boolean values [true] and [false] can be stored.
** Character type ** Only one character can be stored in one variable. When writing common characters, it is necessary to enclose them in ['(single quotation marks)]. No character code is required.
A type that holds the reference destination where the data is stored instead of handling the data
If, the baldness is not stored in the string, but the reference destination with the data baldness is held.
** String class (String type) ** A class that handles strings. When writing in a program, enclose it in ["(double quotation marks)]. It is treated as [String] type in the program.
** Wrapper class ** A class that allows primitive types to be treated as wrapper classes. It will be possible to handle things that cannot be handled by primitive types (will be described later).
Primitive type | Wrapper class |
---|---|
long | Long |
int | Integer |
short | Short |
byte | Byte |
double | Double |
float | Float |
boolean | Boolean |
char | Character |
** Auto Boxing, Unboxing ** Doing automatic conversion from primitive types to wrapper classes ** Autoboxing ** From the reverse wrapper class to the primitive type ** unboxing **
Integer integer2 = Integer.valueOf(5); //No autoboxing
int int1 = Integer1; //Unboxing
int int2 = integer2.intValue(); //No unboxing
** Array ** Data of the same type can be handled by one variable.
The data in the array is called ** element **. Data is assigned to and referenced from the element using ** index number **.
** Index number ** starts at 0 and is the number obtained by subtracting 1 from the array.
I thought it would be a good review because I would put it together in my own letters. I don't fully understand modifiers yet, so I'll summarize them.
Recommended Posts