




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This exam guide prepares candidates for Java programming fundamentals. Coverage includes syntax, object-oriented concepts, data types, control structures, exception handling, and basic application development.
Typology: Exams
1 / 106
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which component of the Java platform is responsible for converting bytecode into native machine instructions at runtime? A) JDK B) JRE C) JVM D) JAR Answer: C Explanation: The Java Virtual Machine (JVM) loads, verifies, and executes bytecode, translating it into native instructions for the host OS. Question 2. What does the “Write Once, Run Anywhere” (WORA) principle rely on? A) Source code portability B) Bytecode execution by the JVM C) Platform-specific compilers D) Native machine code distribution Answer: B Explanation: Java source is compiled to bytecode, which the JVM interprets on any platform, enabling WORA. Question 3. Which of the following is NOT a valid Java primitive type? A) byte B) short C) String D) double Answer: C Explanation: String is a reference type; all other options are primitives.
Question 4. In Java, what is the default value of an uninitialized instance variable of type boolean? A) true B) false C) null D) 0 Answer: B Explanation: Instance variables receive default values; for boolean the default is false. Question 5. Which access modifier allows a class member to be accessed only within its own package and by subclasses in other packages? A) private B) protected C) default (package-private) D) public Answer: B Explanation: protected provides package access plus subclass access across packages. Question 6. Which statement correctly creates an array of ten integers? A) int[] nums = new int[10]; B) int nums = new int[10]; C) int[10] nums = new int[]; D) int nums[10] = new int(); Answer: A
Answer: C Explanation: Static methods cannot access instance members without an object reference. Question 10. Which of these is a checked exception? A) ArrayIndexOutOfBoundsException B) NullPointerException C) IOException D) ArithmeticException Answer: C Explanation: IOException must be either caught or declared in the method signature; the others are unchecked. Question 11. Which statement correctly declares a method that may throw an SQLException? A) public void read() throws SQLException {} B) public void read() throw SQLException {} C) public void read() catches SQLException {} D) public void read() throws SQLException; Answer: A Explanation: The throws clause declares that the method can propagate the checked exception. Question 12. What is the output of the following code?
String s1 = "Java"; String s2 = new String("Java"); ## Associate Certification Exam Guide System.out.println(s1 == s2);A) true B) false C) Compilation error D) Runtime exception Answer: B Explanation: == compares references; s1 refers to the string pool object, s2 refers to a distinct object. Question 13. Which of the following best describes autoboxing? A) Converting a primitive to its wrapper class automatically. B) Converting a wrapper class to a primitive automatically. C) Manually invoking Integer.valueOf(). D) Casting between unrelated reference types. Answer: A Explanation: Autoboxing automatically wraps a primitive value into its corresponding wrapper class. Question 14. Which loop guarantees that its body is executed at least once? A) for B) while C) do-while D) Enhanced for Answer: C
D) sealed Answer: A Explanation: Declaring a class as final disallows inheritance. Question 18. Which method must be implemented by a class that implements the java.util.Comparator interface? A) compareTo(T o) B) compare(T o1, T o2) C) equals(Object obj) D) hashCode() Answer: B Explanation: Comparator defines int compare(T o1, T o2) for custom ordering. Question 19. Which of the following statements about StringBuilder is correct? A) It is immutable. B) It is thread-safe. C) It provides better performance for frequent modifications than String. D) It cannot be converted to a String. Answer: C Explanation: StringBuilder is mutable and not synchronized, making it faster for many appends. Question 20. Which of the following is the correct way to obtain the current date using the Java 8 Date/Time API? A) LocalDate.now(); B) new Date();
C) Calendar.getInstance(); D) Instant.now().toLocalDate(); Answer: A Explanation: LocalDate.now() returns the current date without time-zone information. Question 21. What will be printed by the following code?
int i = 0; while(i++ < 3) { System.out.print(i + " "); }A) 1 2 3 B) 2 3 4 C) 1 2 D) 0 1 2 Answer: B Explanation: Post-increment returns the old value for the test; after each iteration i has been incremented, so printed values are 2,3,4. Question 22. Which of the following is true about the finalize() method? A) It is guaranteed to run before an object is garbage-collected. B) It can be called directly to free resources. C) Its use is discouraged because it is unpredictable. D) It must be overridden in every class. Answer: C
Answer: B Explanation: ++a increments to 11, yields 11; a++ yields 11 then increments to 12; sum = 22. Question 26. Which of the following is a correct way to declare a generic ArrayList that holds only String objects? A) ArrayList list = new ArrayList(); B) ArrayList list = new ArrayList(); C) ArrayList list = new ArrayList(); D) ArrayList list = new ArrayList(); Answer: B Explanation: Both the reference and the instantiated type must specify ``. Question 27. Which of the following statements about the throws clause is correct? A) It can be used only with checked exceptions. B) It can appear in both method declarations and constructors. C) It must be accompanied by a finally block. D) It automatically logs the exception. Answer: B Explanation: Both methods and constructors may declare that they throw exceptions.
Question 28. Which of the following is NOT a valid way to create a thread in Java? A) Extending Thread and overriding run(). B) Implementing Runnable and passing it to a Thread constructor. C) Using a lambda expression that implements Runnable. D) Instantiating Thread with the start() method as a parameter. Answer: D Explanation: Thread.start() is a method call, not a constructor argument. Question 29. Which of the following statements about the transient keyword is true? A) It prevents a field from being serialized. B) It makes a field constant. C) It forces a field to be static. D) It enables lazy initialization. Answer: A Explanation: transient marks a field to be ignored by the default serialization mechanism. Question 30. What does the instanceof operator evaluate? A) Whether a reference is null. B) Whether an object is an instance of a specific class or interface. C) Whether two objects are equal. D) Whether a class implements Serializable. Answer: B Explanation: instanceof returns true if the left-hand operand is an instance of the right-hand type (or its subclass).
Explanation: An enum type is implicitly final; it cannot be subclassed. Question 34. What will be the output of the following code?
int[] a = {1,2,3}; for(int i : a) { System.out.print(i + " "); }A) 1 2 3 B) [1, 2, 3] C) 123 D) Compilation error Answer: A Explanation: The enhanced for-loop iterates over each element, printing them with a space. Question 35. Which of the following is a correct way to handle a NumberFormatException when parsing an integer from a string? A) int n = Integer.parseInt(str) throws NumberFormatException; B) try { Integer.parseInt(str); } catch (NumberFormatException e) {} C) if (str instanceof Number) { Integer.parseInt(str); } D) Integer.parseInt(str) catch (NumberFormatException e) {} Answer: B Explanation: The try-catch block catches the checked (actually unchecked) NumberFormatException.
Question 36. Which statement about the static initializer block is correct? A) It can be overloaded. B) It runs each time an object of the class is created. C) It runs once when the class is first loaded. D) It must return a value. Answer: C Explanation: A static initializer executes a single time when the class is loaded by the JVM. Question 37. Which of the following is a functional interface in java.util.function? A) Comparator B) Predicate C) Iterable D) Serializable Answer: B Explanation: Predicate has a single abstract method test(T t) and is a functional interface. Question 38. Which of the following statements about the final keyword when applied to a method is true? A) The method can be overridden in subclasses. B) The method must be static. C) The method cannot be overridden. D) The method cannot be called. Answer: C
B) It is immutable. C) It can be directly converted to a java.util.Date without a formatter. D) It provides methods like plusDays() and minusHours(). Answer: C Explanation: Converting to java.util.Date requires bridging via Instant and a ZoneId; there is no direct method. Question 42. Which of the following is the correct way to declare an abstract method named process that returns an int and takes no parameters? A) public abstract int process(); B) public int process() abstract; C) abstract int process {} D) public abstract int process {} Answer: A Explanation: Abstract methods are declared with the abstract keyword, a return type, name, and a terminating semicolon. Question 43. In Java, which of the following statements about String immutability is TRUE? A) Changing a character in a String modifies the original object. B) Concatenating strings creates a new String object. C) StringBuilder and String share the same memory model. D) String objects are stored only on the heap. Answer: B Explanation: Because String is immutable, any modification like concatenation results in a new object.
Question 44. Which of the following statements about the java.lang.Math class is correct? A) All its methods are instance methods. B) It cannot be subclassed because it is final. C) It provides the constant PI. D) It implements Serializable. Answer: C Explanation: Math.PI is a public static final double representing π. Question 45. Which of the following is the correct way to create a lambda expression that implements Predicate and tests if a number is even? A) Predicate isEven = (int n) -> n % 2 == 0; B) Predicate isEven = n -> n % 2 == 0; C) Predicate isEven = n -> { return n % 2; }; D) Predicate isEven = () -> n % 2 == 0; Answer: B Explanation: The parameter type can be inferred; the expression returns a boolean indicating evenness. Question 46. Which of the following statements about the java.util.Collections class is FALSE? A) It contains static methods for sorting collections. B) It can be instantiated to create a collection object. C) It provides unmodifiableList to create read-only views. D) It includes a binarySearch method for sorted lists. Answer: B
D) It requires implementing finalize(). Answer: A Explanation: Closeable declares void close() throws IOException; and is compatible with try-with-resources. Question 50. Which of the following statements about method overriding is FALSE? A) The overriding method must have the same signature as the method in the superclass. B) The overriding method can have a more restrictive access modifier. C) The overriding method can return a subtype (covariant return). D) The @Override annotation helps the compiler detect mismatches. Answer: B Explanation: An overriding method cannot reduce visibility; it may only maintain or broaden it. Question 51. Which of the following is the correct way to declare a constant named MAX_SIZE of type int? A) public static final int MAX_SIZE = 100; B) final int MAX_SIZE = 100; C) static int MAX_SIZE = 100; D) public const int MAX_SIZE = 100; Answer: A Explanation: Constants are static final; public is optional but common for globally visible constants. Question 52. Which of the following statements about the java.util.HashMap class is true?
A) It maintains insertion order. B) It allows duplicate keys. C) It permits one null key and multiple null values. D) It is synchronized by default. Answer: C Explanation: HashMap allows a single null key and any number of null values; it is unsynchronized and does not guarantee order. Question 53. Which of the following statements about the break statement is correct? A) It can be used only inside for loops. B) It terminates the nearest enclosing loop or switch. C) It can be labeled to exit multiple nested loops. D) Both B and C are correct. Answer: D Explanation: break exits the innermost loop or switch; a labeled break can exit an outer block. Question 54. Which of the following statements about Java’s byte type is FALSE? A) It is an 8-bit signed integer. B) It can store values from -128 to 127. C) Arithmetic operations on byte are performed using 32-bit int. D) It can be directly assigned to a char without casting. Answer: D Explanation: byte to char conversion requires an explicit cast because char is unsigned 16-bit.