Inretview Questions

Wednesday, April 1, 2009

1.What is the difference between apache webserver, java webserver and tomcat server?

Apache is an HTTP server written in C that can be compiled and run on many platforms. Java WebServer is an HTTP server from Sun written in Java that also supports Servlets and JSP.
Tomcat is an open-source HTTP server from the Apache Foundation, written in Java, that supports Servlets and JSP. It can also be used as a "plug-in" to native-code HTTP servers, such as Apache Web Server and IIS, to provide support for Servlets (while still serving normal HTTP requests from the primary, native-code web server).
Tomcat behind Apache with a connector .apache web server is a webserver where as tomcat is a servlet container.
Apache is what your browser connects to, tomcat is what apache connects
to to ask for servlets to be processed. However, tomcat now includes a
webserver so you can cut out the middle man. You might not want to do
this on a large production environment.
Apache is a general-purpose http server, which supports a number of advanced options that Tomcat doesn't. Although Tomcat can be used as a general purpose http server, you can also set up Apache and Tomcat to work together with Apache serving static content and forwarding the requests for dynamic content to Tomcat. This is generally prefered when using tomcat because the overhead from serving static content directly from Apache is much lower than having Tomcat handle all of the requests

2.What is the difference between Web Site and Web Browser?


Web site is the client base system( or said to collection of web pages contains information interact with user or client) use to interact over the network
Web Browser is the applicaction or tool use to run web pages or web site.

3.Difference between web server and application server?


Webserver:
A Web server handles the HTTP protocol. When the Web server receives an HTTP request, it responds with an HTTP response, such as sending back an HTML page. To process a request, a Web server may respond with a static HTML page or image, send a redirect, or delegate the dynamic response generation to some other program such as CGI scripts, JSPs (JavaServer Pages), servlets, ASPs (Active Server Pages), server-side JavaScripts, or some other server-side technology. Whatever their purpose, such server-side programs generate a response, most often in HTML, for viewing in a Web browser.
Application Server:
As for the application server, according to our definition, an application server exposes business logic to client applications through various protocols, possibly including HTTP. While a Web server mainly deals with sending HTML for display in a Web browser, an application server provides access to business logic for use by client application programs. The application program can use this logic just as it would call a method on an object

Exception Handling

Exception handling
Exception can be generated by Java-runtime system or they can be manually generated by code.

Error-Handling becomes a necessary while developing an application to account for exceptional situations that may occur during the program execution, such as
Run out of memory
Resource allocation Error
Inability to find a file
Problems in Network connectivity.
If the Resource file is not present in the disk, you can use the Exception handling mechanisim to handle such abrupt termination of program.

Exception class : is used for the exceptional conditions that are trapped by the program.
An exception is an abnormal condition or error that occur during the execution of the program.
Error : the error class defines the conditions that do not occur under normal conditions.
Eg: Run out of memory, Stack overflow error.

Java.lang.Object
+….Java.Lang.Throwable Throwable
+…. Java.lang.Error
| +…. A whole bunch of errors
| Exception Error
+….Java.Lang.Exception (Unchecked, Checked)
+….Java.Lang.RuntimeException
| +…. Various Unchecked Exception
|
+…. Various checked Exceptions.

Two types of exceptions:
1. Checked Exceptions : must be declare in the method declaration or caught in a catch block.
Checked exception must be handled at Compile Time. Environmental error that cannot necessarly be detected by Testing, Eg: disk full, brocken Socket, Database unavailable etc.

2. Un-checked Exceptions: Run-time Exceptions and Error, does’t have to be declare.(but can be caught).
Run-time Exceptions : programming errors that should be detectd in Testing ,
Arithmetic, Null pointer, ArrayIndexOutofBounds, ArrayStore, FilenotFound, NumberFormate, IO, OutofMemory.
Errors: Virtual mechine error – class not found , out of memory, no such method , illegal access to private field , etc.

Java Exception handling can be managed by five keywords:
Try : The try block governs the statements that are enclosed within it and defines the scope of exception handler associated with it. Try block follows catch or finally or both.

Catch: This is a default exception handler. since the exception class is the base class for all the exception class, this handler id capable of catching any type of exception.
The catch statement takes an Object of exception class as a parameter, if an exception is thrown the statement in the catch block is executed. The catch block is restricted to the statements in the proceeding try block only.
Try {
// statements that may cause exception
}
catch(Exception obj)
{

}
Finally : when an exception is raised, the statement in the try block is ignored, some times it is necessary to process certain statements irrespective of wheather an exception is raised or not, the finally block is used for this purpose.
Throw : The throw class is used to call exception explicitly. You may want to throw an exception when the user enters a wrong login ID and pass word, you can use throw statement to do so.
The throw statement takes an single argument, which is an Object of exception class.

Throw
If the Object does not belong to a valid exception class the compiler gives error.

Throws :The throws statement species the list of exception that has thrown by a method.
If a method is capable of raising an exception that is does not handle, it must specify the exception has to be handle by the calling method, this is done by using the throw statement.
[] [] []

Eg: public void accept password( ) throws illegalException
{
System.out.println(“Intruder”);
Throw new illegalAccesException;
}