Skip to main content

Posts

Showing posts from February, 2019

JSP Interview Questions part - 2

JSP Interview Questions 1. How will you implement error page in JSP? To implement an error-handling page in JSP, we first create a JSP with error page handling information. In most of the cases we gracefully handle error by giving a user-friendly message like “Sorry! There is system error. Please try again by refreshing page.” In this error page, we show user-friendly message to user, but we also log important information like stack trace to our application log file. We have to add parameter isErrorPage=true in page directive of this page. This tells to JSP container that this is our error page. <%@page isErrorPage=”true” %> Now we can use this error page in other JSP where we want to handle error. In case of an error or exception, these JSP will direct it to errorPage.            <% page errorPage=”ErrorPage.jsp” %> 2. How will you send XML data from a JSP? In general, JSP is used to pass HTML data to web browser. If we want to send data in XML

JSP Interview Questions

JSP Interview Questions 1. What are the implicit objects in JSP? JSP has following implicit objects: 1. Request 2. Response 3. Application 4. Exception 5. Page 6. Config 7.  Session 2. How will you extend JSP code? We can extend JSP code by using Tag libraries and Custom actions. 3. How will you handle runtime exceptions in JSP? We use Errorpage attribute in JSP to catch runtime exceptions. This attribute forwards user request to the error page automatically. 4. How will you prevent multiple submits of a page that come by clicking refresh button multiple times? We can use Post Redirect Get (PRG) pattern to solve the issue of multiple submission of same data. It works as follows: First time when a user submits a form to server by POST or GET method, then we update the state in application database. Then we send a redirect response to send reply to client. Then we load a view by using GET command. There is no data is sent in this. Since this

Mixed Java Tricky Interview Questions

Tricky Mixed Interview Questions 1. What are Wrapper classes in Java? Java has concept of Wrapper classes to allow primitive types to be accessed as objects. Primitive types like boolean, int, double, float etc. have corresponding Wrappers classes – Boolean, Integer, Double, Float etc. Many of these Wrapper classes are in java.lang package. Java 5.0 has launched the concept of Autoboxing and Unboxing in Java for Wrapper classes. E.g. public class WrapperTest{ public static void main(String args[]){ //Converting int into Integer int count=50; Integer i=Integer.valueOf(count); //converting int into Integer Integer j=a; //autoboxing, now compiler will write Integer.valueOf(count) internally System.out.println(count+" "+i+" "+j); } } 2. What is the purpose of native method in Java? The native keyword is used for applying to a method to indicate that the method is implemented in native code using JNI(Java Native Interface). The

Java Tricky Interview Questions Part - 2

Java Tricky Questions 1. How can we print an Array in Java? We can print an array by using methods of Arrays class. We can either use Arrays.toString() method or we can use Arrays.deepToString() method. Since array doesn't implement toString() method by itself, just passing an array to System.out.println() will not print its contents. But we can use Arrays.toString() to print each element of an array. 2. Is it ok to use random numbers in the implementation of hashcode() method in Java? No. The hashcode of an object should be always same. If you use random number in hashcode() method, then you may get a different value of hashcode for same object. This will break the hashcode contract. 3. Between two types of dependency injections, constructor injection and setter dependency injection, which one is better? Constructor injection guarantees that a class will be initialized with all its dependencies during creation. But setter injection provides flexibility to