Identifiers Data Types Literals Escape Sequence
Identifiers Data Types Literals Escape Sequence
Programming
• Identifiers
• Data Types
• Literals
• Escape Sequence
Identifiers - Symbolic Names
• Identifier are used to name classes, variables
and methods.
• Identifier Rules:
• Must start with a "Java letter"
Example declarations:
int numPlayers, highScore, diceRoll;
short xCoordinate, yCoordinate;
byte ageInYears;
long cityPopulation;
Floating-Point Data Types
Type Size Minimum Value Maximum Value
in Bytes
float 4 1.4E-45 3.4028235E38
double 8 4.9E-324 1.7976931348623157E308
Example declarations:
float salesTax;
double interestRate;
double paycheck, sumSalaries;
char Data Type
Type Size Minimum Value Maximum Value
in Bytes
char 2 character character
encoded as 0 encoded as FFFF
Example declarations:
char finalGrade;
char newline, tab, doubleQuotes;
boolean Data Type
• Two values only:
true
false
• Used for decision making or as "flag"
variables
• Example declarations:
boolean isEmpty;
boolean passed, failed;
Integer Literals
• int, short, byte
• Optional initial sign (+ or -) followed by digits 0
– 9 in any combination.
• long
• Optional initial sign (+ or -) followed by digits
0–9 in any combination, terminated with an L
or l.
Floating-Point Literals
• float
• Optional initial sign (+ or -) followed by a floating-point
number in fixed or scientific format, terminated by an F
or f.
• double
• Optional initial sign (+ or -) followed by a floating-point
number in fixed or scientific format.
• Commas, dollar signs, and percent signs (%)
cannot be used in integer or floating-point literals
char and boolean Literals
• char
• Any printable character enclosed in single
quotes
• A decimal value from 0 – 65535
• boolean
true or false
String Literals
• String is actually a class, not a basic data type;
String variables are objects
• String literal: text contained within double quotes.
• Example of String literals:
"Hello"
"Hello world"
"The value of x is “
Escape Sequences
• To include a special character in a String, use
an escape sequence
Character Escape Sequence
Newline \n
Tab \t
Double quotes \"
Single quote \'
Backslash \\
Backspace \b
Carriage return \r
Form feed \f