VARIABLES AND DATA TYPES

PREVIOUS



Variables

Java has three kinds of variables:

1.Local Variables:

    Local variables are  declared and used inside methods.

2.Instance Variables:

   Instance variables are created when the objects are instantiated and therefore they are   associated with objects.

3. Class Variables
  
    Class variables are global to a class and belong to the entire set of objects that class creates.



Datatypes

Datatype specify the type of value to be stored in the variable.

A variable is a location in memory that can hold a value.

Integer

Datatype Size        Range

Byte        1byte      -127 to 127                                                                                                                                                                                                                                                                             
short       2 bytes    -32,768 to 32,767
int            4 bytes    -2.15E+09 to 2.15E+09  
long         8 bytes    -9.22E+18 to 9.22E+18

Decimal

float                 4 bytes
double             8 bytes

Character

char         2 bytes             
String            

Logical

boolean (true,false)

       

class var
{
int a=10;//reference

static int n=10;
public static void main(String ar[])
{
byte b= 127;    //constant
short s=32767;
int i=236563246;
long l=467765322;

float f=345.567f;
double d=345.6326;

char c='v';
String st="vina "+"csc";

boolean bo;


System.out.println("Integer Types:");
System.out.println(b + "\t" + s +"\t" + i + "\t" + l);

System.out.println("Float Types:");
System.out.println(f+"\t"+d);

System.out.println("Char Types:");
System.out.println(c+st);

bo =  b > s ;
System.out.println("Boolean:\n\t"+bo);
}
}


No comments:

Post a Comment