Top 33 Java J2ee Technical Support Engineer Interview Questions You Must Prepare 14.Jun.2024

First, you need to find the PID of your process, which you can find by using the "ps" command as shown in the previous question. Once you find the PID you can use the "top" command to find the CPU and memory usage. Alternatively, you can also use the prstat command as shown here.

Another simple but frequently asked question on Java support interviews. The main difference between the GET and POST is that GET is both idempotent and safe but POST is not. You can fire GET request multiple time and it will give the same result but multiple POST submission should always be avoided. GET is also used to read data from server and POST is used to send data to the server.

This is another interesting Java JEE support Interview Question. Even though both Servlet and JSP is used to create dynamic HTML the key difference between them is their purpose. Servlet is meant for Java developers and you write more Java than HTML and that's why it serves as Controller in many popular MVC framework e.g. DispatcherServlet in Spring MVC.

On the other hand, JSP is designed for HTML developers and it's more HTML than Java and that's why it is used as "view" in MVC frameworks like Spring and Struts. See the link in the wer for more detailed comparison.

The garbage collector is a component of Java virtual machine which is responsible for reclaiming memory from dead objects. It's one of the key components and allows an application developer to focus on application development rather than doing memory management. Some of the popular garbage collectors are a Concurrent Mark-Sweep garbage collector and G1 garbage collector in recent times.

The JVM stands for Java Virtual machine while JIT stands for Just in time Compiler. The JIT is part of JVM and used to convert the Java bytecode into native machine code which runs faster. There is some threshold set if a code runs more than the threshold it becomes the candidate of just in time compilation by JIT.

hint: Since your Java application is using a connection pool, it has active connections to database which will get disconnected once DB goes down. If you try to execute a query, you will receive Socket errors.

There are many differences between JDBC and Hibernate but the most important one is that JDBC provides an API to connect to the database and execute the query but Hibernate is an ORM (Object Relational modeling) framework, which me it allows you to work with objects while it takes care of saving and retrieving object from database.

In short, in JDBC you need to write SQL queries to get and store data from database but in Hibernate you just deal with objects, Hibernate takes care of issuing SQL queries to the database.

The main differences between 32-bit and 64-bit JVM are that later is designed for 64-bit operating system e.g. Windows 8 or later versions of Linux. From Java developer's perspective, the main difference between them comes from heap size. A 64-bit JVM virtually has unlimited heap memory as compared to 4GB of the theoretical limit of 32-bit JVM. If your program needs more memory, better run it on 64-bit JVM with large heap space. See here to learn more about 32-bit and 64-bit JVM.

The JRE stands for Java Runtime Environment and JVM stands for Java Virtual Machine. You install JRE to run Java application e.g. Applet or Core Java application or Web server like Tomcat. The JVM is part of JRE. See here to learn more differences between JVM and JRE.

You can run the java -version command in the command prompt to find out the version of Java used by your application. If you have multiple JDK or JRE installed then make sure you use the one which is used by your application.

These are parameters to specify heap size in Java. The -Xms defines the size of the heap when JVM starts up and -Xmx is used to specify the maximum heap size for Java application i.e. your heap cannot grow beyond that and JVM will die by throwing OutOfMemoryError if your heap doesn't have enough space to create new objects. See here to learn more about heap memory in Java.

As it name suggests, it just a pool of database connections. Since creating a new database connection in real-time is an expensive process and can potentially slow down the response time, many application maintains a pool of active database connection. When a request comes in they retrieve a connection from the pool, get the data from the database and then return the connection back to pool so that it can be reused. This way, response time is improved in most of the Java web application. See here to setup a database connection pool in Tomcat using Spring framework.

Taking thread dump is easier than taking heap dump because you don't need to remember tool. In Linux, you can just use the kill command to take the thread dump e.g.

$ kill -3 PID 

will print the thread dump in the log file or where System.out is redirected. Similarly, in Windows, you can use Ctrl + Break from the command prompt. Alternatively, you can also use jConsole and VisualVM to take the thread dump of Java application in both Windows and Linux. You can also read Java Performance The Definitive Guide By Scott Oaks to learn more about thread dump and heap dump.

When you install Tomcat in Linux by unzipping the downloaded package, you can see that there is a startup.sh and shutdown.sh file in the tomcat/bin directory. These scripts are used to start and stop Tomcat in Linux. These scripts internally call Catalina.sh, the main script to start Tomcat engine.

Both are key environment variable used by Java platform, but the key difference between them is that PATH points to the JDK binaries or native libraries e.g. java.exe, while CLASSPATH points to Java binaries e.g. JAR files, which contains bytecode. PATH is also system level concept independent of Java but CLASSPATH is purely Java concept and used by JVM to load classes required by Java application you are running.

This is again a popular and frequently asked question on Java JEE Interviews. Even though both are popular web MVC framework for Java applications, the key difference is that Spring brings dependency injection first and Struts brings it later using Struts 2.0.

