Excerpt for Tomcat Interview Questions You'll Most Likely Be Asked by Vibrant Publishers, available in its entirety at Smashwords

Tomcat

Interview Questions


You'll Most Likely Be Asked


Job Interview Questions Series


www.vibrantpublishers.com


*****



Tomcat Interview Questions You'll Most Likely Be Asked

Published by Vibrant Publishers at Smashwords

Copyright 2012 Vibrant Publishers, USA.

Smashwords Edition, License Notes

This ebook is licensed for your personal use only. This ebook may not be re-sold or given away to other people. If you would like to share this book with another person, please purchase an additional copy for each recipient. If you’re reading this book and did not purchase it, or it was not purchased for your use only, then please return to Smashwords.com and purchase your own copy. Thank you for respecting the hard work of this author.


This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The Author or the Publisher will not be liable for any damages caused or alleged to be caused either directly or indirectly by this book.


Vibrant Publishers books are available at special quantity discount for sales promotions, or for use in corporate training programs. For more information please write to bulkorders@vibrantpublishers.com


Please email feedback / corrections (technical, grammatical or spelling) to spellerrors@vibrantpublishers.com


To access the complete catalogue of Vibrant Publishers, visit www.vibrantpublishers.com


*****



Table of Contents


1. General Questions

2. Classes Not Found Problem

3. Character Encoding

4. Clustering

5. Connectors

6. Deployment

7. FDA_Validation

8. Developing

9. Security

10 Tomcat on Windows

11. Memory Issues

12. Tomcat on Linux_Unix and Performance

13. Logging

14. Using PHP

15. Versions

16. Background

17. Technical

18. Apache httpd

19. Error Log Messages and Problems Starting Apache

20. Directory Structure

21. Components

22. Ports and Proxy

23. Balancer

24. Configuration

25. Features

26. URL Rewriting

27. Authentication and Access Restrictions

28. Dynamic Content

29. Common Issues

30. Architecture

HR Questions

INDEX



*****



Tomcat Interview Questions


Review these typical interview questions and think about how you would answer them. Read the answers listed; you will find best possible answers along with strategies and suggestions.


*****



General Questions


1: Is it true that Apache web server is just another name for Apache Tomcat?

Answer:

No. Apache web server is a C implementation of an HTTP web server where as Apache Tomcat is HTTP web server environment for Java code to run.


2: Which Sun Microsystems specifications are implemented by Apache Tomcat?

Answer:

Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems.


3: Does Tomcat have built-in support for Web Services?

Answer:

No.


4: What are the most common components of Apache Tomcat?

Answer:

Normally there are three different components available in Apache Tomcat namely: servlet container, an HTTP container and a JSP engine.


5: Can one set Java system properties differently for each webapp?

Answer:

There is no way to add such a property in web.xml or in the webapp's context.


6: You have an application that uses EJBeans. Is Tomcat the right choice to deploy that application?

Answer:

Since Tomcat is not an EJB container, EJBeans applications should not be deployed on Tomcat.


7: How one can share sessions across web apps?

Answer:

Due to violation of the Servlet Specifications, one cannot share sessions directly across web apps. There are other ways to do that; for example: using a singleton class loaded from the common classloader repository to hold shared information and putting some of this shared information in a database or another data store.


8. How to make Tomcat startup faster?

Answer:

There are several things that can be done in this regard. To list a few:

a) Remove extra Jar files,

b) Use the profiler in order to get rid of slow code,

c) Reduce parsing


9: Is there a way to run Tomcat without root privileges?

Answer:

We can use the jsvc, available as part of the commons-daemon project.


10: How can you debug a Tomcat application?

Answer:

We need an IDE and two environmental variables to debug. Variables are:

C:\>set JPDA_ADDRESS=1044

C:\>set JPDA_TRANSPORT=dt_socket


11: How to improve Tomcat performance in terms of memory settings?

Answer:

