Powered by Blogger.

Friday 26 February 2016

Question And Answer

Q.1- What is the difference between Exception and Error in java ?Exception and Error classes are both subclasses of the Throwable class. The Exception class is used for exceptional conditions that a user’s program should catch. The Error class defines exceptions that are not excepted to be caught by the user program.

Q.2- What is the difference between throw and throws ?
The keyword throw is used inside method body to invoke an exception and throws clause is used in method declaration (signature). In other words Throws clause in used to declare an exception and thow keyword is used to throw an exception explicitly.

Q.3- How many types of errors?
The types of errors in java are
 1. Syntax Error : Syntax errors are also called as compiler errors. 
Example: Missing of semicolon, Mismatch in opening and closing parenthesis, Misspell a keyword etc.
 2. Run time/Logical Error: Run-time errors are errors that occur while your program runs.
Examples: Divide an integer by zero.
                   Using a null object to reference an objects members.
                   Storing a value that is of incompatible data type. etc.

Q.4- why we use try and catch block in java?
Try: The try block contains a block of program statements within which an exception might occur. A try block is always followed by a catch block, which handles the exception that occurs in associated try block. A try block must followed by a Catch block or Finally block or both.
Catch: A catch block must be associated with a try block. The corresponding catch block executes if an exception of a particular type occurs within the try block. For example if an arithmetic exception occurs in try block then the statements enclosed in catch block for arithmetic exception executes.

Q.5- What is the difference between difference between doGet() and doPost()?
doGet() and doPost() are HTTP requests handled by servlet classes.
In doGet(), the parameters are appended to the URL and sent along with the header information.
This does not happen in case of doPost().
In doPost(), the parameters are sent separately.
Since most of the web servers support only a limited amount of information to be attached to the headers, the size of this header should not exceed 1024 bytes.
doPost() does not have this constraint.
Usually programmers find it difficult to choose between doGet() and doPost().
doGet() shall be used when small amount of data and insensitive data like a query has to be sent as a request.
doPost() shall be used when comparatively large amount of sensitive data has to be sent.

Q.6- What is the difference between using getSession(true) and getSession(false) methods?
getSession(true) will check whether a session already exists for the user. If yes, it will return that session object else it will create a new session object and return it.
getSession(false) will check existence of session. If session exists, then it returns the reference of that session object, if not, this methods will return null.

Q.7- What is meant by a Web Application ?
A Web application is a dynamic extension of a Web or application server.
There are two types of web applications:   
  • Presentation-oriented 
  • Service-oriented. 
A presentation-oriented Web application generates interactive web pages, which contain various types of markup language and dynamic content in response to requests. On the other hand,
A service-oriented web application implements the endpoint of a web service. In general,
A Web application can be seen as a collection of servlets installed under a specific subset of the server’s URL namespace.

Q.8- How are the JSP requests handled ?
On the arrival of a JSP request, the browser first requests a page with a .jsp extension. Then, the Web server reads the request and using the JSP compiler, the Web server converts the JSP page into a servlet class. Notice that the JSP file is compiled only on the first request of the page, or if the JSP file has changed.The generated servlet class is invoked, in order to handle the browser’s request. Once the execution of the request is over, the servlet sends a response back to the client.