Servlet Java Interview Questions – Set 09

In the Servlet 2.4 specification SingleThreadModel has been deprecated, why Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level. Can you give some … Read more

Interface Java Interview Questions – Set 09

Why does JComponent have add() and remove() methods but Component does not because JComponent is a subclass of Container, and can contain other components and jcomponents. How can I implement a thread-safe JSP page? – You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive … Read more

Multi Threading Java Interview Questions – Set 09

Why is locking of a method or block of code for thread safety is called “synchronized” and not “lock” or “locked When a method or block of code is locked with the reserved “synchronized” key word in Java, the memory (i.e. heap) where the shared data is kept is synchronized. This means,When a synchronized block … Read more

Core Java Interview Questions – Set 09

How are commas used in the intialization and iteration parts of a for statement Commas are used to separate multiple statements within the initialization and iteration parts of a forstatement. When are the non static variables loaded into the memory They are loaded just before the constructor is called What modifiers can be used with a … Read more

JSP Java Interview Questions – Set 08

How do you restrict page errors display in the JSP page You first set “Errorpage” attribute of PAGE directory to the name of the error page (ie Errorpage=”error.jsp”)in your jsp page .Then in the error jsp page set “isErrorpage=TRUE”. When an error occur in your jsp page it will automatically call the error page. How … Read more

Servlet Java Interview Questions – Set 08

What is JSP tag file A source file containing a reusable fragment of JSP code that is translated into a tag handler when a JSP page is translated into a servlet. What is JSP container A container that provides the same services as a servlet container and an engine that interprets and processes JSP pages … Read more

Interface Java Interview Questions – Set 08

What is an observer design pattern The Observer pattern is a behavioral design pattern that  allows an object (an Observer) to watch another object (a Subject). The subject and observer to have a publish/subscribe relationship. Observers can register to receive events from the Subject. Some of the practical uses of observer pattern are: When a … Read more

Multi Threading Java Interview Questions – Set 08

What is the difference between sleep(), suspend() and wait() Thread.sleep() takes the current thread to a “Not Runnable” state for specified amount of time. The thread holds the monitors it has acquired. For example, if a thread is running a synchronized block or method and sleep method is called then no other thread will be … Read more

Core Java Interview Questions – Set 08

What values of the bits are shifted in after the shift In case of signed left shift >> the new bits are set to zero. But in case of signed right shift it takes the value of most significant bit before the shift, that is if the most significant bit before shift is 0 it … Read more

Exception Handling Java Interview Questions – Set 07

Explain how you would get thread-safety issues due to non-atomic operations with a code example The code snippets below demonstrates non-atomic operations producing incorrect results with code. The program below uses a shared Counter object, that is shared between three concurrent users (i.e. three threads). The Counter object is responsible for incrementing the counter. Firstly, the Counter class. … Read more