Data Types, Variables and Arrays
Java defines 8 primitive(simle) types of data: byte, short, int, long, char, float, double, boolean.
Byte - the smallest integer type. This is a signed 8-bit type that has a range from -128 to 127.
Short - is a signed 16-bit type. It has range from -32,768 to 32767.
Int - is a signed 32-bit type that has a range from -2,147,483,648 to 2,147,483,647.
Long - is a signed 64-bit type.
Float - specifies single-precision value that uses 32 bits of storage.
Double - uses 64 bits of storage.
Char - is 16-bit type. The range of a char 0 to 65,536. There are no negative chars.
Boolean - has two possible values true or false.
Integer Literals. An integer literal can always be assigned to a long variable. You do this by appending an
upper- or lowercase L to the literal. For example, 0x7fffffffL or 12345L.
You can also specify integer literals using binary. To do so, prefix the value with 0b or 0B. int x = 0b1010;
Octal values are denoted in Java by leading zero.Normal decimal numbers cannot have a leading zero.
Underscores can only be used to separate digits, and can not come at the beginning or the end of a literal.
Ex: int x = 123__555_1233;
Each time you start a new block, you are creating new scope. A variable declared within a block is called a local variable.Objects declared in the outer scope will be visible to code within the inner scope.
Комментарии
Отправить комментарий