FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 260   



There are 8 Primitive data types in Java, you can categorize them into 4 groups.

  1. Integer data types: byte, short, int & long
  2. Floating Data types: float, double
  3. Character Data types: char
  4. Boolean Data types: boolean
Data Type Size Default Value Range
byte 8-bit 0 -128 to 127
short 16-bit 0 -32,768 to 32,767
int 32-bit 0 -2^31 to 2^31-1
long 64-bit 0L -2^63 to 2^63-1
float 32-bit 0.0f
double 64-bit 0.0d
boolean NA '\u0000' NA
char 16-bit false NA

Following is a sample program with using all primitive datatypes

public class PrimiteDataTypes {

    public static void main(String[] args) {

        byte byteVal = 127;
        short shortVal = 32767;
        int intValue = 2147483647;
        long longValue = 9223372036854775807L;

        float floatValue = 1.5F;
        double doubleVaue = 12.678;

        char charValue = 'f';

        boolean booleanValue = true;

    }
}



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News