Test Yourself on the Sun Java 2 Programmer Exam
As part of maintaining a database of exam questions, I offer a regularly updated collection of the most difficult Java programmer questions on my Web site at www.lanw.com/java/javacert/HardestTest.htm. This list draws on my own experiences, plus what visitors and readers tell me are some of the trickiest and most challenging aspects of the Java 2 Programmer exam. Share your comments and questions with me at firstname.lastname@example.org.
In a slight departure from the usual StudyGuide Q&A format, I also include a remark on each question that explains why I covered this topic, or what’s new and interesting about the subject matter it covers.
1. Which of the following class declarations for a normal top-level class represent incorrect use of modifier keywords?
A. public synchronized class WorkingClass extends Thread
B. protected class WorkingClass
C. public abstract class WorkingClass
D. class WorkingClass extends Thread
Remarks: The exam objectives include the ability to identify correctly constructed class declarations. (Note the trap for the unwary: The question asks for incorrect declarations, not correct ones. You may encounter questions written this way on the real exam.)
2. Select all of the following methods that are static (class) methods of the Thread class, excluding any methods deprecated in current versions of Java. Select 2 options. (Note that the current version of the test tells you how many options to select.)
E. sleep( long msec )
Remarks: Topics related to programming with Threads are a major part of the exam, so you should expect to see several questions related to correct use of Thread methods and/or synchronization of Threads.
3. The hierarchy of Exceptions related to array index errors looks like this:
Suppose you had a method myMethod that could throw both array index and string index exceptions. Assuming that myMethod does not have any try-catch blocks, which of the following statements are correct? Select two options.
A. The declaration for myMethod must include “throws ArrayIndexOutOf