← All SCJP Flashcard Decks

Sun Certified Java Programmer MCQ Flashcards

7 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 7 Sun Certified Java Programmer MCQ flashcards as text
  1. Which of the following initialization strategies for the array "dayhigh" with seven values is correct?

    Answer: int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21 };

    In Java, an array can be initialized directly at the time of declaration using an initializer list enclosed in curly braces. The syntax `int dayhigh[]` correctly declares an integer array named `dayhigh`. The `{ 24, 23, 24, 25, 25, 23, 21 }` part then initializes this array with the specified seven integer values, with the compiler inferring the array's size from the list.

  2. Which of the following claims regarding garbage collection in Java is accurate?

    Answer: All of the above

    All the statements regarding Java's garbage collection are accurate. The `finalize()` method is called before an object is garbage collected, though its execution time is not guaranteed. It is also best practice for `finalize()` methods to call their superclass's `finalize()` for proper resource cleanup. Lastly, the garbage collector can be explicitly suggested to run using `Runtime.getRuntime().gc()` or `System.gc()`, although the JVM retains control over its actual execution.

  3. Which procedures are necessary to implement the Runnable interface.

    Answer: run()

    The `Runnable` interface in Java is designed to encapsulate a task that can be executed by a thread. It is a functional interface, meaning it declares a single abstract method. This method is `run()`, which contains the actual code that a thread will execute when it starts.

  4. What causes a thread's execution to halt?

    Answer: All of the above

    A thread's execution can halt or pause due to several factors. Invoking `wait()` causes the thread to release its lock and enter a waiting state until notified. The `yield()` method suggests to the scheduler that the current thread is willing to give up its CPU time, allowing other threads to run. Additionally, a higher-priority thread becoming runnable can preempt a lower-priority thread, temporarily halting its execution.

  5. Which of the following methods can modify a String object, s?

    Answer: none of the above will change s

    String objects in Java are immutable, meaning their content cannot be changed after they are created. Methods like `concat()`, `equals()`, and `substring()` do not modify the original String object `s`. Instead, `concat()` and `substring()` return new String objects with the modified content, while `equals()` returns a boolean value indicating equality, leaving the original `s` unchanged.

  6. Which subclass(es) of Component in the following list cannot be instantiated directly:

    Answer: Container

    `Container` is an abstract class in the AWT hierarchy. Abstract classes cannot be instantiated directly; they must be subclassed, and then an instance of the concrete subclass can be created. `Frame`, `Panel`, and `Dialog` are all concrete subclasses of `Container` and can therefore be instantiated directly.

  7. If a variable-width font is used to create the string text for a column, the column's starting size is:

    Answer: determined by the number of characters in the string, multiplied by the average width of a character in this font

    For variable-width fonts, each character can have a different width. Therefore, simply multiplying by a single character width would not accurately determine the column's size. Instead, the starting size is estimated by considering the total number of characters in the string and multiplying it by the average width of a character in that specific font, providing a more realistic approximation.

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