Sie sind auf Seite 1von 4

Reference Data Types:

 Reference variables are created using defined constructors of the classes. They are used to access
objects. These variables are declared to be of a specific type that cannot be changed. For example,
Employee, Puppy etc.

 Class objects, and various type of array variables come under reference data type.

 Default value of any reference variable is null.

 A reference variable can be used to refer to any object of the declared type or any compatible type.

 Example: Animal animal = new Animal("giraffe");

Java Literals:

A literal is a source code representation of a fixed value. They are represented directly in the code
without any computation.

Literals can be assigned to any primitive type variable. For example:

byte a = 68;
char a = 'A'

byte, int, long, and short can be expressed in decimal(base 10), hexadecimal(base 16) or octal(base
8) number systems as well.

Prefix 0 is used to indicate octal and prefix 0x indicates hexadecimal when using these number
systems for literals. For example:

int decimal = 100;


int octal = 0144;
int hexa = 0x64;

String literals in Java are specified like they are in most other languages by enclosing a sequence of
characters between a pair of double quotes. Examples of string literals are:

"Hello World"
"two\nlines"
"\"This is in quotes\""

String and char types of literals can contain any Unicode characters. For example:

char a = '\u0001';
String a = "\u0001";

Java language supports few special escape sequences for String and char literals as well. They are:

Notation Character represented


\n Newline (0x0a)

\t Tab

\" Double quote

\' Single quote

\\ Backslash

Data Type Default Value Default size

Boolean False 1 bit

Char '\u0000' 2 byte

Byte 0 1 byte

Short 0 2 byte

Int 0 4 byte

Long 0L 8 byte

Float 0.0f 4 byte

Double 0.0d 8 byte

Why char uses 2 byte in java and what is \u0000 ?

because java uses unicode system rather than ASCII code system. \u0000 is the lowest range of
unicode system.
Size Minimum Maximum
Category Types Precision Example
(bits) Value Value

byte b =
byte 8 -128 127 From +127 to -128
65;

char c =
'A';
char 16 0 216-1 All Unicode characters
char c =
65;

Integer short s =
short 16 -215 215-1 From +32,767 to -32,768
65;

From +2,147,483,647 to - int i =


int 32 -231 231-1
2,147,483,648 65;

From
long l =
long 64 -2 63 63
2 -1 +9,223,372,036,854,775,807 to -
65L;
9,223,372,036,854,775,808

(2-2- From 3.402,823,5 E+38 to 1.4 E- float f =


float 32 2-149 23
)·2 127
45 65f;
Floating-
From double
point (2-2-
double 64 2-1074 1.797,693,134,862,315,7 E+308 d=
52
)·21023
to 4.9 E-324 65.55;

boolean
Other boolean 1 -- -- false, true
b = true;
void -- -- -- -- --

Das könnte Ihnen auch gefallen