Professional Documents
Culture Documents
2023 - 01 - 13 - Variables, Primitives
2023 - 01 - 13 - Variables, Primitives
Section B Page 1
Variable declarations
Section B Page 2
Primitive types and their sizes
char: any single char ('q', 'Q', 'x', 'Z', '@', etc.) -- 16 bits
• ASCII (8-bits, used in older languages), Java uses Unicode (16 bits) to represent more
characters. This is the way that the character values get converted (encoded) into
binary for the computer to understand
"Literal" values
• "Hardcoded" or "magic" numbers
• Typically used in expressions or on the RHS (right hand side) of an assignment.
• int num = 10; // 10 is an integer literal
• double pi = 3.1415; // 3.1415 is a double literal
• float f = 3.1415f; // or 3.1415F (notice the F, it indicates the literal must be a float)
• long l = 10L; // or 10l (notice the L, it indicates the literal must be a long)
• char c = 'Q'; // enclose char literals in single quotes
• String s = "Hello!"; // enclose String literals in double quotes
• boolean b = true; // true and false are the boolean literals
Section B Page 3
Assigned "Reading"
Modules -> General Information -> TA Created Help Videos -> Debugging Series
Section B Page 4