Chapter 2 Data types, Variables And Arrays




Chapter 2  Data types, Variables And Arrays
Data Types :
java defines eight simple types of data byte, short, int, long, float, double, and Boolean.
NameWidth(bit)
long64
int32
short16
byte8
double64
float32

One - Dimensional Arrays :
To create an array, you first must create an array. Variable of the desired type. The general form of one - dimensional array declaration is
type var_name[];
Example :
int month_days[];
Although this declaration establish the fact that month-days is an array variable, no array actually exists. To like month_days actual, physical array of integers, operator that allocates memory.
array_var = new type[size];
Example :
month_day = new int[12];
Multi - Dimensional Arrays :
In java, multidimensional arrays are actually arrays of arrays. For example , the following declares a two - dimensional array variable called twoD.
Example :
int twoD[][]=new int [4][5];