InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What do you understand by Java Message Service (JMS)? |
|
Answer» JMS is a Java-based API that is like a GATEWAY to the MESSAGE-oriented middleware like SONICMQ, IBM MQSeries etc. It provides a mechanism for sending and receiving messages by making use of the publishing/subscribe (1 message multiple receivers) model or point-to-point (1 message 1 receiver) paradigm from one client to another. The following image describes how 2 clients can communicate with each other utilizing JMS providers. Conclusion:J2EE DEFINES standards and specifications for various COMPONENTS such as e-mailing, database connectivity, security, XML parsing, CORBA communication etc that help in developing complex, reliable, secure and distributed servlets and applications that follow the client-server model. It provides various API interfaces that act as standards between different vendor adapters and J2EE components. This ensures that the application components are not dependent on vendor codes. Due to this, J2EE has been very popular among Java developers in the field of software development. |
|
| 2. |
How does a servlet application work? |
|
Answer» A Java servlet is typically multithreaded. This MEANS that multiple requests can be sent to the same servlet and they can be executed at the same TIME. All the local variables (not pointing to shared resources) INSIDE the servlet are automatically thread-safe and are request specific. Care has to be taken when the servlet is accessing or modifying the global shared variable. The servlet instance lifecycle for different requests are managed by the web container as follows:
|
|
| 3. |
Can you describe the phases of the servlet lifecycle? |
|
Answer» The below IMAGE describes the different phases of the servlet lifecycle: There are five phases, are as follows:
|
|
| 4. |
What are deployment descriptors used for? |
|
Answer» Servlets are server-side components that aid in developing powerful server-side APPLICATIONS. Ther are SERVERS that are platform-independent and follow various protocols as per the application design. The most commonly used protocol is the HTTP protocol. In Java, we can create servlets by implementing the Servlet INTERFACE that has 3 LIFECYCLE methods - INIT, service and destroy - and we can use the below classes for implementing servlets:
|
|
| 5. |
What do you know about Hibernate? |
|
Answer» Hibernate is an Object Relational MAPPER framework in Java that provides a layer of abstraction for retrieving or modifying data in the database. It handles all the implementations internally and the developer need not worry about how the connections to the databases are made, how the data translation from Java application to Database and vice versa happens. Hibernate SUPPORTS POWERFUL object-oriented concepts LIKE inheritance, association, polymorphism, compositions, collections that help in making queries using the Java approach by using HQL (Hibernate QUERY Language). |
|
| 6. |
What are EAR, WAR, and JAR? |
|
Answer» EAR stands for Enterprise Archive file and it consists of WEB, EJB and client components all compressed and PACKED into a file called .ear file. EAR files allow us to deploy different modules onto the application server simultaneously. WAR stands for Web Archive file and consists of all web components packed and compressed in a .war file. This file ALLOWS testing and deploying web applications easily in a single request. JAR stands for Java Archive file. It consists of all libraries and class files that constitute APIs. These are packed and compressed in a file called the .jar file. These are used for deploying the entire application INCLUDING classes and resources in a single request. |
|
| 7. |
How is J2EE different from Spring? |
||||||||||||||
Answer»
|
|||||||||||||||
| 8. |
How can we take a heap dump of a Java process? |
|
Answer» There are multiple ways for taking heap dump of Java process. Tools like jCmd, jVisualVM, jmap are AVAILABLE for this purpose. For example, if we are using jmap, then heap dump can be TAKEN by running the below command: $ jmap -dump:live, file=/path/of/heap_dump.hprof PIDThis heap dump contains live objects that are STORED in heap_dump.hprof file. Process ID (PID) of the Java process is needed to get the dump that can be obtained by using ps or GREP commands. |
|
| 9. |
What is the purpose of heap dumps and how do you analyze a heap dump? |
|
Answer» Heap dumps consist of a snapshot of all live objects on Java heap memory that are used by running Java applications. Detailed INFORMATION for each object like type, class name, address, size and references to other objects can be obtained in the heap dump. Various tools help in analyzing heap dumps in Java. For instance, JDK itself provides jhat tool for analysing heap dump. Heap dumps are also used for analysing memory leaks which is a phenomenon that OCCURS when there are objects that are not used by the application anymore and the garbage collection is not able to free that memory as they are still shown as referenced objects. Following are the causes that result in memory leaks:
Due to this, the application keeps consuming more and more memory and eventually this leads to OutOfMemory Errors and can ultimately crash the application. We can MAKE use of the Eclipse Memory Analyzer or jvisualVM tool for analysing heap dump to identify memory leaks. |
|
| 10. |
How is a webserver different from an application server? |
||||||||||||||||
Answer»
|
|||||||||||||||||
| 11. |
How is 32-bit JVM different from 64-bit JVM? |
|
Answer» 64-bit JVM is used in 64-bit operating systems whereas 32-bit JVM is used for 32-bit operating systems. In 64-bit JVM, we can specify more heap size memory up to 100G when COMPARED to the 4G limit of 32-bit JVM. Java applications take more memory while running in 64-bit JVM when compared to running the same APPLICATION in 32-bit JVM. This is because of the increased size of the ORDINARY Object Pointer. However, this can be bypassed by making use of the -XXCompressedOOP option of the JVM for telling to use 32-bit pointers. Additionally, 64-bit JVM uses 12 bytes object header size and a maximum of 8 bytes of INTERNAL references whereas the 32-bit JVM uses 8 bytes headers and a maximum of 4 bytes of internal references. |
|
| 12. |
What happens if the database connected to the Java application via connection pool suddenly goes down? |
|
Answer» Since the JAVA application uses a connection POOL, it has active CONNECTIONS that would get disconnected if the database goes down. When the QUERIES are executed to RETRIEVE or modify data, then we will get a Socket exception. |
|
| 13. |
What do you understand by JRMP? |
|
Answer» JRMP stands for Java Remote Method Protocol which is used for Remote Method Invocation (RMI) for passing Java objects as arguments. It is an underlying protocol used by RMI for MARSHALLING objects as a stream during object SERIALIZATION for transferring objects from one JVM to other. |
|
| 14. |
What do you understand by Connectors? Can you describe the Connector Architecture? |
|
Answer» Connectors are used for PROVIDING standard extension mechanisms to provide connectivity to DIFFERENT enterprise information systems. A connector ARCHITECTURE consists of RESOURCE adapters and system-level contracts, both of which are specific to enterprise information systems. The resource adapters are plugged into the container. The connector architecture defines certain contracts which a resource adapter must support for plugging into J2EE applications like security, transaction, resource MANAGEMENT etc. |
|
| 15. |
What are the design goals of J2EE architecture? |
|
Answer» The design goals of J2EE architecture are as follows:
|
|