Here is a list of the most commonly asked apache tomcat interview questions so that you can prepare for your next job interview. Keep one thing in mind that just by reading you won’t get the fundamentals so make sure you also know the functioning associated with Tomcat. An eligible candidate also knows the installation, virtual hosting functions, and security of the webserver. If you have practically worked over it then this will prove to be an add-on.
1. What is Tomcat?
Apache Tomcat is basically a Web Server and Servlet system which is an open-source (i.e. freely available on the internet) and is created by Apache Software Foundation. It is the server mostly used by Java Developers. The server is nothing but a computer program that provides service to other computers. So the final definition is Tomcat is a Java Servlet container and web server from the Jakarta project of the Apache software foundation.
- A web server responds with web pages to requests from client browsers.
- Web servers can provide dynamic content based on the requests sent by the user.
- Tomcat is very good at this because it provides both Java servlet and JavaServerPages (JSP) technologies.
- Tomcat can also be used as a web server for many applications even if free servlet and JSP engine are wanted.
- It can be used standalone or used behind traditional web servers such as Apache HTTPd, with the traditional server serving static pages and Tomcat serving dynamic servlet and JSP requests.
Related Post: Linux Interview Questions
2. Type of server?
There are basically two types of servers:
- Application Server
- Web Server
Apache Tomcat offers HTTP protocol, which means the user can connect with the server from anywhere by the URL provided and can access the Java application. This is very easy and simple to install and is compatible with any Operating System.
3. Why do we require Apache Tomcat?
It is required to run Java Web Applications on the host and server-based systems. It also helps to run JSP and Servlets.
4. Difference between apache and apache-tomcat server?
Apache Tomcat server: Apache Tomcat is a web container. It allows the users to run Servlet and JAVA Server Pages that are based on web applications. It can be used as an HTTP server. The performance of the Tomcat server is not as good as the designated web server. It can be used as a separate product with its own internal Web-server. It can also be used as mutually with the others Web-servers which include Apache, Microsoft Internet Information Server, and Microsoft Personal Web-server.
Apache Webserver: Apache web-server is designed to create the web-servers. It can host one or more HTTP based web-servers. It is used by various web hosting companies for mutual web-hosting. It is the oldest web server.
Difference between the Apache Tomcat server and Apache webserver:
Apache Tomcat Server | Apache Web Server |
---|---|
This server is a JSP/Servlet container. | This server is an HTTP server. It serves the files through the HTTP protocol. |
It can handle both static pages and dynamic pages. The static pages are generated using HTML. The dynamic pages are generated using Servlet and JSP. | It can handle static pages which are generated using HTML. It can handle dynamic content which is coded in PHP, Ruby, or other languages only through add-on modules offered by Apache or any other client. |
It can be used only for hosting JAVA-based code. | It can be used to host applications written in any programming language. |
It is not capable of requests/response processing. It is the container that can manage the entire lifecycle of the pages which are generated through the Servlet & JSP. | It is capable of request/ response & load balancing. |
It can be coded in pure JAVA. | It is only coded in the C programming language. |
Note:
The two technologies can be used together through a connector module called mod_jk. This will allow you to use the Apache HTTP server to serve regular static webpages, and the Tomcat Servlet engine to execute servlets.
5. What is the default port for Apache Tomcat?
The default port of Apache Tomcat is port 8080. After installing Tomcat on your system, click on http://localhost:8080 to validate if Tomcat is running.
6. What represents the root of Tomcat installation?
$CATALINA_HOME
7. How do you use services to start and stop Apache Tomcat?
The services are as follows:
- service tomcat start
- service tomcat stop
Or in centos 7+
- systemctl start tomcat
- systemctl stop tomcat
Or There are two .sh file in cd $CATALINA_HOME/bin dir or in /usr/share/tomcat7/bin/
- ./startup.sh
- ./shutdown.sh
8. Which is the vital configuration file that is used in Apache Tomcat?
The vital configuration file that is used in Apache Tomcat is server.xml.
9. What is the deployment process of a web application using the WAR file?
There is a Web apps directory in Tomcat under which all the web components JSP, Servlets, and HTML are placed. Hereby putting all the files into a single folder we can compress the files into a single unit which has.WAR extension.
Now, we can easily deploy the web application by putting the WAR file in the Web apps directory. And, when the server starts it extracts all the web components.
10. Explain what is Jasper?
- Jasper is a Tomcat’s JSP engine
- It parses JSP files to compile them into JAVA code as servlets
- At runtime, Jasper allows to automatically detect JSP file changes and recompile them
11. What is Catalina?
Catalina is Tomcat’s servlet container. Catalina makes Tomcat a Web Server for dynamic content.
12. What is Coyote?
Coyote is the component that makes Tomcat capable as an HTTP Web Server. Coyote makes Catalina also act as a server that serves static content.
13 Mention what is the output of select * from tab?
It displays the default tables in the database.
14. Explain how you can configure Tomcat to work with IIS and NTLM?
You have to follow the standard instructions for when the isapi_redirector.dll. Configure IIS to use “integrated windows security”
Ensure that in the server.xml you have to disable tomcat authentication:
<Connector port = "8009" enableLooksup = "false" redirect port = "8443" protocol = "AJP/1.3" tomcatAuthentication = "false" />
15. Explain when you can use . and when you can use []?
If you are running a bean property, use the .operator, and if you are executing a map value or an array index, it is preferred to use the [] operator. Although you can use these operators interchangeably.
16. Mention what are the connectors used in Tomcat?
In Tomcat, two types of connectors are used
- HTTP Connectors: It has many attributes that can be changed to determine exactly how it works and access functions such as redirects and proxy forwarding
- AJP Connectors: It works in the same manner as HTTP connectors, but they practice the AJP protocol in place of HTTP. AJP connectors are commonly implemented in Tomcat through the plug-in technology mod_jk.
17. Mention what are Catalina’s Configuration files?
Catalina consists of configuration files are
- policy
- properties
- properties
- xml
- xml
- Tomcat-users.xml
- xml
18. Explain how running Tomcat as a windows service provides benefits?
Running Tomcat as a windows service provides benefits like
- Automatic startup: It is crucial for environment where you may want to remotely re-start a system after maintenance
- Server startup without active user login: Tomcat is run oftenly on blade servers that may not even have an active monitor attached to them. Windows services can be started without an active user
- Security: Tomcat under window service enables you to run it under a special system account, which is protected from the rest of the user accounts
19. Explain when to use SSL with Tomcat?
You would use Tomcat to handle connection, when you are running Tomcat as a stand-alone web server.
20. Does Apache Tomcat generate Log files? If yes name them?
Yes, Apache Tomcat generates Log files. Basically, there are two important Log Files that are generated by Apache Tomcat.
They are as follows:
- Access.log
- Error.log
Related Post: Networking (CCNA) Interview Questions
21. How do you justify the significance of Virtual Hosting?
The concept of virtual hosting plays an important role by allowing to host of several websites on a single object.
Virtual hosting can be IP-based and Name based.
- Name-Based Virtual Host: It refers to that multiple host running on each IP address.
- IP Based Virtual Host: It refers to that a different IP address exists for each website served.
Name-Based Virtual Host is widely used everywhere.
22. What Is Default Session Time Out In Tomcat?
The default session timeout is 30 minutes in tomcat and can change in $TOMCAT_HOME/conf/web.xml via modification below:
<session-config>
<session-timeout>30</session-timeout>
</session-config>
23. How Do I Can Change The Default Home Page Loaded By Tomcat?
We can easily override the home page via adding welcome-file-list in application $TOMCAT_HOME/webapps//WEB-INF /web.xml file or by editing in container $TOMCAT_HOME/conf/web.xml
In $TOMCAT_HOME/conf/web.xml, it may look like this:
index.html
index.htm
index.jsp
Request URI refers to a directory, the default servlet looks for a “welcome file” within that directory in the following order: index.html, index.htm, and index.jsp
24. How To We Can Change Tomcat Default Port?
8080 is the default HTTP port that Tomcat attempts to bind to at startup. To change this, we need to change the port in $ TOMCAT_HOME /conf/server.xml, so that we can search 8080 and after getting the below statement
We can change 8080 to another port like 8081, we need to restart tomcat to take effect. We required changes in URL as http://localhost:8081/.
25. Difference between the web server and application server?
S.NO | Web Server | Application Server |
---|---|---|
1. | Web server encompasses web container only. | While the application server encompasses the Web container as well as the EJB container. |
2. | Web server is useful or fitted for static content. | Whereas the application server is fitted for dynamic content. |
3. | Web server consumes or utilizes fewer resources. | While application servers utilize more resources. |
4. | Web servers arrange the run environment for web applications. | While application servers arrange the run environment for enterprises applications. |
5. | In web servers, multithreading is not supported. | While in the application server, multithreading is supported. |
6. | The web server’s capacity is lower than the application server’s. | While the application server’s capacity is higher than the webserver. |
7. | In webserver, HTML and HTTP protocols are used. | While in this, GUI, as well as HTTP and RPC/RMI protocols, are used. |
26. What is a Tomcat cluster?
In order to manage the large applications Tomcat cluster is used. It is used more efficiently for load balancing and for managing most of the traffic, Apache Tomcat cluster is utilized. For the Tomcat server, it can provide multiple instances based on its content.
27. what is the configuration file in the tomcat server?
Tomacat XML Configuration Files:
server.xml(TOMCAT-HOME/conf/server.xml)
web.xml (TOMCAT-HOME/conf/web.xml)
tomcat-users.xml (TOMCAT-HOME/conf/tomcat-users.xml)
28. What is the server server.xml configuration file mean?
The server.xml file is the main Tomcat configuration file which is responsible for specifying the entire setup and Tomcat configuration while startup.
29. What does the web.xml configuration file mean?
This file is derived from the servlet specification in Tomcat. It contains information that is used to deploy the components on web applications or servers.
30. What do you understand by the Tomcat-users.xml configuration file?
Under the Tomcat-users.XML configuration files, the entire Tomcat users are specified and defined. It is located in the conf folder in the server root of Tomcat.
31. Difference between Apache Tomcat and Nginx?
S.NO. | Apache | Nginx |
---|---|---|
1. | Apache is an open-source web server. | Nginx is a web server. It is also used as a reverse proxy server which revises the request from the client and sends the request to the proxy server. |
2. | It is mostly used for Unix, Linux, Windows, and Solaris platforms. | It is mostly used for Unix-like systems and does not completely support Windows. |
3. | It was developed by the Apache group and initially released on 25 March 1999. | It was developed by Nginx. inc and initially released on 4 October 2004. |
4. | Apache is written in C and XML. | Nginx is written in C language. |
5. | It is designed for web servers. | It is designed for proxy servers as well as web servers. |
6. | In heavy web traffic, it cannot support multiple requests. | It can support multiple client requests with limited hardware resources. |
7. | In Apache, modules are dynamically fixed which makes it more complex. | In Nginx, modules cannot be loaded dynamically as there is a core software in which they comply. |
8. | It follows a Multi-Threaded approach to processing client requests. | It follows an Event-Driven approach to processing client requests. |
9. | In Apache, there is dynamic content in the web server itself. | It does not support providing dynamic content. |
10. | Apache’s performance for static content is lower than that of Nginx. | Nginx’s performance of static content is two times faster than that of Apache as it can simultaneously run thousands of connections and it uses less memory comparatively. |
32. Explain how servlet life cycles?
The life-cycle of a typical servlet running on Tomcat
- Tom-cat receives a request from a client through one of its connectors
- For processing, this request Tomcat maps this request to appropriate
- Once the request has been directed to the appropriate servlet, Tomcat verifies that servlet class has been loaded. If it is not than Tomcat wraps the servlet into Java Bytecode, that is executable by the JVM and forms an instance of the servlet
- Tomcat initiates the servlet by calling its init The servlet contains code that is able to screen Tomcat configuration files and act accordingly, as well as declare any resources it might require
- Once the servlet has been started, Tomcat can call the servlet’s service method to proceed the request
- Tomcat and the servlet can co-ordinate or communicate through the use of listener classes during the servlet’s lifecycle, which tracks the servlet for a variety of state changes.
- To remove the servlet, Tomcat calls the servlets destroy method.