PUB ID

Monday, 28 December 2015

Why "this" keyword is not Allowed in static Method Area?


1. "this" is used to refer to the parent object of a variable or method. When you declare static on a method the method can be called without needing to instantiate an object of the class. Therefore the "this" keyword is not allowed because your static method is not associated with any objects.


2.  Keyword "this" refers to the object that you are operation with. In your case "this" inside any non-static methods or constructor, then "this" refers to that particular instance of the class Sub.So it is applicable only when the object is created. But anything in the static context of a class, you can use without even creating object for that as it is resolved during the class loading. "this" resolved only when object is created ( you can even say dynamically for which object). So "this" make sense in static context

3.  this :- "this" means current class OBJECT , so its clear that "this" only come in the picture once we intended to create an Object of that class.
static method:- there is no need to create an object in order to use static method. means "instance" or object creation doesn't any sense with "static" as per Java rule.
So There would be contradiction,if we use both together(static and this) . That is the reason we can not use "this" in static method.


Tuesday, 22 December 2015

why no reverse() method in String class?

Because String Class Object  is Immutable. (an immutable object is an object whose state cannot be modified after it is created).
So modification is not allowed in string class in same object. If we want to reverse the String We should use StringBuffer class reverse() method.

Difference between ServletConfig and ServletContext?


                         ServletConfig
                ServletContext
ServletConfig  Represents single Servlet.
It represents  whole  WebApplication running on particular JVM and Common for all Servlets.
It’s like a local parameter associated with particular Servlet.
It’s like a local parameter associated with whole application.
It is a name,value pair defined inside the servlet section of web.xml file .so,it has servlet wide scope.
It has application wide scope .so,defined out side of servlet tag in web.xml
getServletConfig() method is used to get the config object.
getServletContext() method is used to get the context object.


Monday, 21 December 2015

What is the difference between Web Server and Application server?


                    Web Server
                     Applilcation Server
Webserver serves pages for viewing in web browser.
application server provides exposes businness logic for client applications through various protocols.
Webserver exclusively handles http requests.
application server serves bussiness logic to application programs through any number of protocols.
Web Server Have Only Servlet Container  And  JSP Container
Application Server  Have Servlet Container ,JSP Container  And EJB Container.
Webserver delegation model is fairly simple,when the request comes into the webserver,it simply passes the request to the program best able to handle it(Server side program). It may not support transactions and database connection pooling.
Application server is more capable of dynamic behaviour than webserver. We can also configure application server to work as a webserver.Simply application server is a superset of webserver.