- Java Overview
- JDK, JRE, JVM
- Compilation to Bytecode
- Syntax Basics (Identifiers, Keywords, Literals, Comments)
- Data Types and Ranges
- Variables, Scope, Lifetime, Shadowing
- Operators (Arithmetic, Relational, Logical, Bitwise, Shift, Ternary)
- Type Conversion and Casting
- Control Flow (if/switch/loops/labels)
- Arrays (1D/2D), Varargs
- Strings and String Pool
- Wrapper Classes, Autoboxing/Unboxing
- Packages and Imports
- Access Modifiers and Other Modifiers (static, final, abstract, sealed)
- Initialization Order (static/instance blocks, constructors)
- Assertions
- Logging (java.util.logging) quick intro
- Common Utilities (Objects, Math, Random, UUID)
Java is a statically-typed, object‑oriented, general‑purpose language. Source code (.java) is compiled to bytecode (.class) and executed by the JVM. Write once, run anywhere.
- JDK: Compiler (javac), tools, and JRE for development.
- JRE: Runtime libraries and JVM for running applications.
- JVM: Loads, verifies, JIT‑compiles, and executes bytecode.
javac Hello.java
java Hellojavac produces .class files. The JVM uses a class loader, verifier, and execution engine to run them.
- Identifiers: letters, digits,
_,$(not recommended for public APIs). - Keywords: class, interface, enum, if, else, switch, try, catch, finally, return, etc.
- Literals: numeric (10, 0xFF), char ('a'), string ("abc"), boolean (true/false), text blocks (Java 15+).
- Comments: //, /* ... /, /* javadoc */.
- Primitives: byte(8), short(16), int(32), long(64), float(32), double(64), char(16), boolean(1 bit logical).
- Reference types: arrays, classes, interfaces, enums, records.
Example:
int a = 10;
long b = 10L;
double d = 10.5;
char c = 'A';
boolean ok = true;- Local variables live on the stack frame and must be initialized before use.
- Instance variables get default values.
- Shadowing occurs when a local variable has the same name as a field.
class ShadowingExample {
int value = 10;
void show() {
int value = 5; // shadows the field
System.out.println(value); // 5
System.out.println(this.value); // 10
}
}- Arithmetic: + - * / %
- Relational: == != > >= < <=
- Logical: && || !
- Bitwise: & | ^ ~
- Shift: << >> >>>
- Ternary: cond ? a : b
int x = 5, y = 2;
int div = x / y; // 2
double exact = x / 2.0; // 2.5
int mask = 0b1010 & 0b1100; // 0b1000- Widening: automatic (int → long).
- Narrowing: explicit cast (long → int). Beware overflow.
long big = 1_000_000_000_000L;
int small = (int) big; // overflow- if/else, switch (supports strings and enums), loops (for, enhanced for, while, do-while), break, continue, labeled break.
switch (day) {
case "MON": case "TUE": System.out.println("Weekday"); break;
default: System.out.println("Other");
}- Fixed-size, zero-indexed, length property.
- Varargs compile to arrays; only one varargs parameter at end of signature.
int[] a = {1, 2, 3};
int[][] m = { {1,2}, {3,4} };
static int sum(int... nums) {
int s = 0;
for (int n : nums) s += n;
return s;
}- Immutable; literals stored in string pool for sharing.
- Use StringBuilder for frequent concatenation.
String s1 = "java";
String s2 = "java";
System.out.println(s1 == s2); // true (same pool entry)- Integer, Long, Double, etc.
- Beware NullPointerException during unboxing.
Integer i = null;
// int n = i; // NPEOrganize types into namespaces. Import types with import pkg.Type; or import pkg.*;
- Access: public, protected, package‑private, private.
- Other: static, final, abstract, synchronized, native, strictfp, transient, volatile, sealed (17), non‑sealed.
- Static fields/blocks (parent → child)
- Instance fields/blocks (parent → child)
- Constructors (parent → child)
Enable with -ea. Do not use for argument validation in public APIs.
assert x > 0 : "x must be positive";import java.util.logging.Logger;
Logger log = Logger.getLogger("app");
log.info("starting");Objects.requireNonNull, Objects.equals; Math; Random and ThreadLocalRandom; UUID.