Java Data Types

Data types in any of the language means that what are the various type of data the variables can have in that particular language. Information is stored in a computer memory with different data types. Whenever a variable is declared it becomes necessary to define data type that what will be the type of data that variable can hold.

Data Types available in java are:

  1. Primary Data Type (Java supports 8 primitive data types): byte, short, int, long, float, double, char and boolean.
  2. Non-Primitive Data Types: string, array etc.

Integer Types

byteSigned integer08 bit or
1 byte
-27 to 27-1 or
-128 to 127
shortSigned integer016 bit or
2 bytes
-215 to 215-1 or
-32768 to 32767
intSigned integer032 bit or
4 bytes
-231 to 231-1 or
-2147483648 to 2147483647
longSigned integer064 bit or
8 bytes
-263 to 263-1 or
-9223372036854775808 to

Rational Numbers

floatIEEE 754 floating point
0.0f32 bit or
4 bytes
±1.4E-45 to
doubleIEEE 754 floating point
0.064 bit or
8 bytes
±439E-324 to


charUnicode character
\u000016 bits or
2 bytes
0 to 216-1 or
\u0000 to \uFFFF


booleantrue or falsefalse1 bittrue or false

Data Types and Variable Declarations in Java

class DataTypes{
     public static void main(String args[]){
        byte byteVar = 5;
        short shortVar = 20;
        int intVar = 30;
        long longVar = 60;
        float floatVar = 20;
        double doubleVar = 20.123;
        boolean booleanVar = true;
        char charVar ='W';
        System.out.println("Value Of byte Variable is " + byteVar);
        System.out.println("Value Of short Variable is " + shortVar);
        System.out.println("Value Of int Variable is " + intVar);
        System.out.println("Value Of long Variable is " + longVar);
        System.out.println("Value Of float Variable is " + floatVar);
        System.out.println("Value Of double Variable is " + doubleVar);
        System.out.println("Value Of boolean Variable is " + booleanVar);
        System.out.println("Value Of char Variable is " + charVar);
Program Output:


                                                                      ⏪ PREVIOUS PAGE          NEXT PAGE ⏩

No comments:

Post a Comment