Oracle Java Foundations study materials
Oracle Java Foundations study resources

Oracle Java Foundations flashcards

Oracle Java Foundations · Build recall with a focused review session.

32 cards. Read the term and the definition here. The deck at the top of this page is optional.

main method signature
The JVM entry point must be public static void main(String[] args); static lets it run without an instance, and the return type must be void.
javac versus java
javac compiles .java source files into .class bytecode files, while the java launcher starts the JVM and executes a class that has already been compiled.
Java identifier rules
Identifiers may contain letters, digits, underscore, and dollar sign, must not start with a digit, and cannot be a reserved keyword; Java treats identifiers as case-sensitive.
Java package statement
A package declaration, when present, is the first non-comment statement of a source file, and the directory structure conventionally mirrors the package name.
eight primitive types
Java has eight primitives: byte, short, int, long, float, double, char, and boolean. Only char is unsigned, and boolean is not numeric.
integer literal default type
A plain integer literal such as 100 is an int, and a long needs the L suffix; a decimal literal is a double unless suffixed with F for float.
numeric promotion in arithmetic
byte, short, and char operands are widened to int before arithmetic, so byte b = 1; b = b + 1; fails to compile without a cast.
local variable default value
Local variables declared inside a method have no default and must be assigned before use; instance and static fields default to zero, false, or null.
short-circuit logical operators
&& and || stop evaluating once the outcome is known, whereas & and | always evaluate both operands; all four require boolean operands.
ternary conditional operator
The expression condition ? a : b yields a when the condition is true and b otherwise; the condition must be boolean and both results type-compatible.
switch supported selector types
A switch selector may be byte, short, char, int, their boxed forms, String, or an enum; case labels must be unique compile-time constants.
compound assignment casting
Operators such as += apply an implicit narrowing cast back to the variable's type, so byte b = 1; b += 2; compiles while b = b + 2 does not.
array length field
An array's size is exposed through the final field length, written a.length; length() is a String method and size() belongs to collections.
array default element values
After allocation with new int[5] every element is 0; boolean arrays default to false, char arrays to '\u0000', and object arrays to null.
array initializer syntax
Curly-brace initializers such as int[] a = {1,2}; work only in a declaration; assigning later requires the explicit form new int[]{1,2}.
ArrayIndexOutOfBoundsException cause
Accessing an element with an index below 0 or greater than length-1 throws this unchecked exception at runtime, since valid indexes run from 0 to length-1.
do-while loop guarantee
A do-while loop tests its condition after the body, so the body always executes at least once even when the condition is false initially.
enhanced for limitation
The enhanced for loop iterates arrays and Iterable objects; its loop variable holds a copy, so assigning to it does not modify the array element.
labeled break statement
A label placed before a loop allows break label; or continue label; to exit or continue an outer loop rather than only the innermost one.
method overloading rules
Overloaded methods share a name but differ in parameter count, types, or order; changing only the return type or access modifier is not a valid overload.
Java pass-by-value
Java always passes by value: primitives copy their value and object references copy the reference, so reassigning a parameter never affects the caller's variable.
this() constructor call
this(...) invokes another constructor of the same class and must be the first statement in the constructor body; it cannot be combined with super(...).
varargs parameter rule
A variable-arity parameter written as type... name must be last in the parameter list and is treated inside the method body as an array.
method overriding requirements
An override keeps the same name and parameter list, may narrow the return type, cannot reduce visibility, and cannot throw broader checked exceptions than the parent.
super constructor call
If a subclass constructor omits this(...) and super(...), the compiler inserts a no-argument super() call, which fails to compile when the parent has no such constructor.
instanceof and casting
instanceof tests an object's runtime type and returns false for null; a failing downcast throws ClassCastException, so check with instanceof before casting.
checked versus unchecked exceptions
Checked exceptions extend Exception but not RuntimeException and must be caught or declared; RuntimeException, Error, and their subclasses are unchecked.
finally block execution
A finally block runs whether the try completes normally, throws, or returns; only System.exit or a JVM crash prevents it from executing.
try-with-resources ordering
Resources declared in a try-with-resources header must implement AutoCloseable and are closed automatically in reverse order of their declaration.
StringBuilder mutability
StringBuilder is a mutable character sequence with append, insert, reverse, and delete; it does not override equals, so both == and equals compare references.
String substring indexes
substring(begin, end) returns characters from begin up to but not including end; the single-argument substring(begin) runs through the end of the string.
ArrayList remove overloads
remove(int index) deletes by position and returns the removed element, while remove(Object) deletes the first matching element and returns a boolean.