1. What is J2EE?
J2EE stands for Java 2 Platform, Enterprise Edition. It’s a platform-independent, Java-centric environment for developing, building, and deploying web-based enterprise applications online.
2. What are the main components of J2EE?
- Client Tier Components: Applets, Java applications.
- Web Tier Components: Servlets, JSP.
- Business Tier Components: EJB.
- Enterprise Information System (EIS) Tier: Databases, legacy systems.
3. Differentiate between J2EE and J2SE.
- J2SE: Standard Edition for desktop applications.
- J2EE: Enterprise Edition for large-scale, distributed, and web-based applications.
4. What is a Servlet?
A servlet is a Java program that runs on a server, handling requests and responses in a web application.
5. Explain the lifecycle of a Servlet.
- Initialization:
init()
method. - Request Handling:
service()
method. - Destruction:
destroy()
method.
6. What is JSP?
JavaServer Pages (JSP) is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types.
7. How does JSP differ from Servlets?
- JSP: Easier to write, mainly for presentation.
- Servlets: More powerful, better for processing logic.
8. What is EJB?
Enterprise JavaBeans (EJB) is a server-side software component that encapsulates business logic of an application.
9. Types of EJBs?
- Session Beans: Handle business logic.
- Entity Beans: Represent persistent data.
- Message-Driven Beans: Handle asynchronous messages.
10. What is the role of JNDI in J2EE?
Java Naming and Directory Interface (JNDI) provides naming and directory functionality, allowing applications to look up resources like EJBs and DataSources.
11. What is JDBC?
Java Database Connectivity (JDBC) is an API for connecting and executing queries with databases.
12. Explain the JDBC architecture.
- Driver Manager: Manages database drivers.
- Driver: Connects to the database.
- Connection: Interface with the database.
- Statement: Executes SQL queries.
- ResultSet: Holds data retrieved from the database.
13. What is the difference between Statement and PreparedStatement?
- Statement: Executes static SQL queries.
- PreparedStatement: Executes precompiled SQL queries, allowing parameterization.
14. What is a DAO?
Data Access Object (DAO) is a design pattern that provides an abstract interface to some type of database or other persistence mechanism.
15. What is connection pooling?
A technique to maintain a cache of database connections for reuse, improving performance.
16. Explain MVC architecture.
Model-View-Controller (MVC) separates application logic into three interconnected components:
- Model: Business logic.
- View: User interface.
- Controller: Handles user input.
17. What is Struts?
An open-source framework for creating Java web applications using the MVC design pattern.
18. What is Hibernate?
An ORM (Object-Relational Mapping) tool for Java, facilitating the mapping of Java classes to database tables.
19. What are the benefits of using Hibernate?
- Simplifies database interactions.
- Eliminates boilerplate code.
- Provides caching mechanisms.
20. What is the difference between load() and get() in Hibernate?
- load(): Throws an exception if the object is not found.
- get(): Returns null if the object is not found.
21. What is a transaction in J2EE?
A sequence of operations performed as a single logical unit of work.
22. What is JTA?
Java Transaction API (JTA) allows applications to perform distributed transactions.
23. What is JMS?
Java Message Service (JMS) is an API for sending messages between two or more clients.
24. Types of messaging models in JMS?
- Point-to-Point: One sender, one receiver.
- Publish/Subscribe: One sender, multiple receivers.
25. What is a WAR file?
Web Application Archive (WAR) is a file used to distribute a collection of JAR files, JavaServer Pages, Java Servlets, and other resources.
26. What is an EAR file?
Enterprise Archive (EAR) is a file format used by Java EE for packaging one or more modules into a single archive.
27. What is the difference between WAR and EAR?
- WAR: For web applications.
- EAR: For enterprise applications, can contain multiple WAR and JAR files.
28. What is the role of web.xml?
The deployment descriptor for a web application, defining servlets, servlet mappings, and other configurations.
29. What is the use of annotations in J2EE?
Annotations provide metadata to the Java code, simplifying configuration and reducing the need for XML.
30. What is dependency injection?
A design pattern where an object receives other objects it depends on, promoting loose coupling.
31. What is the Singleton design pattern?
Ensures a class has only one instance and provides a global point of access to it.
32. What is the Factory design pattern?
Provides an interface for creating objects without specifying their concrete classes.
33. What is the DAO design pattern?
Separates the data persistence logic from the business logic.
34. What is the Front Controller design pattern?
A single handler for all requests, centralizing request processing.
35. What is the Service Locator pattern?
Provides a centralized registry for services, reducing the need for repetitive lookup code.
36. What is the difference between session and entity beans?
- Session Beans: Handle business logic.
- Entity Beans: Represent persistent data.
37. What is the difference between stateless and stateful session beans?
- Stateless: Do not maintain client state.
- Stateful: Maintain state across multiple method calls.
38. What is the role of interceptors in EJB?
Allow developers to define methods that intercept business method invocations or lifecycle events.
39. What is the difference between JSP include directive and include action?
- Include Directive: Static inclusion.
- Include Action: Dynamic inclusion at runtime.
40. What is the purpose of tag libraries in JSP?
Provide reusable components to encapsulate complex functionality.
41. What is the difference between forward and redirect?
- Forward: Server-side, URL remains the same.
- Redirect: Client-side, URL changes.
42. What is the role of filters in J2EE?
Intercept requests and responses to perform filtering tasks.
43. What is the difference between GET and POST methods?
- GET: Appends data to the URL.
- POST: Sends data in the request body.
44. What is the role of the session in web applications?
Maintains user state across multiple requests.
45. What is the difference between HttpSession and Cookie?
- HttpSession: Server-side storage.
- Cookie: Client-side storage.
46. What is the role of listeners in J2EE?
Monitor events in web applications, such as session creation or attribute changes.
47. What is the difference between ServletContext and ServletConfig?
- ServletContext: Application-wide parameters.
- ServletConfig: Servlet-specific parameters.
48. What is the role of the dispatcher servlet in Spring MVC?
Acts as the front controller, dispatching requests to appropriate handlers.
49. What is the difference between BeanFactory and ApplicationContext?
- BeanFactory: Basic container.
- ApplicationContext: Advanced container with more features.
50. What is the purpose of the @Autowired annotation in Spring?
Automatically injects dependencies into beans.
❓ Frequently Asked Questions (FAQs)
Q1: Is J2EE still relevant in 2025?
Yes, J2EE, now known as Jakarta EE, continues to be a foundational platform for building enterprise-level applications.
Q2: How should I prepare for a J2EE interview?
Focus on understanding core concepts, practice coding, and review common interview questions like those listed above.
Q3: Are certifications important for J2EE roles?
While not mandatory, certifications can validate your skills and enhance your resume.