Literals
An Introduction with Examples in Java |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
Type | Example |
byte
|
N/A |
short
|
N/A |
int
|
83 |
long
|
83L |
float
|
2.9f |
double
|
2.9 |
char
|
'd' |
boolean
|
true |
100,000
is not a valid int
literal) but you can
use an underscore (e.g., 100_100
is a valid
int
literal)1.
is a double
literal)
'a'
, '7'
,
'['
)'\''
)
'\\'
)'\t'
is the tab literal'\n'
is the newline literal'\r'
is the carriage return literal'\"'
is the double quote literal (the need for which
will become apparent later)char
(a string of a single character is used instead)char
literals and double quotes are used for
String
literalsTrue
and False
are used
(instead of true
and false
)