SUN CERTIFIED PROGRAMMER FOR THE JAVA 2 PLATFORM 1 2 Practice Exam, Exams of Technology

This practice exam is designed to help candidates prepare for the Sun Certified Programmer for the Java 2 Platform 1.2 exam. It covers topics such as core Java programming, object-oriented design principles, exception handling, multithreading, and Java APIs. The exam tests the candidate's ability to design, write, and debug Java applications for the Java 2 platform.

Typology: Exams

2025/2026

Available from 01/13/2026

shilpi-jain-1
shilpi-jain-1 šŸ‡®šŸ‡³

4.2

(5)

29K documents

1 / 84

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
SUN CERTIFIED PROGRAMMER FOR THE JAVA 2
PLATFORM 1 2 Practice Exam
Question 1. Which of the following is a valid Java identifier?
A) 2ndValue
B) value_2
C) value-2
D) value 2
Answer: B
Explanation: Identifiers can include letters, digits, underscores, and dollar signs, but cannot begin with a
digit or include spaces or hyphens.
Question 2. Which of the following is NOT a Java keyword?
A) transient
B) interface
C) implements
D) include
Answer: D
Explanation: "include" is not a Java keyword; the others are reserved Java keywords.
Question 3. What is the value of the following char literal: '\u0041'?
A) 'A'
B) 'B'
C) 41
D) '\u0041'
Answer: A
Explanation: '\u0041' is the Unicode escape for the character 'A'.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54

Partial preview of the text

Download SUN CERTIFIED PROGRAMMER FOR THE JAVA 2 PLATFORM 1 2 Practice Exam and more Exams Technology in PDF only on Docsity!

PLATFORM 1 2 Practice Exam

Question 1. Which of the following is a valid Java identifier? A) 2ndValue B) value_ C) value- 2 D) value 2 Answer: B Explanation: Identifiers can include letters, digits, underscores, and dollar signs, but cannot begin with a digit or include spaces or hyphens. Question 2. Which of the following is NOT a Java keyword? A) transient B) interface C) implements D) include Answer: D Explanation: "include" is not a Java keyword; the others are reserved Java keywords. Question 3. What is the value of the following char literal: '\u0041'? A) 'A' B) 'B' C) 41 D) '\u0041' Answer: A Explanation: '\u0041' is the Unicode escape for the character 'A'.

PLATFORM 1 2 Practice Exam

Question 4. What is the effect of the strictfp keyword in Java? A) Ensures consistent floating-point results across platforms B) Makes a method final C) Restricts access to a method D) Forces integer precision Answer: A Explanation: strictfp enforces strict IEEE 754 compliance for floating-point computations. Question 5. Which primitive data type has the largest range? A) int B) long C) float D) double Answer: D Explanation: double has the largest range among primitives, as it uses 64 bits for floating-point values. Question 6. What is the default value of an instance boolean variable? A) true B) false C) null D) 0 Answer: B Explanation: The default value for a boolean instance variable is false.

PLATFORM 1 2 Practice Exam

Question 10. Which access modifier prevents a class from being subclassed? A) abstract B) protected C) private D) final Answer: D Explanation: The final modifier prevents a class from being subclassed. Question 11. Which of these can be declared as abstract? A) Methods only B) Classes only C) Both classes and methods D) Variables Answer: C Explanation: Both classes and methods can be declared abstract. Question 12. What is true about variables declared in an interface? A) They are public, static, and final by default B) They are private by default C) They must be initialized in the constructor D) They are protected by default Answer: A Explanation: Interface variables are implicitly public, static, and final.

PLATFORM 1 2 Practice Exam

Question 13. What does the following code print? int i = 0; if (i == 0) { System.out.print("A"); } else { System.out.print("B"); } A) A B) B C) AB D) Compilation error Answer: A Explanation: Since i is 0, the condition is true and "A" is printed. Question 14. Which types are legal in a switch statement in Java 1.2? A) int, byte, short, char B) long C) float D) double Answer: A Explanation: Only int, byte, short, and char are legal in switch statements in Java 1.2. Question 15. What is the output of the following loop? int i = 0; while (i < 3) { System.out.print(i);

PLATFORM 1 2 Practice Exam

Explanation: Throwable is the superclass; Exception and Error extend Throwable; RuntimeException extends Exception. Question 18. Which is a checked exception? A) NullPointerException B) IOException C) ArithmeticException D) ArrayIndexOutOfBoundsException Answer: B Explanation: IOException is checked; must be caught or declared. Question 19. What will happen if a finally block is present after try-catch? A) It always executes B) Executes only if exception is thrown C) Executes only if no exception D) May not execute Answer: A Explanation: finally always executes after try-catch, regardless of exceptions. Question 20. Which method signature is valid for an overridden method? A) public void run() throws IOException B) private void run() throws Exception C) protected void run() throws IOException D) public void run() throws Throwable

PLATFORM 1 2 Practice Exam

Answer: C Explanation: Overridden methods cannot throw broader or new checked exceptions. Question 21. Which of the following enables assertions at runtime? A) - ea B) - da C) - enableassertions D) - assert Answer: A Explanation: - ea enables assertions at runtime. Question 22. What is an appropriate use of assertions? A) Checking method parameters from the public API B) Validating internal invariants C) Input validation D) Authentication Answer: B Explanation: Assertions should be used for validating internal invariants, not for public input. Question 23. What is true about an Is-A relationship? A) Achieved using inheritance B) Achieved using composition C) Achieved using interfaces only D) Not possible in Java

