Docsity

Software Development Skills Advanced Java Practice Exam, Exams of Technology

Toggle sidebar
bg1
Software Development Skills Advanced
Java Practice Exam
**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.
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
pf55
pf56
pf57
pf58

Partial preview of the text

Download Software Development Skills Advanced Java Practice Exam and more Exams Technology in PDF only on Docsity!

Java Practice Exam

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.

Java Practice Exam

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

Java Practice Exam

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

Java Practice Exam

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()?

Java Practice Exam

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>

Java Practice Exam

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?

Java Practice Exam

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) Callable C) Future D) Supplier Answer: B Explanation: Callable 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

Java Practice Exam

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

Java Practice Exam

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.

Java Practice Exam

Question 38. Which of the following is a functional interface in java.util.function? A) Comparator B) Consumer C) Iterable D) List Answer: B Explanation: Consumer<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.

Java Practice Exam

Question 44. Which class represents an optional value that may be absent? A) Nullable B) Maybe C) Optional D) Void Answer: C Explanation: java.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

Java Practice Exam

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

Java Practice Exam

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

Java Practice Exam

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