10/01/2008

Variables

Primitives

byte (8bits)
short (16bits)
int (32bits)
long (64bits)
float (32bits)
double (64 bits)

A defult value of primitive is 0.

You can put a suffix to double and float, like 1.5d or 1.5f.

boolean / char

boolean --> true or false
char --> character (16bits), defaut \u0000

String

String is an immutable object; actually String is a Java class.

There are a couple of ways to create a String instance.

String str = "Hello world";
String str = new String ("Hello world");

exapmple

String s1 = "Hello";
String s2 = s1;

then s2 and s1 refer to the same "Hello" in the pool.

"Hello" is a String object and s1 refers to the object.

In other words, variables (except primitives) are objects, each of which referes to an instance.