-
Time allowed: 2 hours
-
The test consists of multiple-choice questions, short answer questions, and coding exercises.
-
Coding exercises should be implemented in Java. Write clean and optimized code.
-
Use appropriate comments to explain your code where necessary.
-
What is the difference between
StringBuilderandStringBufferin Java? (2 points)-
StringBuilderis thread-safe, andStringBufferis not. -
StringBufferis thread-safe, andStringBuilderis not. -
Both are immutable.
-
Both are thread-safe.
-
-
What does the
volatilekeyword do in Java? (2 points)-
Prevents a variable from being overridden.
-
Ensures a variable's value is visible to all threads.
-
Synchronizes a block of code.
-
Declares a variable as constant.
-
-
What will the following code print? (2 points)
int x = 10; int y = ++x; System.out.println(x + " " + y);
-
10 11
-
11 10
-
11 11
-
10 10
-
-
Which collection allows null keys and values in Java? (2 points)
-
Hashtable -
HashMap -
TreeMap -
LinkedHashMap
-
-
Which of the following is not a feature of Java 8? (2 points)
-
Lambda Expressions
-
Streams
-
Modules
-
Functional Interfaces
-
-
Explain the purpose of the
@RestControllerannotation in Spring Boot. (5 points) -
What is the use of the
ResponseEntityclass in Spring? (5 points)
Problem:
-
Create a REST API endpoint to manage a list of books. Implement the following:
-
GET /books: Retrieve all books.
-
POST /books: Add a new book. Each book should have a unique ID, title, author, and price.
-
DELETE /books/{id}: Delete a book by ID.
-
-
Write the Java code using Spring Boot.
Write an SQL query to fetch the titles of books that have a price
greater than $20 from a table named books.
Problem:
- Connect to a MySQL database in Java using JDBC and retrieve all rows
from the
bookstable. Display the results in the console.
Problem: The following code throws a NullPointerException. Fix the
issue.
public class NullPointerExample {
public static void main(String[] args) {
String str = null;
System.out.println(str.length());
}
}Problem: Write a Java program to find the first non-repeating character in a string.
-
Core Java: 20 points
-
API Development: 30 points
-
Database Integration: 20 points
-
Debugging and Problem Solving: 30 points
Total: 100 points