Data Types:



                     There are eight data types in java.        a>byte  b>Short c>Int  d>long e>double f>float g>Boolean g>char.
a>byte:
              Size=8 bits or 1 byte.
               Min-Size=-128.
               Max-Size=127.
               Range=127to -128.
Advantage:- If you want to handled data in terms of stream either from file or network then byte is recommended.
b>Short:
            Size     :  16bits or 2 bytes.
             Range : -2^15 to 2^15-1.  [-32768 to 32767]
Important points: I. Short is most rarely used data type in java. It is used in 16 bit processor like 8086.This processors are outdated so, short is also outdated.
c> int: Mostly used data type is int.
            Size: 32 bits or 4 bytes.
          Range: -2^31 to 2^31-1.
Note:-
1.> In c-language the size of int varied from platform to platform. If processor is 16 bits then it’s size is 2 bytes and if the processor is 32 bits then it’s size is 4 bytes. Hence ,it is not robust but performance is high.
2.>In java size of int is 4 bytes in all the platform. So ,it is robust and performance is not high.
d> Long:-  Whenever int is not able to hold big values then we should go for long.
Ex:- Distance travelled by light in miles.
      To count the number of characters present in the big files.
       Size:8 bytes.
       Range: -2^63 to 2^63-1.        Default value: 0
NOTE:-All the above data type (byte ,short , int ,long)are used to represents whole numbers. If you want to represents real number then we should go for floating point data type. e.>float:-
            Size : 32 bits or 4 bytes.
             Range: -3.4e^38 to 3.4e^38.
               Default value:0.0
If we want 5-6 decimal places then we should go for float data type. Float follows single precisions.
f.>double:-
            Size: 8 bytes.
             Range:-1.7e^308 to 1.7e^308.
              Default value=0.0
If we want 15-16 decimal places then we should go for double data types. Double follows double precisions.
g.>Boolean:-
              Size: Not applicable.
             Range: Not applicable.[Allowed value is true/false.]
               Default value: false.
Examples:- Boolean b=”true”;(Not valied).               boolean b=Ture;(Not valied).          boolean b=true;(Valied).                 boolean True=true;        boolean b=True; System.out.println(b);//true.
Note:- The only allowed value for the boolean data type is true or false where case is important. If we pass int value to boolean we will get CE(Compile Time Exception).
Example:-
    if(1){  System.out.println(“Hello”);}//CE   while(0){System.out.println(3);}//CE: incompatible type fount int required boolean. Above examples works fine in the c++ language but in java it gives compile time error.
h>Char:-
            In old languages like c,c++ we use ASCII characters to represents all the ASCII characters which required 8 bits. So, one byte is enough.
 But in java we use unicodes which covers world wide all sets of characters. It is greater then 256 characters so, one byte is not enough. Hence the size of char is 2 bytes in java. Size: 2 bytes.
Range: 0 to 65535.
Default Value: 0(represent blank space).
Literals:- The constant value assigned to the variable is called as literals.
Ex:-      int a=10; //where int is data type, keyword.  a is variable or identifier           10 is constant value or literal.
 Integral Literals:- For the integral data types are(byte, short, int , long).Following are the way to specify the literals:-
a.> decimal literals:- allowed digits are 0 to 9.
                                                int x=10;
b.>Octal literals:- allowed digits are 0 to 7.
                                         int a=010;
c.>Hexadecimal literals:- allowed digits are o to 9,a to z or A to Z. For the extra digits we can use both uppercase and lowercase.
This is one of very few places where java is not case sensitive.
Literals value should be prefixed with oxe or ox.
Example:-
                 int x=ox10; or int x=OX10;
          {
public static void main(String args[])
{
int  x=10; int y=011; int z=ox11; System.out.println(x+” “+y+” “+z);  //10   9  17
}
}
Bydefault every integral literal is of int type but we can specify as long type by suffixing with l or L. example:- i> int i=100;(valid). ii>int j=10l;(C.E: plp found long req int). iii>long l=10l;(valid) iv>long l=19;(valid) v>long x=0xBaBal;(valid)
There is no way to specify integral literal is of byte and short type explicitly.
If we are assigning integral literal to the byte variable and that integral literal is with in the range of byte then it treats as byte literal automatically. Similarly short literal also.
example:-
              byte b=10;(valid)              byte b=130;(invalid) CE:PLP found int req byte.
           Floating point Literals:-
Every floating point literal is by default double type and hence we can’t assign directly to float variable.
But we can Specify Explicitly floating point literal is the float type by suffixing with ‘f’ or
‘F’.
Example:-
                      float f=121.456;//plp found double req. float                      float f=188.99898f;(valid).
                    double d=1234343.989898;(valid);
We can Specify floating point literal Explicitly as double type or by suffixing with d or D.
example:- double d=123.4567D;(valid)
                   float f=123.45464d;(Invalid)
We can specify floating point literal only in decimal form and we can’t specify in Octal and Hexadecimal form.
example:- 
                i>double d=123.456;(valid)               ii>double d=0123.456;(valid) o/p=123.456              iii>double d=0x123.456;      C.E: malformed floating point literal.
Which of the floating point declaration are Valid?
I>float f=123.456;(not Valid)
II>double d=0123.456;(valid)
III>double d=0x123.456; Iv>double d=0xface;(valid) v>float f=0xBEa; vI>float f=0642;
NOTE:-We can assign literal directly to the floating point data type and that integral literal can be specified either in decimal form or octal form or hexadecimal form.
But we can’t assign floating point literals directly to the integral types. Example:-
                  int i=123.456;//plp found: double required int.                double d=1.203;syso(d);//1200.0
We can specify floating point literal even in specific form also(exponential form) i>double d=1.2e3;syso(d);1200.0; ii>float f=1.2e3; C.E:PLP found: double, required float. iii>float f=1.2ef;//o/p=1200.0
Boolean Literals:-  
                               The only possible values for the Boolean data type are true/false. Q>Which of the following Boolean declaration are valid. i>boolean b=0; C.E ii>boolean b=True ;C.E iii>boolean b=true; iv>boolean b=”true”;C.E
Char Literals:- A char literals can be represented as single character with in single quote.
example:-   char c=’a’; char c=’ab’;(Invalid)
A char literal can be represented in Integral form i.e  we can assign decimal value to char literal ,octal value and hexadecimal value to char literal. But the size should be in its range.(char range). example:-  char c=97;   char c=0123;  char c=0x10; char c=0xBaba;
A char literal can also be represented in unicode value(‘\uxxxx’).
example:-   char c=’\u0061’; char c=’\uface’;
A char literal can also have escape character value like ‘\n’,’\t’.
example:- char c=’\n’; char c=’\t’;

Null Literal:-  To reduce the number of references to an object, we use null literal. example:- s=null;//s is ref. variable of object.

String Literal:-  String literal always use double quotes to represent the string literals.
example:- String s=”java”; String s=””;String s=”hi”+”hello”;