Data Types in Java

In Java, Data types are classified into two categories:

1. Primitive Data Type

2. Non-Primitive Data Type

there are 8 primitive data types:

char  boolean  byte  short  int   long   float  double

8 primitive can be classfiied into 4 groups;

group 1: Integer

byte : It is 8 bit integer data type. Value range from -128 to 127. Default value zero. example: byte b=10;

short : It is 16 bit integer data type. Value range from -32768 to 32767. Default value zero. example: short s=11;

int : It is 32 bit integer data type. Value range from -2147483648 to 2147483647. Default value zero. example: int i=10;

long : It is 64 bit integer data type. Value range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Default value zero. example: long l=100012;

group 2: Floating-Point Number

float : It is 32 bit float data type. Default value 0.0f. example: float ff=10.3f;

double : It is 64 bit float data type. Default value 0.0d. example: double db=11.123;

group 3: characters

char : It is 16 bit unsigned unicode character. Range 0 to 65,535. example: char c='a';

group 4: boolean

This group represent boolean, which is a special type for representing true/false values. They are defined constant of the language. example: boolean b=true;

2) Non-Primitive (Reference) Data Type:

A reference data type is used to refer to an object. A reference variable is declare to be of specific and that type can never be change. We will talk a lot more about reference data type later in Classes and Object lesson.

原文地址:https://www.cnblogs.com/morningdew/p/5618472.html