boolean result = true;
char capitalC = 'C';
byte b = 100;
short s = 10000;
int i = 100000;
>> You may have noticed that the new
keyword isn't used when initializing a variable of a primitive type.
>> Primitive types are special data types built into the language; they are not objects created from a class.
>> A literal is the source code representation of a fixed value;
>> literals are represented directly in your code without requiring computation
The integral types (byte
, short
, int
, and long
) can be expressed using decimal, octal, or hexadecimal number systems.
int decVal = 26; // The number 26, in decimal
int octVal = 032; // The number 26, in octal
int hexVal = 0x1a; // The number 26, in hexadecimal
double d1 = 123.4;
double d2 = 1.234e2; // same value as d1, but in scientific notation
float f1 = 123.4f;
The Java programming language also supports a few special escape sequences for char
and String
literals:
\b
(backspace),
\t
(tab),
\n
(line feed),
\f
(form feed),
\r
(carriage return),
\"
(double quote),
\'
(single quote),
and \\
(backslash).
>> There's also a special null
literal that can be used as a value for any reference type. There's also a special null
literal that can be used as a value for any reference type. null
may be assigned to any variable, except variables of primitive types. may be assigned to any variable, except variables of primitive types.
>> Therefore, null
is often used in programs as a marker to indicate that some object is unavailable.
>> There's also a special kind of literal called a class literal, formed by taking a type name and appending ".class"
; for example, String.class
. This refers to the object (of type Class
) that represents the type itself.
No comments:
Post a Comment