This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Creating an object from an interface (like ServletConfig) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating an object from an interface (like ServletConfig)" Watch "Creating an object from an interface (like ServletConfig)" New topic
Author

Creating an object from an interface (like ServletConfig)

Deepak Giri
Ranch Hand

Joined: Feb 12, 2009
Posts: 52
sorry, might be the question is too silly but still can't help without asking (the reason might be that my mind has become completely useless at this point)

we know in the life cycle of a servlet, in the early stages, an object of ServletConfig is passed to the init() method (which is called by the container).
but i'm wondering how can we create an object of an interface (which ServletConfig is)???


SCJP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

Moved to Java in General (with appropriate change of title).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

Deepak Giri wrote:how can we create an object of an interface (which ServletConfig is)???

You don't. You create an object of a (concrete) class that implements the interface.

In the specific case of ServletConfig, the container (Tomcat, for example) instatiates a class that implementes ServeltConfig. We don't know which class that is, and more importantly we don't care!
Deepak Giri
Ranch Hand

Joined: Feb 12, 2009
Posts: 52
thanks

by the way, can you tell me the exact signature of that init(ServletConfig) method?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

It's in the JavaDoc.
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Here is the link to the Java API Collection.

You need to check the Enterprise Edition API
 
Don't get me started about those stupid light bulbs.
 
subject: Creating an object from an interface (like ServletConfig)
 
Similar Threads
jspInit()
getServletConfig()
init method of servlets
Why does GenericServlet implements ServletConfig?
init() and http related questions