http://www.technicalpage.net/search/label/SQL

DataTypes in Java


DataTypes are of two types;
Primitive and Non-Primitive

Primitive data types:
boolean, byte, int, char, short, long, double, float

Non-Primitive data types:
String, Array, Class, Interface


Default Values


boolean  //Defaultvalue=false      
byte  //Defaultvalue=0          
int  //Defaultvalue=0          
char  //Defaultvalue='\u0000'   
String  //Defaultvalue=null       
short  //Defaultvalue=0          
long  //Defaultvalue=0L       
double //Defaultvalue=0.0d 
float  //Defaultvalue=0.0f  

Size and Range
boolean  //size=1bit                          //range:
byte  //size=8bits(1byte)          //range:-2tothepower(8-1)to+2tothepower8-1
int  //size=32bits(4bytes)        //range:-2tothepower(32-1)to+2tothepower32-1
char  //size=16bits(2bytes)        //range:-2tothepower(16-1)to+2tothepower16-1
short  //size=16bits(2bytes)        //range:-2tothepower(16-1)to+2tothepower16-1
long  //size=64bits(8bytes)        //range:-2tothepower(64-1)to+2tothepower64-1
double //size=64bits(8bytes)        //range:-2tothepower(64-1)to+2tothepower64-1
float  //size=32bits(4bytes)        //range:-2tothepower(32-1)to+2tothepower32-1







In Non-Primitive datatypes, you create reference object of the String , Array or Class.
String[] string = new String[20]; // This is example of String +Array. Click here for detail about string array.
Class objectReference = new Class();
 
Below code finds the default value of each variables:

package heloWorld;

public class DataTypes {

            static boolean bl;  
            static byte bt;      
            static int it;       
            static char chr;     
            static String str;                                                        
            static short shrt;  
            static long lng;     
            static double dble;  
            static float fl;    
           
            public static void main(String[] args) {

                        System.out.println("Default value of boolean = "+bl);
                        System.out.println("Default value of byte = "+bt);
                        System.out.println("Default value of int = "+it);
                        System.out.println("Default value of char = "+chr);
                        System.out.println("Default value of String = "+str);
                        System.out.println("Default value of short = "+shrt);
                        System.out.println("Default value of long = "+lng);
                        System.out.println("Default value of double = "+dble);
                        System.out.println("Default value of float = "+fl);

            }

}

OutPut:

No comments:

Post a Comment