Java Primitive DataTypes

Java has 8 primitive data types. All Java objects are made upon these primitive data types. Primitive DataType variable store actual value in memory while Java Object variables store address of corresponding object.

boolean ::: default value: false ; space requirement : 1 byte

byte ::: default value: 0 ; space requirement : 1 byte

short ::: default value: 0 ; space requirement : 2 byte

char ::: default value: ; space requirement : 2 byte

integer ::: default value: 0 ; space requirement : 3 byte

float ::: default value: 0.0 ; space requirement : 3 byte

double ::: default value: o.o ; space requirement : 4 byte

long ::: default value: 0 ; space requirement : 4 byte

Primitive DataType variable store actual value in memory while Java Object variables store address of corresponding object.

=> Easiest way to remember primitive DataTypes and corresponding space requirement is : bb sc if dl

=> floating point data type values should be suffixed by f or F else it will be recognized as double data type.

=> long data type values should be suffixed by l or L else it will be recognized as integer data type.

public class Pdt {

	boolean vbool ;
	byte vbyte;

        short vshort ;
        char vchar ;
    
	int vint ;
	float vfloat ;
	
	double vdouble;
	
	long vlong ;
	
	public static void main(String[] args) {
  Pdt obj1 = new Pdt() ;
		
		System.out.println("Default values "+""
				+ " \n boolean:"+obj1.vbool 
				+ "\n byte:"+obj1.vbyte
				+"\n short:"+obj1.vshort
				+"\n char:"+obj1.vchar
				+"\n integer:"+obj1.vint
				+"\n float:"+obj1.vfloat
				+"\n double:"+obj1.vdouble
				+"\n long:"+obj1.vlong);
       
	}
	
	int vint1 = 10 ;
	long vlong1 = 10L ;  // long data type values should be suffixed by l or L
	double vdouble1 = 100.0 ;
	float vfloat1 = 100.0F ; // float data type values should be suffixed by f or F
}

Output:

Default values 
 boolean:false
 byte:0
 short:0
 char:
 integer:0
 float:0.0
 double:0.0
 long:0

For Your kind attention Please –

If you are preparing for Java Certificate exam, You can take a Practice Test by clicking here. Practice Test have real exam questions. Thus it will ensure that you pass your Certificate Exam without any surprise.

  If you want to crack an interview for the Java Developer role, a demo interview will fortify your chances. Thus, Book an interview preparation session.

Workspace in use - Eclipse Error

Leave a Comment

Your email address will not be published.

Shopping Cart