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
Find Unique Elements In List Java Miscellaneous 07-10-2023
Java Program To Implement A Custom equals() and hashcode() In Java Miscellaneous 07-10-2023
Java Program To Find The Intersection Of Two HashSets Miscellaneous 07-10-2023
Java Program To Remove Duplicate Elements From List Miscellaneous 07-10-2023
Java program to parse a date and time string from a log file and store it in a database Miscellaneous 19-09-2023
Java Program To Print All The Dates In A Month That Fall On A Weekend Miscellaneous 19-09-2023
Java Program To Find Number Of Working Days In A Month Miscellaneous 19-09-2023
Java Program To Calculate Age From Year Of Birth Miscellaneous 16-09-2023
How To Check If Two Strings Are Anagrams In Java Miscellaneous 22-08-2023
Java Program To Make A Snake Game Miscellaneous 15-08-2023
Java Program To Find Repeated Characters Of String Miscellaneous 15-08-2023
String To Array In Java Miscellaneous 11-08-2023
Java Program To Convert Date To String Miscellaneous 11-08-2023
Java Program To Convert String To Date Object Miscellaneous 11-08-2023
Java Program To Find Number Of Days In A Month Miscellaneous 11-08-2023
Java Program To Print First And Last Day Of Month Miscellaneous 11-08-2023
Java Program To Find Leap Year Between Two Dates Miscellaneous 11-08-2023
Java Code To Find Difference Between Two Dates In Years Months And Days Miscellaneous 11-08-2023
Java program to calculate age from year of birth Miscellaneous 29-06-2023
Swap Two Numbers Without Using Third Variable In Java Miscellaneous 02-06-2023
Java Program To Find The Average Of An Array Of Numbers Miscellaneous 02-06-2023
How Do You Find The Factorial Of A Number In Java Miscellaneous 02-06-2023
Java Program That Takes Two Numbers As Input And Prints Their Sum Miscellaneous 27-05-2023
How To Get The Length Of An Array In Java Miscellaneous 27-05-2023
Java Add Element To List Example Miscellaneous 19-05-2023
Java Program To Square All Items In List Miscellaneous 17-05-2023
Java Program To Merge Two Lists Miscellaneous 17-05-2023
How To Reverse A List In Java Miscellaneous 17-05-2023
Java Program To Find Unique Elements In An Array Miscellaneous 14-05-2023
Java Program To List All Elements In List Miscellaneous 30-04-2023

1 2