1/21
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Data Types
Describe possible operations on the data and the storage method. In Java, they are classified into primitive (standard) and abstract (derived) data types.
Primitive Data Types
Built into the Java language, not objects, and have no methods. Includes byte, short, int, long, float, double, char, boolean.
Byte
Smallest integer type, stores values from -128 to 127, size 8-bit.
Short
Integer type, range -32,768 to 32,767, size 16-bit.
Int
Most commonly used integer type, range -2,147,483,648 to 2,147,483,647, size 32-bit.
Long
Large integer type, suffix L must be added, size 64-bit.
Float
Single precision floating-point, used for fractional numbers, suffix f required, size 32-bit.
Double
Double precision floating-point, default for decimals in Java, size 64-bit.
Char
Stores a single character (Unicode), size 16-bit, range 0 to 65,535.
Boolean
Logical type with only true or false values, size 1-bit.
Abstract Data Types
Based on primitive types but with more functionality. Example: String, used to store characters, symbols, and words.
Variable
A named memory location that stores data, which can change during program execution.
Constant
Similar to variables but values cannot be changed once assigned.
Variable Naming Rules
Must be meaningful, unique, start with a letter, dollar sign, or underscore, cannot use keywords, and avoid symbols/spaces.
Variable Naming Conventions
Use meaningful names, start with lowercase, use camelCase for multi-word names (e.g., empGender
).
Default Values of Variables
Primitive types have defaults (e.g., int = 0, float = 0.0, boolean = false, char = '\u0000'). Objects (like Strings) default to null.
Literals
Constant values directly assigned to variables.
Boolean Literals
Types of Literals
true
, false
Integer Literals
Types of Literals
Decimal, octal (0
prefix), hexadecimal (0x
prefix), binary (0b
prefix)
Floating-point Literals
Types of Literals
Numbers with decimal, require F/f suffix for floats
Character Literals
Types of Literals
Single characters in ' '
, can use Unicode or escape sequences ('\n'
, '\t'
)
String Literals
Types of Literals
Sequence of characters in " "