NJCTL Java Complete Study Guide
Section 1: Variables and Data Types
Primitive types: int, double, boolean, char
- int: whole numbers
- double: decimals
- boolean: true/false
- char: single character, use single quotes
Strings: sequence of characters, use double quotes
- Important methods: .length(), .charAt(index), .substring(start, end), .equals(string), .toLowerCase(),
.toUpperCase(), .indexOf(char/string)
Constants: use final keyword
Example:
final int MAX = 100;
Variable rules: letters, numbers, _, no spaces, cannot start with a number
Example:
int age = 16;
double gpa = 3.7;
boolean isStudent = true;
char grade = 'A';
String name = "AP CSA";
Section 2: Operators
Arithmetic operators: +, -, *, /, %
Increment/Decrement: ++, --
Comparison operators: ==, !=, <, >, <=, >=
Logical operators: &&, ||, !
Assignment operators: =, +=, -=, etc.
Example:
int x = 5;
x += 3; // x = 8
boolean test = (x > 5) && (x < 10); // true
Section 3: Conditional Statements
if, if-else, if-else if-else
Nested conditionals
Switch statements (switch-case)
Boolean expressions and logic
FRQ tips: always test all cases
Example:
int score = 85;
if (score >= 90) {
[Link]("A");
} else if (score >= 80) {
[Link]("B");
} else {
[Link]("C");
}