Data Types in Java ( Part 1)

              For the most commonly used data types, Java provides the following base types
              (also called primitive types):

                                                         boolean        a boolean value: true or false
                                              char             16-bit Unicode character
                                              byte              8-bit signed two’s complement integer
                                              short            16-bit signed two’s complement integer
                                              int                32-bit signed two’s complement integer
                                              long             64-bit signed two’s complement integer
                                             float              32-bit floating-point number (IEEE 754-1985)
                                             double          64-bit floating-point number (IEEE 754-1985)

                     A variable having one of these types simply stores a value of that type. Integer
                     constants, like 14 or 195, are of type int, unless followed immediately by an ‘L’
                     or ‘l’, in which case they are of type long. Floating-point constants, like 3.1416
                     or 6.022e23, are of type double, unless followed immediately by an ‘F’ or ‘f’, in
                     which case they are of type float. Code Fragment 1.1 demonstrates the declaration,
                     and initialization in some cases, of various base-type variables

               1 boolean flag = true;
               2 boolean verbose, debug;            // two variables declared, but not yet initialized
               3 char grade = ‘A’;
               4 byte b = 12;
               5 short s = 24;
               6 int i, j, k = 257;                         // three variables declared; only k initialized
               7 long l = 890L;                           // note the use of ”L” here
               8 float pi = 3.1416F;                    // note the use of ”F” here
               9 double e = 2.71828, a = 6.022e23;   // both variables are initialized

                              Declarations and initializations of several base-type variables.
                                                         Primitive data types table:



we have four reference data type :

1. Array   2. Class   3. Interface   4.enum

Data Types in Java ( Part 1)

Data Types in Java ( Part 2)

Leave a Comment

Your email address will not be published. Required fields are marked *