MY mENU


Wednesday, 21 March 2012

Differences between Servlets and JSP:


Differences between Servlets and JSP:


Servlets


JSP

1. Best suitable for processing logic

1. Best suitable for presentation logic

2. we cannot separate business and presentation logic

2. Separation of presentation and business logic is possible

3. Servlet developer should have strong knowledge in Java

3.JSP author is not required to have strong knowledge in Java

4. For source code changes ,we have to perform explicitly compilation

4. For source code changes ,it is not required to perform explicit compilation

5. Relatively development time is more

5. Relatively development time is less

Jsp Interview Questions

What is JSP ? 

Java Server Pages (JSP) is a server side component for the generation of dynamic information as the response. Best suitable to implement view components (presentation layer components). It is part of SUN’s J2EE platform.



Explain the benefits of JSP?

These are some of the benefits due to the usage of JSP they are:

  •  Portability, reusability and logic components of the language can be used across various platforms. 
  • Memory and exception management. 
  • Has wide range of API which increases the output functionality.
  • Low maintenance and easy deployment. 
  • Robust performance on multiple requests.

Is JSP technology extensible?

Yes, it is. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.



Can we implement an interface in a JSP?
No 



Explain the differences between ASP and JSP?
The big difference between both of these technologies lies with the design of the software. JSP technology is server and platform independent whereas ASP relies primarily on Microsoft technologies.

Can I stop JSP execution while in the midst of processing a request?
Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick (assuming Java is your scripting language) is to use the return statement when we want to terminate further processing.

Explain JSP API ?

The JSP API contains only one package : javax.servlet.jsp

It contains the following 2 interfaces: 

  1. JspPage: This interface defines the two life cycle methods jspInit() and jspDestroy()
  2.  HttpJspPage:This interface defines only one life cyle method _jspService() method.

Every generated servlet for the jsp's should implement either JspPage or HttpJspPage interface either directly or indirectly.

Generate Pyramid For a Given Number in Java

Generate Pyramid For a Given Number in Java
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class GeneratePyramidExample {
      public static void main (String[] args) throws Exception{
            BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
                System.out.println("Enter Number:");
                     int as= Integer.parseInt (br.readLine());
                         System.out.println("Enter X:");
                             int x= Integer.parseInt (br.readLine());
  int y = 0;
    for(int i=0; i<= as ;i++) {
            for(int j=1; j <= i ; j++) {
                  System.out.print(y + "\t");
                      y = y + x;
                   }
           System.out.println("");
         }
    }
}

Output of this example would be

Enter Number:
5
Enter X:
1

0
1 2
3 4 5
6 7 8 9
10 11 12 13 14

----------------------------------------------

Enter Number:
5
Enter X:
2

0
2 4
6 8 10
12 14 16 18
20 22 24 26 28

----------------------------------------------

Enter Number:
5
Enter X:
3

0
3 6
9 12 15
18 21 24 27
30 33 36 39 42