Ads 468x60px

Monday, July 25, 2011

Data Types of JAVA


Data Types of JAVA
 To represent data values in your code you use literals. Literals are described by types, named by identifiers, and stored in variables, which were outlined earlier in the chapter and are explored further in this section.
When you use literals in your code, they appear in their raw form rather than as a result of an expression. Several types of literals are commonly used: numbers, integers, floating points, characters, Booleans, and strings.
Table 1.1 outlines Java's strict definitions of these data types.

Table 1.1. Rules for Java literals.
Literal TypeTypename Rule
NumberNum Can_ be integer, floating point, or character.
Integer Can be decimal, hexadecimal, or octal.
 Byte 8-bit integers between -128 and 127.
 Short 16-bit integers between -32768 and 32767.
 Int 32-bit integers between -2147483648 and 2147483647.
 Long 64-bit integers between -9223372036854775808 and 9223372036854775807 or have L or l appended to them.
 Hex Preceded by 0x or 0X.
 Oct Preceded by 0.
Floating point Any number with a decimal point. Can be made exponential by appending an e or E, followed by the exponent.
 Float 32-bit.
 Double 64-bit.
CharacterChar 16-bit integers represented by a single character and enclosed in single quotes.
  In Java, the Unicode character map is used. The following special characters must be represented by escape sequences:
  backspace      \b
  backslash       \\
  carriage return  \r
  double quote   \"
  formfeed        \f
  hex number     \xhh
  horizontal tab   \t
  newline         \n
  octal number    \000
  question mark  \q
  single quote     \'
  vertical tab      \v
BooleanBoolean Can only be true or false. Are not represented by 0 or 1.
StringString Zero or more characters enclosed in double quotes.

Literals are described by identifiers. Identifiers are sequences of letters and digits, and can also be used to describe variables, methods, and classes. Identifiers can consist of any letter from a to z, underscore, dollar sign, digits from 0 to 9 (except as the first character); identifiers are case-sensitive.
Java has several reserved keywords that are its own identifiers, which cannot be used as identifiers in any way other than that defined by Java, as listed in Table 1.2. Though these words are reserved, not all are used in the most recent release.


Table 1.2. Reserved keywords.
Abstract elseint short
boolean extendsinterface static
break finallong super
byte finallynative switch
case floatnew synchronized
cast fornull this
catch futureoperator throw
char genericouter throws
class gotopackage transient
const ifprivate try
continue implements protectedvar
default importpublic void
do innerrest volatile
double instanceof returnwhile 

0 comments:

Post a Comment