Spring is also a suite of libraries e.g. you get Spring Security to implement security in your application, then there is Spring Boot, Spring Data, Spring Cloud and many more useful libraries under Spring umbrella.

There are many tools to analyze heap dump in Java e.g. you can use the jhat tool which comes along with JDK. You can also use Eclipse Memory Analyzer to analyze heap dump to find out any memory leak in Java while dealing with OutOfMemoryError in Java. See Java Performance The Definitive Guide By Scott Oaks to learn more about analyzing Java Heap dump.

The main difference between Web and Application Server comes from the fact that you cannot run EJB on the Web server like Tomcat or Jetty. The application server like WebLogic and WebSphere provides the runtime environment for EJB and other advanced services required by Java EE or J2EE specification.

The Java virtual machine throws java.lang.OutOfMemoryError when there is not enough memory to run the application e.g. no more memory to create new objects, no more memory to create new threads etc. The most common OutOfMemoryError is the java.lang.OutOfMemoryError: java heap space, which comes when there is no more memory left to create a new object.

The deadlock is a condition which can occur between two or multiple threads. In this case, each of the thread waits for each other and cannot progress. In Java, this usually happens when thread 1 holds the lock required by thread 2 and thread 2 holds the lock required by thread @If your Java program is hung then it could be a deadlock. You can take a thread dump and find out if any thread is waiting for the lock hold by other and vice-versa. You can also use jConsole tool to find deadlock.

Yes, you can use Apache and Tomcat together. There are many Java web application which is fronted by Apache web server to deliver static resources e.g. HTML files, images, configuration files etc. You can then configure Apache to forward the request to Tomcat.

This is one of the common and easy questions. Of course, you know the difference between HTTP and HTTPS right? well, HTTP is insecure but HTTPS is secure, the extra "s" is for security, which me it not only encode and encrypt the message before sending but also verify the identity of the server by using  SSL certificates provided by global certificate authorities e.g. GoDaddy, Thawte, VeriSign, Digicert, GeoTrust, and Comodo.  See here to learn more how SSL and Certifications work in Java web application.

The Apache server runs as httpd daemon in Linux and you can either use kill command after finding the PID of httpd process as shown here or you can use the apachectl script as shown below to start and stop Apache web server in Linux

Starting Apache web server in Linux

$ apachectl start

Stopping Apache web server in Linux

$ apachectl stop

Restarting Apache web server in Linux

$ apachectl restart

or:

/sbin/service httpd restart

You might need root access to do if Apache web server is not running on your application account.

Though both httpd and Tomcat are products of Apache software foundation, the httpd is more popular and used across the web and not just in Java world. The httpd is a web server which can serve static HTML files and dynamic content using PHP, Perl or Python, while Tomcat is a Servlet container which provides the runtime environment for Servlet and JSP. You can also use both Apache httpd and Tomcat together in Java world.

These are just two different memory areas used to store different kinds of variables. The stack is local to every thread while heap memory is shared among all threads. Since Stack is closer to thread and usually implemented using CPU registers they are faster than heap memory. The stack is used to store local variables as well method call frames while heap is used to store objects and class metadata. See the detailed wer for more points.

There are many ways to take the heap dump of a Java process e.g. Tomcat, but most common is by using tools available in JDK e.g. jVisualVM, jCmd, and jmap. Here is the command you can use to take the heap dump of Java process:

$ jmap -dump:live, file=/location/of/heap_dump.hprof  PID

The heap dump will contain all live objects and they are stored in heap_dump.hprof file. Remember, you also need PID of Java process which you can find by using "ps" and "grep" command as discussed in the first question. You can see Java Performance Companion by Charlie Hunt to learn more about taking and analyzing heap dump in Java to find memory leak and other memory related errors.

The race condition is another multithreading and concurrency bug which happens due to racing between two threads, for example, if one thread is updating a variable and second thread tries to read the value before it finished. You can avoid race conditions by properly synchronizing your code.

As I said in the previous wer, the JDBC stands for Java Database Connectivity and provides APIs and guidelines to connect a database from Java, while JNDI stands for Java Naming and Directory Interface and provides a logical structure for retrieving resources e.g. database, messaging queues, enterprise Java be without knowing their physical place e.g. host or port. You can register a resource with JNDI and then rest of your application component can access them using JNDI name. The database connection pool is the most common resource accessed via JNDI in web servers like Tomcat or WebLogic.

You can check by using "ps" command and "grep" command e.g. ps -ef | grep "myprocess". The keyword which you use with grep for search can be anything unique to your process, something which appears in its command line e.g. name of the class which implements the main method. You can also do "ps -ef | grep java" to list all Java process.

There are some commands available in Linux e.g. curl and wget which allows you to send HTTP commands, which you can use to call and test your web services from Linux. Particular, Curl is used extensively to test RESTful Web Services because it can send POST request, GET request, request with headers and also authenticate using both basic and digest authentication.

If you are working with REST API, I suggest learning curl, it's very convenient to check if your API is working properly using curl from the command line. You can even write a script to automate those stuff.