Language fundamentals¶
Variables and primitive types¶
A declaration combines a type, name, and optional initializer:
Java's eight primitive types are byte, short, int, long, float, double, char, and boolean. Reference variables hold references to objects and may contain null.
Type inference¶
For local variables, var asks the compiler to infer the static type from the initializer:
var is not dynamic typing and cannot be used for fields, method parameters, or return types.
Arrays¶
Array indices begin at zero. An invalid index throws ArrayIndexOutOfBoundsException.
Methods¶
A method signature includes its name and parameter types. The return type is not part of overload selection.
Classes¶
final class Counter {
private int value;
void increment() {
value++;
}
int value() {
return value;
}
}
Repository examples¶
src/main/java/nitin/a1languageFundamentalssrc/main/java/nitin/arrayssrc/main/java/nitin/stringssrc/main/java/nitin/a5object