February 13, 2010
Difference between web server and application server?
Why can’t we make jsp as a controller and action servlet in struts?
When JSP compiles, internally the jsp compiler converts it to servlets and compiles servlets java file and generartes the class file. Every time it will do the same thing, so it may take several time. It may cause performance issue.
Most of the applications are created in MVC design pattern to seperate the functions of differnetcomponents and handle the complexity of applications. JSP and Servlets are the server sidecomponents which can respond to the client request.
Servlets are the basic components for request handling in Web Server. They contains pure Java code. Everything that needs to be done to generate the proper user response (which is genarally HTML code) needs to be done through coding. As a single servlet cannot respond each and every request by itself as client request varies in type (e.g. enquiry, update request, add etc) the request and response object is passed onto different servlets with little task completed by each servlet. This controlling part is easier to write in java. So Servlet is used as controller.
JSP is again a servlet which has syntax more like to HTML with java support. Whatever user is going to see as result of his request is HTML. Programmer can easily write html tags inside JSP to render html. This is very economical to change also. So all this code is written JSP which is (generally) the final link in Servlet chaining.
In simple words, Controller (servlet) has pure Java code while View (JSP) has HTML code.
why string is immutable ?
In java, Strings are handling in Pool format.
For example:
String str1 = “xyz”;
This string(str1) will be stored into memory in particular address. When we defining new String with same array of characters like
String str2 = “xyz”;
Now JVM will check in String Pool where there is same characters are available or not. If two Strings are match the JVM will refer str1 address to str2. Now the str1 and str2 referring the same characters in same memory location. This is a good idea for increasing memory efficiency.
When we change the str1 characters, the changes will be reflected to str2. Because both str1 and str2 variables are referring the same memory location. For avoiding this we are keeping String as immutable. However we can use StringBuffer if you want to do modifications in the string.
Making String immutable, makes it thread safe and thus imporves performance.
Once a string object is created no changes can be made to it. If a string is modified in code a new object will be
created. That is why string is immutable.
February 9, 2010
What is the Difference between jar, ear and war?
.jar files: These files are with the .jar extension. The .jar files contain the libraries, resources and accessories files like property files.
.war files: These files are with the .war extension. The war file contains the web application that can be deployed on the any servlet/jsp container. The .war file contains jsp, html, java script and other files for necessary for the development of web applications.
.ear files: WAR(Web module) + JAR(can be EJB module or application client module). An EAR(Enterprise archive) is a top-level container which contains modules like: EJB modules, web modules, application client modules etc.