
















































































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
A deep technical exam testing advanced Java programming concepts such as multithreading, exception handling, JDBC, servlets, JSP, Spring Framework, Hibernate ORM, design patterns, JVM tuning, and data structures. Includes complex coding scenarios and architectural problem cases.
Typology: Exams
1 / 88
This page cannot be seen from the preview
Don't miss anything!

















































































Question 1. Which JDBC driver type communicates directly with the database using the vendor’s native protocol? A) Type‑1 (JDBC‑ODBC Bridge) B) Type‑2 (Native‑API) C) Type‑3 (Network Protocol) D) Type‑4 (Thin Driver) Answer: D Explanation: Type‑4 drivers are pure Java drivers that implement the database’s native protocol, eliminating the need for native libraries. Question 2. In the JDBC workflow, which method of DriverManager obtains a Connection object? A) getDriver(String url) B) getConnection(String url, String user, String password) C) connect(String url, Properties info) D) openConnection(String url) Answer: B Explanation: DriverManager.getConnection creates a connection using the supplied URL and credentials. Question 3. Which Statement method should be used when executing a DML statement that does not return a ResultSet? A) executeQuery() B) executeUpdate() C) execute() D) executeBatch() Answer: B
Explanation: executeUpdate returns the number of rows affected by INSERT, UPDATE, DELETE, or DDL statements. Question 4. What is the primary advantage of using PreparedStatement over Statement? A) It allows execution of multiple SQL commands in one call. B) It automatically caches query results. C) It prevents SQL‑Injection and enables pre‑compilation. D) It supports stored procedures only. Answer: C Explanation: PreparedStatement pre‑compiles SQL and safely sets parameters, eliminating injection risks. Question 5. Which JDBC method returns a boolean indicating whether the first result is a ResultSet? A) execute() B) executeQuery() C) executeUpdate() D) executeBatch() Answer: A Explanation: execute() can return either a ResultSet or an update count; it returns true if the first result is a ResultSet. Question 6. Which interface provides metadata about the columns of a ResultSet? A) DatabaseMetaData B) ResultSetMetaData C) Statement
C) Opening a new Connection for each request and closing it immediately. D) Sharing a Statement object across multiple connections. Answer: B Explanation: Connection pools keep a set of active connections ready for reuse, improving performance. Question 10. In a servlet, which method is called only once during the servlet’s lifecycle? A) doGet() B) doPost() C) service() D) init() Answer: D Explanation: init() is invoked by the container when the servlet is first loaded, before any request handling. Question 11. Which HTTP method should a servlet implement to safely retrieve data without side effects? A) GET B) POST C) PUT D) DELETE Answer: A Explanation: GET requests are intended for idempotent data retrieval and should not modify server state. Question 12. Which servlet method is responsible for handling all request types by default? A) doGet()
B) doPost() C) service() D) init() Answer: C Explanation: service() dispatches the request to the appropriate doXXX method based on the HTTP verb. Question 13. How can a servlet obtain an initialization parameter defined in <init-param> of web.xml? A) getServletContext().getInitParameter() B) getServletConfig().getInitParameter() C) request.getParameter() D) response.getWriter() Answer: B Explanation: ServletConfig holds servlet‑specific init parameters; getInitParameter retrieves them. Question 14. Which object provides a way to store data across multiple HTTP requests for a single user? A) ServletContext B) HttpSession C) ServletConfig D) Cookie Answer: B Explanation: HttpSession maintains state information for a user across multiple requests. Question 15. Which of the following is NOT a valid way to maintain session tracking?
Question 18. Which JSP implicit object represents the current request object? A) session B) request C) response D) out Answer: B Explanation: request is an implicit object of type HttpServletRequest available in every JSP. Question 19. Which JSP element allows you to embed Java code that produces output directly? A) Declaration <%! ... %> B) Expression <%= ... %> C) Scriptlet <% ... %> D) Directive <%@ ... %> Answer: B Explanation: An expression evaluates the Java code and inserts its result into the response. Question 20. Which tag library provides core JSTL tags such as <c:forEach> and <c:if>? A) fmt B) sql C) core D) x Answer: C Explanation: The JSTL core library (prefix c) contains iteration and conditional tags.
Question 21. In the MVC pattern for a Java web application, which component is responsible for handling user input and controlling flow? A) Model B) View C) Controller D) Service Answer: C Explanation: The controller processes requests, interacts with the model, and selects the view for rendering. Question 22. Which method must a class implement to be used as a Runnable? A) run() B) start() C) execute() D) call() Answer: A Explanation: The Runnable interface defines a single run() method that contains the thread’s code. Question 23. When a thread calls wait() on an object, what must be true before the call? A) The thread must own the object’s monitor (i.e., be inside a synchronized block). B) The thread must be a daemon thread. C) The thread must be in BLOCKED state. D) The thread must have called notifyAll() previously. Answer: A Explanation: wait() can only be invoked by a thread that holds the monitor lock on the object.
Explanation: shutdownNow attempts to cancel running tasks via interruption and returns tasks that never commenced. Question 27. Which concurrent collection allows lock‑free reads and writes without external synchronization? A) Vector B) Hashtable C) CopyOnWriteArrayList D) ConcurrentHashMap Answer: D Explanation: ConcurrentHashMap partitions its internal map to permit concurrent access without global locking. Question 28. Which class provides atomic increment and decrement operations without using synchronized blocks? A) AtomicInteger B) Integer C) LongAdder D) BigInteger Answer: A Explanation: AtomicInteger offers methods like incrementAndGet() that perform atomic updates. Question 29. Which lock implementation allows a thread to try acquiring the lock without blocking? A) ReentrantLock B) ReadWriteLock C) StampedLock
D) Lock interface only Answer: A Explanation: ReentrantLock provides tryLock() which attempts acquisition and returns immediately. Question 30. In Hibernate, which annotation maps a Java class to a database table? A) @Entity B) @Table C) @Column D) @Id Answer: A Explanation: @Entity marks the class as a persistent entity; @Table optionally specifies the table name. Question 31. Which Hibernate query language is case‑insensitive for keywords and uses entity names instead of table names? A) SQL B) JPQL C) HQL D) Criteria API Answer: C Explanation: HQL operates on entity objects and is case‑insensitive for its keywords. Question 32. Which annotation indicates the primary key field of an entity? A) @PrimaryKey B) @Id
B) request C) session D) singleton Answer: D Explanation: By default, Spring beans are singletons within the container. Question 36. Which Spring MVC annotation maps a method to handle HTTP GET requests? A) @PostMapping B) @RequestMapping(method = RequestMethod.GET) C) @GetMapping D) Both B and C Answer: D Explanation: @GetMapping is a shortcut for @RequestMapping(method = RequestMethod.GET). Question 37. In a Spring Boot application, which annotation enables auto‑configuration and component scanning? A) @EnableAutoConfiguration B) @SpringBootApplication C) @ComponentScan D) @Configuration Answer: B Explanation: @SpringBootApplication combines @EnableAutoConfiguration, @ComponentScan, and @Configuration. Question 38. Which of the following best describes a microservice architecture?
A) A single monolithic application deployed as one unit. B) Multiple loosely coupled services, each responsible for a specific business capability. C) A set of tightly integrated modules sharing the same database schema. D) An application that runs only on a single server. Answer: B Explanation: Microservices are independent services that communicate over lightweight protocols. Question 39. In Spring Cloud, which component provides client‑side load balancing for REST calls? A) Eureka B) Ribbon C) Feign D) Zuul Answer: B Explanation: Ribbon implements client‑side load balancing; Feign can be combined with Ribbon for declarative REST clients. Question 40. Which Java I/O class is used for reading characters efficiently from a file? A) FileInputStream B) BufferedReader C) DataInputStream D) ObjectInputStream Answer: B Explanation: BufferedReader buffers character input, providing efficient reading and convenient methods like readLine().
Question 44. Which collection interface guarantees insertion order and allows duplicate elements? A) Set B) List C) Map D) Queue Answer: B Explanation: List maintains the order of insertion and permits duplicates. Question 45. Which Map implementation provides O(log n) time for basic operations and sorts keys according to their natural ordering? A) HashMap B) LinkedHashMap C) TreeMap D) ConcurrentHashMap Answer: C Explanation: TreeMap is a Red‑Black tree implementation that orders keys naturally or via a comparator. Question 46. Which method of the Iterator interface removes the last element returned by next()? A) delete() B) remove() C) drop() D) clear() Answer: B Explanation: Iterator.remove() safely removes the element most recently returned by next().
Question 47. Which interface must a class implement to define a natural ordering for its instances? A) Comparator<T> B) Comparable<T> C) Orderable D) Sortable Answer: B Explanation: Implementing Comparable<T> requires overriding compareTo, defining natural order. Question 48. In generics, what does the wildcard ? extends Number represent? A) Any type that is a supertype of Number. B) Exactly the type Number. C) Any subtype of Number. D) Any type unrelated to Number. Answer: C Explanation: ? extends Number allows a reference to a Number or any subclass (e.g., Integer, Double). Question 49. Which functional interface is used by the Stream.filter method? A) Function<T,R> B) Predicate<T> C) Consumer<T> D) Supplier<T> Answer: B Explanation: Predicate<T> supplies a boolean-valued function used to test each element in filter.
Answer: C Explanation: orElseThrow() throws NoSuchElementException if no value is present. Question 53. Which statement about Java enum types is true? A) Enums cannot implement interfaces. B) Enum constants are implicitly public static final. C) Enums can be subclassed. D) Enums cannot have constructors. Answer: B Explanation: Each enum constant is a public static final instance of its enum type. Question 54. What is autoboxing in Java? A) Converting a primitive to its wrapper class automatically. B) Converting a wrapper class to a primitive automatically. C) Manually calling valueOf on a wrapper. D) Serializing an object to a byte stream. Answer: A Explanation: Autoboxing automatically wraps primitives (e.g., int → Integer) where an object is required. Question 55. Which API allows runtime inspection of classes, methods, and fields? A) java.io B) java.lang.reflect C) java.nio D) java.util.concurrent
Answer: B Explanation: The Reflection API (java.lang.reflect) provides classes like Class, Method, Field. Question 56. Which annotation can be applied to a method to indicate it should be executed after bean construction but before it is put into service? A) @PostConstruct B) @PreDestroy C) @Autowired D) @Bean Answer: A Explanation: @PostConstruct marks a method to be run after dependency injection is complete. Question 57. In the Java Module System, which descriptor file defines a module’s dependencies? A) module-info.java B) MANIFEST.MF C) pom.xml D) module.xml Answer: A Explanation: module-info.java contains requires statements that declare module dependencies. Question 58. Which JDBC driver type requires both a client‑side native library and a server‑side library? A) Type‑ 1 B) Type‑ 2 C) Type‑ 3