Data Types In Java

Chapter: Miscellaneous Last Updated: 09-06-2018 12:55:35 UTC

Program:

            /* ............... START ............... */
                
public class JavaDataTypes {

    public static void main(String args[]){
        /* Boolean Type  */
        boolean value = true;
        System.out.println("Boolean Value : "+value);

        /* Char Type */
        char c = 'A';
        System.out.println("Character Val : "+c);

        /* Byte type */
        byte byteval = 127;  // 127 is byte max value (Range : -128...127)\
        System.out.println("Byte Val : "+byteval);

        /* Short Type */
        short shortVal = 32767; // 32767 is short max value (Range : -32768...32767)
        System.out.println("Short Val : "+shortVal);

        /* Int Type */
        int intVal = 2147483647; // 2147483647 is int max value (Range : - 2147483648...2147483647)
        System.out.println("Int Val : "+intVal);

        /* Long Type */
        long longVal;
        longVal = 9223372036854775807L;
        /* 9223372036854775808 is the max value (Range : -9223372036854775808... 9223372036854775807) */
        System.out.println("Long Val : "+longVal);

        /* Float Type */
        float floatVal;
        floatVal = 3.14f;
        System.out.println("Int Val : "+floatVal);

        /* Double Type */
        double doubleVal;
        doubleVal = 13.36d;
        System.out.println("Double Val : "+doubleVal);


    }

}

                /* ............... END ............... */
        

Output

Boolean Value : true
Character Val : A
Byte Val : 127
Short Val : 32767
Int Val : 2147483647
Long Val : 9223372036854775807
Float Val : 3.14
Double Val : 13.36

Notes:

  • In java there are eight primitive types boolean, char, byte, short, int, long, float, double.
  • boolean is a one byte data types which stores the value as tree or false. Default value is false.
  • char data type is a 16-bit Unicode character (Min Val : '\u0000' or 0 and Max : '\uffff' or 65535 ).
  • byte is 8-bit signed two's complement integer (Min Val : -128 (-2^7) and Max : 127 (2^7 -1)).
  • short is 16-bit signed two's complement integer (Min Val : -32,768 (-2^15) and Max : 32,767 (2^15 -1).
  • int is 32-bit signed two's complement integer (Min Val : - 2,147,483,648 (-2^31) and Max : 2,147,483,647 (2^31 -1).
  • long is 64-bit signed two's complement integer (Min Val : -9,223,372,036,854,775,808(-2^63) and Max : 9,223,372,036,854,775,807 (2^63 -1).
  • float is single-precision 32-bit IEEE 754 floating point. Default value is 0.0f.
  • double is double-precision 64-bit IEEE 754 floating point. Default value is 0.0d.

Tags

Java Data Types, Primitive data types

Similar Programs Chapter Last Updated
Java Program To Find Largest Element Of Array Miscellaneous 21-09-2017
Java Program To Check Whether Number Is Prime Or Not Miscellaneous 08-09-2017
Java Program To Find Power Of Number Using For Loop Miscellaneous 29-08-2017
Java Program To Find LCM Of Two Numbers Miscellaneous 29-08-2017
Java Program To Find GCD Of Two Numbers Miscellaneous 29-08-2017
Java Program To Check Whether An Alphabet Is Vowel Or Consonant Miscellaneous 25-08-2017
Java Program To Find ASCII Value Of Character Miscellaneous 25-08-2017
Java Object HashCode Method Miscellaneous 02-08-2017
Java Builder Design Pattern Example Miscellaneous 06-06-2017
Java Factory Design Pattern Example Miscellaneous 06-06-2017
Java Program To Print ASCII Values Miscellaneous 06-04-2017
Java Program To Find HCF LCM Of Two Numbers Miscellaneous 06-04-2017
Java String Array Iteration Miscellaneous 31-03-2017
Java Array Size Miscellaneous 30-03-2017
Java Integer toString Miscellaneous 30-03-2017
Java Sort Array Using Arrays.sort() Miscellaneous 28-03-2017
Java Print Array Using Arrays.toString Miscellaneous 28-03-2017
Java Nested Interface Miscellaneous 25-03-2017
Java Static Nested Class Miscellaneous 25-03-2017
Packages In Java Miscellaneous 24-03-2017
Java Strictfp Keyword Miscellaneous 24-03-2017
Java Call By Reference Miscellaneous 23-03-2017
Java Call By Value Miscellaneous 23-03-2017
Java Unboxing Example Miscellaneous 23-03-2017
Java Autoboxing Example Miscellaneous 23-03-2017
Java Format Currency Miscellaneous 15-02-2017
Java String To BigDecimal Conversion Miscellaneous 15-02-2017
Java Program To Convert Arraylist To Array Miscellaneous 13-02-2017
Java Array Creation And Initialize Miscellaneous 13-02-2017
Java Program To Print Square Pattern Of Star Miscellaneous 16-12-2016

1 2 3 4 5