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.
Literal Type | Typename | Rule |
Number | Num | 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. | |
Character | Char | 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 | ||
Boolean | Boolean | Can only be true or false. Are not represented by 0 or 1. |
String | String | 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.
Abstract | else | int | short |
boolean | extends | interface | static |
break | final | long | super |
byte | finally | native | switch |
case | float | new | synchronized |
cast | for | null | this |
catch | future | operator | throw |
char | generic | outer | throws |
class | goto | package | transient |
const | if | private | try |
continue | implements | protected | var |
default | import | public | void |
do | inner | rest | volatile |
double | instanceof | return | while |
0 comments:
Post a Comment