javatutelearn.com

Easy Learning


Home

Search Javatutelearn.com :


Java Datatypes

  • Datatype is used to store user data.
  • Datatype is used to specify type of data to be stored. If data is of integer type, then datatype should be of integer type.
  • Datatype facilitates operations that are applicable on data. For example, integer datatype facilitates arithmetic operation on the data.
  • Datatype defines name of the variable that stores user data as well as type of data that is being stored in the variable.
  • Java defines many basic datatypes for storing the data which are listed below.

Datatypes

Byte datatype

  • It is signed integer.
  • Size of datatype is 8 bits.
  • Example
    	       byte a = 10;
    	 

Short datatype

  • It is signed integer.
  • Size of datatype is 16 bits.
  • Example
    	      short b=100;
    	

Integer datatype

  • It is signed integer.
  • Size of datatype is 32 bits.
  • Example
    		  int c = 20000;
    	

Long datatype

  • It is signed integer.
  • Size of datatype is 64 bits.
  • Example
    		long d = 200000;
    	

Float datatype

  • It stores number with decimal point.
  • It is single precision floating point datatype.
  • Example
    		float k = 12.5;
    	

Double datatype

  • It stores number with decimal point.
  • It is double precision floating point datatype.
  • Example
    		double l = 12356.67;
    	

Boolean datatype

  • It stores two values only.
  • It stores either True or False.
  • Example
    		boolean n = True;
    	

Character datatype

  • It stores character data.
  • Size of datatype is 16 bits.
  • It uses Unicode to represent characters.
  • Example
    		char p = 'A'; 	// Use single quotes symbol for enclosing character content.
    	

Example (All datatypes)

class datatype {

   public class static void main(String args[])
	{
		byte a = 10;
		short b = 100;
		int c = 20000;
		long d = 200000;
        		float k = 12.5;
		double l = 12356.67;
		boolean n = True;
		char p = 'A';
		System.out.println("value of byte is " + a);
		System.out.println("value of short is " + b);
		System.out.println("value of int is " + c);
		System.out.println("value of long is " + d);
		System.out.println("value of float is " + k);
		System.out.println("value of double is " + l);
		System.out.println("value of boolean is " + n);
		Syatem.out.println("value of char is "+ p);
	}
}

Output of the program

value of byte is 10
value of short is 100
value of int is 20000
value of long is 200000
value of float is 12.5
value of double is 12356.67
value of boolean is True
value of char is A





© Copyright 2016-2024 by javatutelearn.com. All Rights Reserved.