Thursday, January 13, 2011

Lesson5

I know been a long time since the previous lesson. But just couldn't - had a lot of reading to catch up with. Here you go next lesson - this will be notes on datatypes.

Primitive -

byte - 8 bits - Number - from -127 to +128
short- 16 bits
int - 32 bits
long- 64 bits
float- 32 bit floating point - do not use this for precision values - may cause rounding issues
double- 62 bit floating point
boolean- true/false - like any language
char- strings characters

Data TypeDefault Value (for fields)
byte0
short0
int0
long0L
float0.0f
double0.0d
char'\u0000'
String (or any object) null
booleanfalse

Array Declaration -
int[] anArray; // declares an array of integers
int [10] anArray; // to restrict to 10 rows

Similarly, you can declare arrays of other types:

byte[] anArrayOfBytes; short[] anArrayOfShorts; long[] anArrayOfLongs; float[] anArrayOfFloats; double[] anArrayOfDoubles; boolean[] anArrayOfBooleans; char[] anArrayOfChars; String[] anArrayOfStrings;
2 Dimensional Arrays
String[][] names = {{"Mr. ", "Mrs. ", "Ms. "},
                            {"Smith", "Jones"}};

No comments: