Flashcards · Java · Free
Java flashcards, generated for you.
Example Java study cards to learn from right now — then generate a full set from your own notes (plus a practice quiz) and export to Quizlet or Anki. Free, no account needed.
Example Java flashcards
What is the difference between '==' and '.equals()' when comparing strings in Java?
'==' compares object references (memory addresses); '.equals()' compares the actual string content. Always use '.equals()' for string comparison to avoid bugs.
Why does this code print 'false'? int a = 5; Integer b = 5; System.out.println(a == b);
It prints 'true', not false. When comparing int and Integer, Java auto-unboxes Integer to int, so the values are compared. However, Integer.valueOf(257) == Integer.valueOf(257) is false due to caching limits (-128 to 127).
What is the scope and lifetime of a variable declared in a for-loop: for(int i=0; i<10; i++)?
The variable 'i' is scoped to the for-loop block only and ceases to exist after the loop ends. It cannot be accessed outside the loop.
What does 'null' represent, and what exception occurs when you call a method on a null reference?
'null' is the absence of an object reference. Calling a method on null throws a NullPointerException (NPE) at runtime.
Explain the difference between a primitive type and a reference type in Java.
Primitive types (int, boolean, double, etc.) store values directly in memory and are passed by value. Reference types (objects, arrays, strings) store memory addresses and are passed by reference.
What is the default value of instance variables for int, boolean, and String in a class?
int defaults to 0, boolean defaults to false, and String (reference type) defaults to null. Local variables have no default value and must be initialized before use.
What is the difference between a static method and an instance method? Can a static method access instance variables?
Static methods belong to the class and are called via the class name (no object needed). Instance methods belong to objects and require an instance. Static methods cannot access instance variables or non-static methods without an object reference.
Why might this array iteration cause an IndexOutOfBoundsException? for(int i=0; i<=array.length; i++) System.out.println(array[i]);
The loop uses i<=array.length, but valid indices are 0 to array.length-1. When i equals array.length, accessing array[i] throws IndexOutOfBoundsException. Use i<array.length instead.
What is the difference between String, StringBuilder, and StringBuffer in terms of mutability and thread-safety?
String is immutable and thread-safe. StringBuilder is mutable but NOT thread-safe (faster for single-threaded use). StringBuffer is mutable AND thread-safe (slower due to synchronization).
Explain method overloading and method overriding. Can you overload by return type alone?
Overloading: same method name, different parameters, same class (compile-time). Overriding: same name and parameters, different class in hierarchy (runtime). You cannot overload by return type alone; parameters must differ.
Make your own Java study set
Flashcards for related topics
Studying Java to build with AI? MindloomHQ turns it into real skills — structured courses, agent projects, and certificates.
Explore MindloomHQ →