Which is faster in execution-JSP or SERVLET ? Why?


Servlet is faster in execution as every jsp is changed on converted to servlet before starting the execution. Thus the server need to spend some time to convent a JSP file to servlet at it’s first time execution. But developing a jsp is very easy when compared to servlet.
Every time before executing a jsp & server searches for related servlet file. If it existsWhen ever we send a request to the JSP file it checks the servlet representing the JSP file. Then the web container runs the jsp compiler that  generates the servlet code
then start the execution of that servlet otherwise server creates servlet files for those jsps first and then execution takes place

Can we declare final method in abstract class?


If a method in a class is defined as final, then we can’t provide the re-implementation for that final method in it’s derived classes i.e overriding is not possible for that method.

An abstract class contains one or more abstract method.

  • We can have concrete(non-abstract) methods declared as final as it contains both definition and declaration in abstract itself.
  • However, we cannot define abstract methods as final, since the class inheriting our abstract class cannot define/re-implement them.

Example:

abstract class Shape
{
    protected String name;

    abstract void draw();
    abstract void paint();

    final String getNameOfShpae() {
        retrun "Name of the Shape is"+name;
    }
}

 

Can the same object os Stateless Session bean be shared by multiple clients? Can the same object os Stateful Session bean be shared by multiple clients?


It is possible to share the same object of stateless session bean by multiple clients.
A Server maintains a pool of objects in case of stateless session bean. And every When ever we send a request to the JSP file it checks the servlet representing the JSP file. Then the web container runs the jsp compiler that  generates the servlet code
time for a request it uses one of the pool of objects which is free at that time. The server gets back that object in to the pool only after the client work on that object is Directoryover [ client says that by invoking ejbremove() method]

After the client release that object, the server may used the same object to handle another client request, thus the same object to handle another client request. Thus the same object of stateless session can be shared by multiple clients But sharing the same object for multiple clients is not possible in case of state full session bean. Here server should maintain an object for every clients to handle / maintain the state of that object.

How we declare a synchronized block? What does this represent in the Declaration of sunchronized block?


When two or more threads need to access to a shared resource they need some way to ensure that the resource will be used by only one thread at a time. The process by which this achieved is called synchronization.

The general form of synchronize statement :

Synchronized (object) {
// statement to be synchronized
}
here the object is a reference to the object being synchronized. A synchronized block ensures that a call to a method that is member of object occurs only after the current thread has successfully entered the object’s moniter

What is the Max amount of information that can be saved in a Session Object?


As such there is no limit on the amount of information that can be saved in a Session Object. Only the RAM available on the server machine is the limitation. The only limit is the Session ID length(Identifier) , which should not exceed more than 4K. If the data to be store is very huge, then it’s preferred to save it to a temporary file onto hard disk, rather than saving it in session. Internally if the amount of data being saved in Session exceeds the predefined limit, most of the servers write it to a temporary cache on Hard disk.

What are Good Ways of Debugging a Servlet? Are IDE’s which support Servlet Debugging?


There are couple of Methods. Firstly servers like JRun and others provide separate logs where all your Print requests will print their data into. For example requests to System.out. and System.err go to different log files. If this features is not available or you want to maintain logs separately for each module then  you can create a static class called “LogWriter” and call the method inside the try catch loop. The print method in Log Writer will be writing to a custom defined Log File.
try
{  ….
}
catch(Exception exp)
{
LogWriter.print(“Debug : The following error occurred at function ….  ‘)
}
Also Inprise JBuilder supports Servlet Debugging. Please refer to JBuilder documentation for details.
Just as a Cautionary note, from your Servlets, never call System.exit(0). The results might be unpredictable. Might close down the entire Server. The Best way is to catch the Exception and either send resultant Error Page to the Browser or Write to a Log file and inform user about the Error.

What is Server Side Push and how is it implemented and when is it useful?


Server Side push is useful when data needs to change regularly on the clients application or browser , without intervention from client. Standard examples might include apps like Stock’s Tracker, Current News etc. As such server cannot connect to client’s application automatically. The mechanism used is, when client first connects to Server, (Either through login etc..), then Server keeps the TCP/IP connection open.
It’s not always possible or feasible to keep the connection to Server open. So another method used is, to use the standard HTTP protocols ways of refreshing the page, which is normally supported by all browsers.
<META HTTP-EQUIV=”Refresh” CONTENT=”5;URL=/servlet/stockquotes/”>
This will refresh the page in the browser automatically and loads the new data every 5 seconds.

What is difference between stateless and stateful session beans?


In this post, we will see the differences b/w stateless and stateful session beans.

Stateless Session Bean:

  • Stateless session bean do not maintain state across method calls and transactions
    The EJB server transparently reuses instances of the Bean to service different clients at the per-method level (access to the session bean is serialized and is 1 client per session bean per method.
  • Used mainly to provide a pool of beans to handle frequent but brief requests. The EJB server transparently reuses instances of the bean to service different clients.
  • Do not retain client information from one method invocation to the next. So many require the client to maintain on the client side which can mean more complex client code.
  • Client passes needed information as parameters to the business methods. Performance can be improved due to fewer connections across the network.

Stateful Session Bean :

  • A stateful session bean holds the client session’s state.
  • It is an extension of the client that creates it.
  • Its fields contain a conversational state on behalf of the session object’s client.
    This state describes the conversation represented by a specific client/session object pair.
  • lifetime of these are controlled by the client and cannot be shared between clients.

What are the differences between interface and abstract class?


The key difference between an interface and the corresponding abstract class is that a class or interface can have unlimited number of immediate super interface but it can only have one super class.
There are two primary axes of “inheritance” an object-oriented language like java. Implementation inheritance is where the sub-class inherits the actual code implementation from the parent. Interface inhyeritance is where the sub-class adheres to the public interface of the parent.
Also java actally mixes the two notions together a bi…. java interfaces are nice and clean. When you implement an interface, you are stipulating that your class adheres to the “contract” of the interface that you spefified. Java class inheritance isn’t so clean when you sub-class in java you are getting both the code inheritance but you are also stipulating that you sub-class adheres to the contract of the interface of the parent class.

Abstrct class in java are just like regular java classes but with the added constraint that you cannot instance then directly. In terms of that added constraint, they are basically classes which don’t actually implement all lof the code specified by their “contract”.

What is the difference between callable statements, prepare statements , createstatements?


  • CallableStatement: This is used to retrieve the stored procedures from the database. ie., these statements are used when two or more SQL statements are retrieved over and over.
  • PreparedStatement: These are pre-compiled statements which are stored in database. We are using these, if the same query is to be executed over and over.
  • CreateStatement: This is used to execute single SQL statement.