If the web application is using large memory but the memory setting has 64MB by default, this causes application to become slower because the garbage collector is invoked more often, and it can even run out of memory (outofmemory / heap space error ). One way to address this problem is to set a larger heap size.


*****



Classes Not Found Problem


12: What is the reason of jsp:useBean not working?

Answer:

Following can be the cause of jsp:useBean not working:

a) If the class name has been fully qualified (eg: com.bar.package.MyClass)

b) You have imported your class into your jsp (eg: <%@ page import="com.bar.package.MyClass"%>)

c) If the bean is packaged in a class


13: What is the reason of getting java.lang.NoClassDefFoundError: javax/servlet/Filter?

Answer:

If servlet.jar is floating around somewhere, then it could be the cause of the error.


14: You get java.lang.NoClassDefFoundError: org/xml/sax/InputSource exception. What could be the cause of it?

Answer:

Conflicting XML api jar files in the classpath can be the cause.


*****



Character Encoding


15: Write a character encoding test page that helps you verify Tomcat character encoding configuration.

Answer:

<%@ page contentType="text/html; charset=UTF-8" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Character encoding test page</title>

</head>

<body>

<p>Data posted to this form was:

<%

request.setCharacterEncoding("UTF-8");

out.print(request.getParameter("mydata"));

%>


</p>

<form method="POST" action="index.jsp">

<input type="text" name="mydata">

<input type="submit" value="Submit" />

<input type="reset" value="Reset" />

</form>

</body>

</html>


16: Where can you find character encoding filters in Tomcat application server?

Answer:

webapps/servlets-examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java

webapps/jsp-examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java


17: How to send higher characters in HTTP headers?

Answer:

Using url-encoding (% + high byte number + low byte number) would be a good idea.


*****



Clustering


18: Is it possible to configure a cluster at the Engine level? If yes, from which version onward?

Answer:

Yes. From Tomcat 5.5.10 onwards, you can configure clusters at both the Engine and Host levels.


19: How to turn on transport logging?

Answer:

To enable transport logging, we can use "org.apache.catalina.cluster" as logger category and switch it to info, debug or trace as log level. We need to configure the clusterLog attribute (logging category) to send and receive message log.


20: If without network my cluster doesn't work on Windows laptop, what can be done?

Answer:

The Membership attribute mcastBindAddress="127.0.0.1" should be set.


21: Can you pause message sending?

Answer:

Yes. Message sending can be paused but it should be made sure that the membership pig is active. Use fastasyncqueue mode to limit max queue size.


22: Can you add more senders when in pooled mode?

Answer:

Yes. We can configure the attribute maxPoolSocketLimit e.g. maxPoolSocketLimit ="40", in order to have more than the default 25 sockets to transfer more parallel messages.


23: What happens when someone pulls the network cable?

Answer:

If this happens, other members will remove the instance from the cluster, and when you insert the cable again, the Tomcat instance might have completely flipped out. This is because the Operating system (OS) might start using 100% of the CPU when a multicast message is sent.


24: Assume that a JPA application has to be developed targetting Tomcat deployment. What are the JPA limitations with relation to Tomcat that you will convey to the developers?

Answer:

Tomcat is not an ideal choice for JPA applications because of the following reasons.

No dynamic weaving (instrumentation), no @EJB injection of a session bean and no @PersistenceContext injection of a container managed persistence unit is available.

I will convey these limitations to the developers so they can code the application accordingly.


25: The cluster doesn’t work under Linux with two nodes on two boxes. Why does it happen?

Answer:

This may happen because of various reasons. Most common reasons are firewall not active and network interface not enabled for multicast.


26: When using tcpListenAddress="auto", one gets "localhost" rather than "eth0" or another interface. How can this be changed?

Answer:

In order to get eth0, work on /etc/hosts.


*****



Connectors


27: What is JK (or AJP)?

Answer:

AJP can best be explained as a wire protocol. It is an optimized version of the HTTP protocol and allows a standalone web server such as Apache to talk to Tomcat.


28: At boot time, is the order of startup (Apache vs Tomcat) important?

