Mixed Deck — All SCJP Topics Flashcards
100 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 20 Mixed Deck — All SCJP Topics flashcards as text
What is the difference between `Iterator` and `ListIterator` in Java?
Answer: ListIterator can traverse in both directions; Iterator is forward-only
`ListIterator` extends `Iterator` with the ability to traverse a list in both forward and backward directions and also supports `add()` and `set()`.
What is a race condition in Java concurrency?
Answer: Unpredictable behavior caused by multiple threads accessing shared data without proper synchronization
A race condition occurs when the program's outcome depends on the non-deterministic ordering of unsynchronized thread operations.
Which class should be used to format a number as currency for a specific locale in Java?
Answer: java.text.NumberFormat obtained via NumberFormat.getCurrencyInstance(locale)
`NumberFormat.getCurrencyInstance(Locale)` returns a NumberFormat preconfigured for the currency of the given locale. While DecimalFormat can approximate it, the standard SCJP answer is `NumberFormat.getCurrencyInstance()`. java.util.Currency represents a currency but doesn't format numbers.
In Java, can a class implement more than one interface?
Answer: Yes, with a comma-separated list
A Java class can implement multiple interfaces by listing them with commas: `class Foo implements A, B, C`.
Which keyword is used to prevent method overriding in Java?
Answer: final
Declaring a method as 'final' prevents it from being overridden in any subclass.
What happens when `Thread.start()` is called more than once on the same Thread object?
Answer: An IllegalThreadStateException is thrown
Once a thread has been started and has terminated, calling `start()` again on the same Thread object throws `IllegalThreadStateException`.
Which statement about Java interfaces is correct for SCJP?
Answer: Interface fields are public static final by default
All fields declared in an interface are implicitly `public static final` (constants).
Which Java I/O class should be used to write primitive data types (int, double, boolean) to a stream?
Answer: DataOutputStream
`DataOutputStream` provides methods like `writeInt()`, `writeDouble()`, and `writeBoolean()` for writing primitive data types in a portable binary format.
What happens if an exception is thrown inside a `finally` block?
Answer: It replaces any exception from the try/catch block
An exception thrown inside a `finally` block propagates upward and discards any exception that was in progress from the `try` block.
Which of the following best describes the order in which a component is redrawn as a result of method calls?
Answer: invoke repaint() which invokes update(), which in turn invokes paint()
When a component needs to be redrawn, the `repaint()` method is typically invoked. This method does not draw directly but schedules an update request. The AWT event dispatcher then calls the `update()` method, which by default clears the component's background and then calls the `paint()` method to perform the actual drawing.
A thread is in the WAITING state. Which of the following can transition it back to the RUNNABLE state?
Answer: Another thread calling notify() on the object it is waiting on
A thread in WAITING state is moved to RUNNABLE when another thread calls `notify()` or `notifyAll()` on the object the waiting thread holds a lock on.
Can a non-static inner class declare static members?
Answer: Yes, but only static final constant fields
In Java, a non-static inner class may declare static final constant fields (compile-time constants) but cannot declare other static members. This is because the inner class is associated with an outer instance and full static context would be ambiguous.
Which of the following correctly creates a Locale for French as spoken in France?
Answer: new Locale("fr", "FR")
The Locale(String language, String country) constructor takes ISO 639-1 language code ('fr') and ISO 3166-1 country code ('FR'). Language codes are lowercase, country codes are uppercase. 'France' and 'French' are display names, not codes.
Which of the following accurately describes the main() method of an application?
Answer: public static void main( String args[] );
In Java, the `main` method serves as the entry point for any standalone application. Its signature must strictly be `public static void main(String[] args)`. `public` allows universal access, `static` enables calling without an object, `void` signifies no return value, and `String[] args` is an array for command-line arguments. Any deviation from this specific signature will prevent the Java Virtual Machine (JVM) from recognizing it as the application's starting point.
If comp is a __________, the Container methods add(Component comp) and add(String name, Component comp) will raise an IllegalArgumentException.
Answer: window
In AWT, `Window` objects (which include `Frame` and `Dialog`) are top-level containers and cannot be added to other `Container` objects using the `add()` methods. Attempting to add a `Window` to another `Container` will result in an `IllegalArgumentException` because `Window` objects are designed to be standalone and not nested within other components.
In Java, what is the default behavior when a thread encounters an uncaught exception?
Answer: The thread terminates and the JVM continues
When a thread's `run()` method throws an uncaught exception, that thread terminates but other threads and the JVM continue running.
What exception is thrown when a thread that is blocked in `sleep()` or `wait()` has its `interrupt()` method called?
Answer: InterruptedException
`InterruptedException` is a checked exception thrown when a thread's interrupted status is set while it is blocked in a wait, sleep, or join.
What is the effect of marking a class member as `private`?
Answer: Accessible only within the declaring class
`private` is the most restrictive access modifier, limiting access to only the class in which the member is declared.
What happens when the following code is compiled? void test() { return; System.out.println("hello"); }
Answer: It fails to compile due to unreachable code
The Java compiler detects unreachable statements and reports a compile-time error. The `System.out.println` after an unconditional `return` can never execute, so the class will not compile.
What is the purpose of the `super` keyword when used inside a method body?
Answer: To access superclass methods or fields hidden by the subclass
`super` in a method body refers to the superclass, allowing access to its overridden methods or hidden fields.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy