Java Servlet classification.
1 posts in topic
Flat View  Flat View

Posted By:   Kyle_Banashek
Posted On:   Sunday, December 9, 2001 10:59 AM

Is a Java Servlet considered a Java Interface ?

Re: Java Servlet classification.

Posted By:   Stephen_McConnell  
Posted On:   Sunday, December 9, 2001 01:26 PM

Good question.

javax.servlet.GenericServlet is what is called an Abstract class. That is a class that has some methods which are "declared" but not filled in... They have no code behind them.

This means that when you extend them, you have to overwrite the method by definining it again in the "CONCRETE" class that extends the "ABSTRACT" class.

In the case of javax.servlet.GenericServlet many of the methods are filled in, but methods like doPut() and doGet() and init() and some others do not have code behind them. You have to implement them in your own servlet class.

This provides methods that are common to all servlets, but leaves you to develope the methods that are specific to your application.

An interface has no methods that are "filled" in... They are just stubs.
When you implement (as opposed to extend) an interface, you must fill in those methods or it is an "ABSTRACT" class.

This allows different classes to "implement" specific methods in different ways.

For example you might have an interface "Vehicle" that defines the methods goRight(), goFoward(), goLeft(), goBackward(), stop().... etc.

A class "Car", "Boat", "Wagon", "Airplane" might all implement the interface, but each Class will do each method differently.... But a class that operates on a Vehicle can call each method, knowing the concrete class will handle the command correctly.

Hope this helps.

Stephen L. McConnell


About | Sitemap | Contact