Top 20 Advanced Java Interview Questions - Naresh IT
1. What is the difference between ServletContext and ServletConfig?
Answer:
ServletConfig is specific to a single servlet and provides initialization parameters, while ServletContext is shared among all servlets in an application and provides application-wide information.
2. What is the purpose of the volatile keyword in Java?
Answer:
The volatile keyword ensures that the value of a variable is always read from main memory, preventing threads from caching the variable value, thereby ensuring visibility of changes across threads.
3. What is a JSP directive? Name its types.
Answer:
JSP directives provide global information about the JSP page. The types include page, include, and taglib.
4. Explain the Fork/Join framework in Java.
Answer:
The Fork/Join framework is designed for parallel execution of tasks by splitting them into subtasks. It uses the ForkJoinPool to manage worker threads that process these tasks concurrently.
5. What is a Session in Java EE?
Answer:
A Session is a mechanism to maintain state between client requests. The server creates a session object (HttpSession) to store information about the user across multiple requests.
6. How does ConcurrentHashMap differ from HashMap?
Answer:
HashMap is not thread-safe, while ConcurrentHashMap is designed for concurrent access and is thread-safe. ConcurrentHashMap uses finer-grained locking, allowing better performance in a multi-threaded environment.
7. What are Java Streams, and how are they different from collections?
Answer:
Java Streams allow functional-style operations on sequences of elements, supporting pipelining and lazy evaluation. Collections store data, while Streams process data.
8. Explain Spring AOP and its benefits.
Answer:
Spring AOP (Aspect-Oriented Programming) separates cross-cutting concerns (like logging or security) from the business logic. It enables clean and modular code by allowing the separate definition of concerns.
9. What is Hibernate and its benefits?
Answer:
Hibernate is an ORM framework that maps Java objects to database tables. It automates CRUD operations and supports caching, lazy loading, and HQL (Hibernate Query Language), reducing the need for SQL.
10. Describe the Servlet Filter mechanism.
markdown
Copy code
**Answer:**
- A `Servlet Filter` intercepts requests and responses, allowing preprocessing (e.g., authentication, logging) or post-processing (e.g., compression, response modification) of data.
11. What is the significance of the @Transactional annotation in Spring?
kotlin
Copy code
**Answer:**
- The `@Transactional` annotation manages transaction boundaries declaratively in Spring, ensuring data integrity and consistency across multiple database operations.
12. Explain the difference between Callable and Runnable.
ruby
Copy code
**Answer:**
- `Runnable` runs on a separate thread but does not return a result, while `Callable` returns a result and can throw checked exceptions.
13. What is Servlet Chaining?
vbnet
Copy code
**Answer:**
- Servlet Chaining involves passing a request from one servlet to another before sending a response to the client, often used to implement filters or pre-processors.
14. What is Java Reflection and its use case?
kotlin
Copy code
**Answer:**
- Java Reflection allows runtime inspection and manipulation of classes, methods, and fields. It is used in frameworks for dynamic class loading and method invocation.
15. How does Garbage Collection work in Java?
sql
Copy code
**Answer:**
- Garbage Collection in Java automatically reclaims memory by identifying and removing objects that are no longer reachable from any live thread or static references, preventing memory leaks.
16. Explain the Decorator design pattern in Java.
vbnet
Copy code
**Answer:**
- The `Decorator` pattern allows behavior to be added to individual objects, either statically or dynamically, without affecting the behavior of other objects from the same class.
17. What are JDBC batch updates, and why are they used?
markdown
Copy code
**Answer:**
- `JDBC` batch updates allow executing multiple SQL statements as a batch in a single database call, reducing network overhead and improving performance.
18. Explain Java NIO and its advantages over IO.
markdown
Copy code
**Answer:**
- `Java NIO` (New I/O) offers non-blocking IO operations, selectors, and buffers, enabling scalable and high-performance IO operations suitable for server-side applications.
19. What is REST and how does it differ from SOAP?
swift
Copy code
**Answer:**
- `REST` is an architectural style that uses HTTP methods for CRUD operations and is stateless, lightweight, and typically uses JSON/XML. `SOAP` is a protocol with strict standards and supports more complex operations.
20. Describe the Factory design pattern in Java.
typescript
Copy code
**Answer:**
- The `Factory` pattern defines an interface for creating an object but lets subc
More Details :
Visit: https://nareshit.com/courses/advanced-java-online-training
Phone: 040-23746666
Email: support@nareshit.com
Call/Whatsapp: +91 8179191999
International: +1 404-232-9879, +1 248-522-6925
Head Office : 2nd Floor, Durga Bhavani Plaza, Ameerpet, Hyderabad, 500016.
Comments
Post a Comment