PLATFORM 1 2 Practice Exam

Answer: B Explanation: The actual object type determines which overridden method is called at runtime. Question 27. Which cast is necessary and safe? A) Superclass to subclass when object is actually subclass B) Subclass to superclass C) int to double D) double to int Answer: A Explanation: Downcasting is safe only if the object is truly an instance of the subclass. Question 28. What is constructor overloading? A) Multiple constructors with different parameter lists B) Constructors with same parameter list C) Multiple constructors with same name D) Constructors with different return types Answer: A Explanation: Constructor overloading refers to multiple constructors with different parameter lists. Question 29. When does the compiler provide a default constructor? A) When no constructor is defined by the programmer B) When at least one constructor is defined C) Always D) Never

PLATFORM 1 2 Practice Exam

Answer: A Explanation: The compiler provides a default constructor only if the class defines no constructors. Question 30. Which statement about super() in constructors is true? A) It must be the first statement in a constructor B) It can be called from anywhere in the constructor C) It is optional D) It is used to call subclass constructor Answer: A Explanation: super() must be the first statement in a constructor if used. Question 31. What is the order of execution when creating a new object? A) Static initializers, instance initializers, constructor B) Constructor, static initializers, instance initializers C) Instance initializers, static initializers, constructor D) Static initializers, constructor, instance initializers Answer: A Explanation: Static initializers run first, then instance initializers, then the constructor. Question 32. Which is a regular (member) inner class? A) A class declared within another class B) A class declared in a method C) A static class D) An anonymous class

PLATFORM 1 2 Practice Exam

Answer: C Explanation: Anonymous inner classes cannot have constructors. Question 36. What is true about String immutability? A) String objects cannot be changed after creation B) String objects can be changed after creation C) String is a mutable class D) String is an interface Answer: A Explanation: String objects are immutable; modifications create new objects. Question 37. Which method compares two strings for equality, ignoring case? A) equalsIgnoreCase() B) compareTo() C) equals() D) match() Answer: A Explanation: equalsIgnoreCase() compares two strings, ignoring case. Question 38. What does the substring method of String return? A) A new String B) The same String C) An int D) A char array

PLATFORM 1 2 Practice Exam

Answer: A Explanation: substring returns a new String object. Question 39. Which class is used for mutable sequences of characters in Java 1.2? A) StringBuffer B) String C) StringBuilder D) MutableString Answer: A Explanation: StringBuffer is used for mutable character sequences (StringBuilder introduced in Java 5). Question 40. Which collection interface allows duplicate elements? A) Set B) Map C) List D) Collection Answer: C Explanation: List allows duplicate elements. Question 41. Which implementation maintains insertion order? A) HashSet B) TreeSet C) ArrayList D) HashMap

PLATFORM 1 2 Practice Exam

Answer: B Explanation: Iterator is the primary interface for traversing collections. Question 45. Which interface provides the remove() method to delete elements while iterating? A) Iterator B) Collection C) Set D) Map Answer: A Explanation: Iterator provides remove() to delete elements during iteration. Question 46. Which collection does NOT guarantee any order? A) HashSet B) LinkedList C) TreeSet D) ArrayList Answer: A Explanation: HashSet does not guarantee any order of elements. Question 47. What is the primary purpose of wrapper classes? A) To wrap primitive values as objects B) To provide utility methods C) For inheritance D) To store strings

PLATFORM 1 2 Practice Exam

Answer: A Explanation: Wrapper classes wrap primitive types as objects. Question 48. How do you convert a String to an int using a wrapper class? A) Integer.parseInt("123") B) String.parseInt("123") C) parseInt("123") D) Integer.toInt("123") Answer: A Explanation: Integer.parseInt("123") converts a String to int. Question 49. What is true about wrapper class objects? A) They are immutable B) They are mutable C) They are interfaces D) They must be subclassed Answer: A Explanation: Wrapper class objects are immutable. Question 50. Which method starts a thread? A) start() B) run() C) execute() D) begin()

PLATFORM 1 2 Practice Exam

Answer: A Explanation: sleep() pauses the current thread for the specified number of milliseconds. Question 54. What is the purpose of the yield() method? A) Suggests the current thread to pause and let others run B) Terminates the thread C) Suspends the thread D) Restarts the thread Answer: A Explanation: yield() suggests to the thread scheduler to let other threads of equal priority run. Question 55. Which keyword is used for synchronization? A) synchronized B) concurrent C) lock D) threadsafe Answer: A Explanation: The synchronized modifier is used for synchronization in Java. Question 56. What is a race condition? A) When multiple threads access shared data and results depend on timing B) When a thread races to finish C) When threads have same priority D) When only one thread runs

PLATFORM 1 2 Practice Exam

Answer: A Explanation: A race condition occurs when multiple threads manipulate shared data concurrently. Question 57. What does entering a synchronized method ensure? A) The thread owns the object's monitor B) The method runs faster C) The method can be called by any thread D) The thread is paused Answer: A Explanation: Entering a synchronized method ensures the thread owns the object's monitor (lock). Question 58. Which method must be called from within a synchronized context? A) wait() B) notify() C) notifyAll() D) All of the above Answer: D Explanation: wait(), notify(), and notifyAll() must be called from a block synchronized on the object. Question 59. Which of the following is a byte stream class? A) FileInputStream B) FileReader C) BufferedWriter D) PrintWriter