Tuesday, February 25, 2014

Java Data Types

Java Data Types

Java defines eight types of data: byte, short, int, long, char, float, double, and boolean.
These data types can be put in four groups:
  • Integers This group includes byte, short, int, and long, which are for whole-valued signed numbers.
  • Floating-point numbers This group includes float and double, which represent numbers with fractional precision.
  • Characters This group includes char, which represents symbols in a character set, like letters and numbers.
  • Boolean This group includes boolean, which is a special type for representing true/false values

Integer








 Floating-Point Types 

 

 

 

 Characters

In Java, the data type used to store characters is char. However, C/C++ programmers beware:

char in Java is not the same as char in C or C++. In C/C++, char is 8 bits wide. This is not the
case in Java, it requires 16 bits. Thus, in Java char is a 16-bit type. The range of a char is 0 to 65,536. There are no negative chars.
  

Booleans

 Java has a primitive type, called boolean, for logical values. It can have only one of two possible values, true or false. This is the type returned by all relational operators, as in the case of a < b. boolean is also the type required by the conditional expressions that govern the control statements such as if and for.

No comments:

Post a Comment