google Ads

Sunday, July 19, 2009

Data Types

Data Types



Java defines eight simple types of data:

byte
short
int
long
char
float
double
boolean

These 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.


JAVA LANGUAGE

The simple types represent single values—not complex objects. Although Java is
otherwise completely object-oriented, the simple types are not. They are analogous to
the simple types found in most other non–object-oriented languages. The reason for
this is efficiency. Making the simple types into objects would have degraded performance too much.

The simple types are defined to have an explicit range and mathematical behavior.
Languages such as C and C++ allow the size of an integer to vary based upon the
dictates of the execution environment. However, Java is different. Because of Java’s
portability requirement, all data types have a strictly defined range. For example, an
int is always 32 bits, regardless of the particular platform. This allows programs to be
written that are guaranteed to run without porting on any machine architecture. While
strictly specifying the size of an integer may cause a small loss of performance in some environments, it is necessary in order to achieve portability.

No comments:

Post a Comment