Java follows C++ to some degree, which carries the benefit of it being familiar
to many programmers. This section describes the essential features of Java and
points out where the language diverges from its ancestors C and C++.
2.1.1 Primitive Data
Other than the primitive data types discussed here, everything in Java is an
object. Even the primitive data types can be encapsulated inside librarysupplied
objects if required. Java follows C and C++ fairly closely in its set of
basic data types, with a couple of minor exceptions. There are only three
groups of primitive data types, namely, numeric types, Boolean types, and
arrays.
Numeric Data Types
Integer numeric types are 8-bit byte, 16-bit short, 32-bit int, and 64-bit long.
The 8-bit byte data type in Java has replaced the old C and C++ char data
type. Java places a different interpretation on the char data type, as discussed
below.
There is no unsigned type specifier for integer data types in Java.
Real numeric types are 32-bit float and 64-bit double. Real numeric types
and their arithmetic operations are as defined by the IEEE 754 specification. A
floating point literal value, like 23.79, is considered double by default; you
must explicitly cast it to float if you wish to assign it to a float variable.
Character Data Types
Java language character data is a departure from traditional C. Java’s char data
type defines a sixteen-bit Unicode character. Unicode characters are unsigned
16-bit values that define character codes in the range 0 through 65,535. If you
write a declaration such as
char myChar = ‘Q’;
you get a Unicode (16-bit unsigned value) type that’s initialized to the Unicode
value of the character Q. By adopting the Unicode character set standard for its
character data type, Java language applications are amenable to
internationalization and localization, greatly expanding the market for worldwide
applications.
Boolean Data Types
Java has added a boolean data type as a primitive type, tacitly ratifying
existing C and C++ programming practice, where developers define keywords
for TRUE and FALSE or YES and NO or similar constructs. A Java boolean
variable assumes the value true or false. A Java boolean is a distinct data
type; unlike common C practice, a Java boolean type can’t be converted to
any numeric type.
2.1 Main Features of the Java Language
Penulis : Unknown on Sunday, October 17, 2010 | 10:04 AM
Related posts:
If you enjoyed this article just click here, or subscribe to receive more great content just like it.
Labels:
core java,
JamesGosling,
java,
Java Tutorials
Subscribe to:
Post Comments (Atom)
Post a Comment