
















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















































































Question 1. Which JDBC driver type translates JDBC calls into database‑specific calls using the client‑side library of the database? A) Type‑ 1 B) Type‑ 2 C) Type‑ 3 D) Type‑ 4 Answer: A Explanation: Type‑1 drivers (JDBC‑ODBC bridge) convert JDBC calls into ODBC calls, relying on a client‑side library. Question 2. In a JDBC URL, which part specifies the subprotocol? A) jdbc:mysql://localhost:3306/db B) mysql C) localhost D) db Answer: B Explanation: The subprotocol follows “jdbc:” and identifies the driver (e.g., mysql, postgresql). Question 3. Which method of PreparedStatement should be used to execute an INSERT, UPDATE, or DELETE statement? A) executeQuery() B) executeUpdate() C) execute() D) executeBatch() Answer: B Explanation: executeUpdate() returns the number of affected rows for DML statements.
Question 4. What is the primary security advantage of using PreparedStatement over Statement? A) Faster execution B) Automatic connection pooling C) Prevention of SQL injection D) Ability to execute stored procedures Answer: C Explanation: Parameter placeholders prevent malicious input from being interpreted as SQL code. Question 5. Which ResultSet method moves the cursor to the first row of the result set? A) beforeFirst() B) first() C) next() D) absolute(1) Answer: B Explanation: first() positions the cursor on the first row; beforeFirst() places it before the first row. Question 6. Which interface provides metadata about the database itself (e.g., product name, version)? A) ResultSetMetaData B) DatabaseMetaData C) ConnectionMetaData D) DriverMetaData
Answer: B Explanation: Pooling reduces overhead by reusing existing connections. Question 10. Which method in Servlet is called only once when the servlet instance is created? A) service() B) init() C) doGet() D) destroy() Answer: B Explanation: init() is invoked by the container once after servlet construction. Question 11. Which servlet method handles both GET and POST requests if not overridden? A) doGet() B) doPost() C) service() D) init() Answer: C Explanation: service() dispatches requests to doGet(), doPost(), etc., based on HTTP method. Question 12. Which HTTP status code is most appropriate for a successful POST that creates a new resource? A) 200 OK B) 201 Created
C) 204 No Content D) 302 Found Answer: B Explanation: 201 indicates that a new resource has been created. Question 13. Which object provides a way to forward a request from one servlet to another resource on the server? A) HttpServletResponse B) RequestDispatcher C) ServletContext D) FilterChain Answer: B Explanation: RequestDispatcher.forward() forwards the request internally. Question 14. Which session tracking technique works even when the client disables cookies? A) HttpSession only B) URL rewriting C) Hidden form fields D) Both B and C Answer: D Explanation: URL rewriting and hidden fields embed the session ID in URLs or forms, bypassing cookies. Question 15. What is the scope of a servlet attribute stored via ServletContext.setAttribute()?
A) <%@ page import="java.util.*" %> B) <%@ include file="header.jsp" %> C) <%@ taglib uri="..." prefix="c" %> D) <%@ page language="java" %> Answer: A Explanation: The import attribute of the page directive imports classes. Question 19. Which JSP implicit object represents the servlet’s output writer? A) request B) response C) out D) session Answer: C Explanation: out is a JspWriter used to write response content. Question 20. What does the EL expression ${user.name} evaluate to? A) Calls the user.getName() method B) Prints the literal string “user.name” C) Returns the class name of the object user D) Throws a compilation error Answer: A Explanation: EL resolves property access via getter methods. Question 21. Which JSTL core tag is used to iterate over a collection? A) <c:if>
B) <c:choose> C) <c:forEach> D) <c:set> Answer: C Explanation: <c:forEach> loops over collections, arrays, or maps. Question 22. In the MVC pattern for a Java web app, which component typically contains the business logic? A) Model B) View C) Controller D) ServletContext Answer: A Explanation: The Model represents data and business rules, while Controllers orchestrate flow. Question 23. Which thread state indicates that a thread has completed execution? A) BLOCKED B) WAITING C) TERMINATED D) RUNNABLE Answer: C Explanation: TERMINATED means the run() method has finished. Question 24. Which of the following is a correct way to create a new thread by implementing Runnable?
Question 27. Which class in java.util.concurrent provides a thread pool that can dynamically grow and shrink? A) FixedThreadPool B) CachedThreadPool C) SingleThreadExecutor D) ScheduledThreadPoolExecutor Answer: B Explanation: Executors.newCachedThreadPool() creates a pool that creates new threads as needed and reuses idle ones. Question 28. Which interface must a task implement to be submitted to an ExecutorService and return a result? A) Runnable B) CallableCallable defines call() which can return a value and throw exceptions. Question 29. Which method of Future blocks until the computation completes and returns its result? A) getNow() B) cancel() C) get() D) isDone() Answer: C
Explanation: Future.get() waits for the task to finish and returns the result. Question 30. Which lock implementation allows a thread to attempt to acquire the lock without blocking? A) ReentrantLock.lock() B) ReentrantLock.tryLock() C) synchronized block D) Semaphore.acquire() Answer: B Explanation: tryLock() returns immediately with a boolean indicating success. Question 31. Which concurrent collection provides thread‑safe iteration without locking the entire structure? A) Collections.synchronizedList(new ArrayList<>()) B) Vector C) CopyOnWriteArrayList D) Hashtable Answer: C Explanation: CopyOnWriteArrayList creates a new copy on mutative operations, allowing safe iteration. Question 32. What does AtomicInteger.incrementAndGet() guarantee? A) The increment is performed under a synchronized block B) The operation is atomic and visible to all threads without explicit locks C) It returns the previous value before increment D) It can only be used inside a synchronized method
Answer: D Explanation: Both invoke the no‑arg constructor; newInstance() is deprecated in favor of the newer API. Question 36. Which annotation indicates that a method overrides a method in a superclass? A) @Deprecated B) @Override C) @SuppressWarnings D) @FunctionalInterface Answer: B Explanation: @Override signals intent to override and triggers a compile‑time check. Question 37. How do you declare a custom annotation that can be applied to methods and retained at runtime? A) @Target(ElementType.METHOD) @Retention(RetentionPolicy.SOURCE) public @interface MyAnno {} B) @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnno {} C) @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnno {} D) @Target(ElementType.FIELD) @Retention(RetentionPolicy.CLASS) public @interface MyAnno {} Answer: B Explanation: ElementType.METHOD restricts usage to methods, and RetentionPolicy.RUNTIME keeps the annotation available via reflection.
Question 38. Which of the following is a functional interface in java.util.function? A) ComparatorConsumer<T> has a single abstract method accept(T) and is annotated with @FunctionalInterface. Question 39. What is the correct syntax for a lambda expression that takes two integers and returns their sum? A) (int a, int b) - > a + b B) int (a, b) - > { return a + b; } C) (a, b) - > { return a + b; } D) () - > a + b Answer: A Explanation: Explicit parameter types are optional; this form is valid and concise. Question 40. Which stream operation is intermediate and does not trigger processing? A) forEach() B) collect() C) filter() D) reduce() Answer: C Explanation: filter() is lazy; it returns a new stream without executing until a terminal operation is invoked.
Question 44. Which class represents an optional value that may be absent? A) Nullablejava.util.Optional encapsulates a possibly‑null value. Question 45. Which java.time class represents a date without a time‑zone or time component? A) LocalDateTime B) ZonedDateTime C) LocalDate D) Instant Answer: C Explanation: LocalDate holds year, month, day only. Question 46. How do you obtain the current moment in UTC using the Java 8 Date‑Time API? A) LocalDateTime.now() B) ZonedDateTime.now(ZoneId.of("UTC")) C) Instant.now() D) Both B and C Answer: D
Explanation: Instant.now() is UTC‑based; ZonedDateTime.now(UTC) yields the same moment with a zone. Question 47. Which JPA annotation specifies the primary key of an entity? A) @Id B) @PrimaryKey C) @Key D) @GeneratedValue Answer: A Explanation: @Id marks the field/property as the entity’s identifier. Question 48. In JPA, which cascade type propagates the persist operation from a parent to its children? A) CascadeType.REMOVE B) CascadeType.MERGE C) CascadeType.PERSIST D) CascadeType.REFRESH Answer: C Explanation: CascadeType.PERSIST causes child entities to be persisted when the parent is persisted. Question 49. Which annotation defines a many‑to‑many relationship in JPA? A) @OneToMany B) @ManyToOne C) @ManyToMany D) @OneToOne
Explanation: Spring creates a single shared instance per container by default. Question 53. Which annotation marks a class as a Spring MVC controller that returns view names? A) @RestController B) @Controller C) @Service D) @Repository Answer: B Explanation: @Controller indicates a component that resolves view names; @RestController returns body content. Question 54. Which Spring Boot starter provides embedded Tomcat and auto‑configuration for web apps? A) spring-boot-starter-data-jpa B) spring-boot-starter-web C) spring-boot-starter-security D) spring-boot-starter-test Answer: B Explanation: spring-boot-starter-web brings in Spring MVC, Tomcat, and related auto‑config. Question 55. What does the @SpringBootApplication annotation combine? A) @Configuration, @EnableAutoConfiguration, @ComponentScan B) @Entity, @Repository, @Service C) @RestController, @RequestMapping, @EnableWebMvc D) @EnableCaching, @EnableTransactionManagement, @EnableScheduling
Answer: A Explanation: It aggregates three core Spring Boot annotations. Question 56. Which HTTP method should be used to partially update a resource? A) GET B) POST C) PUT D) PATCH Answer: D Explanation: PATCH expresses a partial modification. Question 57. In RESTful URI design, which pattern best represents a collection of orders? A) /order/{id} B) /orders C) /getOrders D) /orders/list Answer: B Explanation: Plural nouns without verbs (/orders) denote a collection. Question 58. Which Jackson annotation is used to ignore a field during serialization? A) @JsonIgnore B) @JsonTransient C) @JsonExclude D) @JsonHide Answer: A