Thursday, July 29, 2010


Literal constants are values that do not change within a program. Numeric constants default to integer or double unless a suffix is appended. Note that a character can be represented by an ASCII equivalent. The literal types are:
  • Boolean: true, false
  • Character: 'c', '\f'
  • String: "Fred", "B and E"
  • Null: null
  • Integer: 5, 0xFF (hexadecimal)
         073 [leading zero] (octal), 5l (long), 0xFFlD (hex)
  • Floating Point: 2.543, -4.1E-6 (double)
         2.543f, 8e12f (float)
Note: Do not use leading zeros to format integers as this can cause an unintended octal meaning. Use spaces instead!
Escape (aka backslash) sequences are used inside literal strings to allow print formatting as well as preventing certain characters from causing interpretation errors. Each escape sequence starts with a backslash. The available sequences are:
SeqUsage SeqUsage
\bbackspace \\backslash
\fformfeed \"double quote
\nnewline \'single quote
\rcarriage return \###Octal encoded character
\thorizontal tab \uHHHHUnicode encoded character

No comments:

Post a Comment