Answer:

No. Apache and Tomcat can be restarted at any time independent of one another.


29: Is there any way to control the content of automatically generated mod_jk.conf-auto?

Answer:

Yes. We need to copy the automatically generated mod_jk.conf-auto and edit it manually accordingly to our preferences. None of production Tomcat installations really use mod_jk.conf-auto as it is.


30: How to bind to a specific ip address?

Answer:

This can be done using the Connector element address property.


31: From where can you download a binary distribution of connector?

Answer:

This is not possible since we need to download the source and compile it for the platform.


32: Why should one integrate Apache with Tomcat?

Answer:

There are many reasons to integrate Tomcat with Apache.

a) Socket handling / system stability: Apache has better socket handling with respect to error conditions, than Tomcat.

b) Speed: Apache is faster at serving static content than Tomcat.

c) Clustering: By using Apache as a front end you can let Apache act as a front door to your content to multiple Tomcat instances.


*****



Deployment


33: What is the reason that Tomcat 5 creates context configuration files?

Answer:

This is part of the change in Tomcat's configuration mechanism from version 4.x to make overall configuration more robust, flexible, and enterprise-friendly.


34: When someone redeploys a web application, the memory usage increases. Why?

Answer:

The reason for memory usage increase is because the Classloader (and the Class objects it loaded) cannot be recycled. They are stored in the permanent heap generation by the JVM.


*****



FDA_Validation


35: Can Tomcat be used in a validated environment?

Answer:

Yes, it can be used in a validated environment.


36: Is Tomcat itself validated?

Answer:

As per JSP specification, we can say that Tomcat can be itself validated.


37: In order to validate Tomcat, what kind of support is there?

Answer:

The Tomcat mailing lists are extremely active and contain members of many of the organizations, including contractors available for hire. There are numerous smaller vendors and several large ones, including IBM, HP, Sun, and Novell, who offer Tomcat consulting and support services, including application auditing, environment assessments, and risk analysis.


38: How you can check if you have a validated release?

Answer:

The PGP signatures are available on all the Tomcat download pages, and can be used to verify if the release really is the signed distribution.


39: How can one know that no one has tampered with the release package?

Answer:

Users are assured with the help of MD5 that the distribution has not been modified since the Release Manager signed it. Users can run MD5 on their local machine to verify that the digest of what they downloaded is the same as that published in the Apache download pages.


*****



Developing


40: How to configure Tomcat to support remote debugging?

Answer:

Add the following options when the JVM is started:

-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n


41: How to remotely debug Tomcat using NetBeans?

Answer:

Tomcat should be started in debug mode. If you have a servlet or JSP file, set a breakpoint where you think a problem might be occurring. Go to Run and then Attach Debugger. A dialog pops up to let you specify the following options:

a) Host: The IP address of the host your Tomcat installation is running on (127.0.0.1 if it is your local machine)

b) Port: The port of your Tomcat debugging interface, which should be 8000

c) Debugger: JPDA Debugger

d) Connector: SocketAttach


42: How can you change the monitoring interval for modified resources and application reloading?

Answer:

Monitoring interval for application reloading and modified resources can be changed by the use of backgroundProcessorDelay property on Context element or on its parent containers: Host and Engine.


43: How can you remotely debug Tomcat using Eclipse?

Answer:

Following steps are done in the given order to debug applications on Tomcat using Eclipse.

a) Make sure that Tomcat is started in remote debugging mode.

b) Make sure that you have the sources for the code that you are trying to debug in your IDE. - For the libraries and for Tomcat itself you can "attach" the sources to the jar files, open a class file and then click "Attach Source..." button.

c) Set a breakpoint where it is sure to hit on the next request.

d) Go to "Run and then Debug Configurations...". Click on "Remote Java Applications", then click "New". Type in the title. Port should be 8000. Save and run.

e) Eclipse will connect to the JVM that Tomcat is running under.


*****



Purchase this book or download sample versions for your ebook reader.
(Pages 1-16 show above.)