i want to know the difference between abstract class and interface and why we use servlets insntead of cgi .wht is getOnBytes(int size) method,wht is the difference between struts 1.0 and 1.1
i want to know the difference between abstract class and interface and why we use servlets insntead of cgi .wht is getOnBytes(int size) method,wht is the difference between struts 1.0 and 1.1
hi friend
first i would like to tell you about abstract classes.
It is a feature of c++. Abstract class means that we cannot create objects of that class. Interface(do mean same) is a concept introduced in java,which is similar to abstract classes.This doesnot mean that java dont have abstract classes.
Interface means that ALL functions in it have declaration only.no definitioni.e no body.(NOTE: ALL functions)
Abstract class means even a single function without body/definition is enough in it(to make it abstract)(NOTE:EVEN SINGLE Function is enough to make it abstract)
therefore 100% pure abstract class is an interface.
CGI stand for Common gateway interfaces.
CGI is most general term used to describe programs on the server that provide dynamic content!These programs can be written in C++,perl ,java.
Servlets is a type of CGI.
Hope my explanation is clear to you.
bye
:)
NEVER SAY DIE.
also do you want to know about getONBytes() !Are you sure? or is it getBytes()
:)
NEVER SAY DIE.
CGI use separate thread for each and every process.Servlet use same thread for all process.So Servlet is faster one than CGI..
Please do not copy and paste from other sites...
Difference between Abstract class and Interface
Last edited by admin; 01-19-2007 at 03:04 AM. Reason: Please do not copy and paste from other sites...
Thereis one more difference ,which i would like to add .
Interfaces have an additional capability.A class can implement more than one interface!By contrast , a class can only inherit a single super class(abstract or otherwise)
bye
:)
NEVER SAY DIE.
hi friends,
abstract class means we can't create the instance for that. It may have all abstract methods(without body), all concrete methods or a mixer of both.
Interface is special case of abstract class ie., all the methods are abstract methods(without body).
regards,
vijayakumar .vr
In Interface we can only declare the methods but can not implement as well as by declaring a method in Interface ,it automatically becomes abstract method.
And we can only declare the variables but can not initialized in Interface.
To use the methods and variables we have to implement the interface.
In Abstract Class we can declare the abstract method as well as normal methods.Diffrence is that we can not implement the abstract method there but implement the normal methods. and abstract method will be Accessible by inherited classes...
further any confusion then ur most welcome
Interface
Interfaces are implemented
Interfaces cannot have constructors
Multiple interfaces can be implemented(thereby allowing multiple inheritance)
Interfaces can only contain abstract methods or functions
all the members of an interface are public by default and cannot be explicitly declared so
All the methods/functions of an interface must be impelmented
Abstract Class
Abstract classes are Inherited
Only a single class can be inherited
Abstract classes can have both abstract and contrete methods
All the abstract members of an Abstract Class must be declared public
All the abstract methods/functions of an Abstract class must be implemented
1. in Interface all the methods are public abstract.this is not necessary with abstract class means abstract class can have concrete methods.
2. all the varible of interface are public static final.this is not necessary with abstract class.
3.abstract class must be inherited.interface must be extended.
in CGI for each request one instance is created which consume resouces.
in Servlet only and only one instance is created by container for servicing many requests.
thanks
A class implementing an interface must implement all of the methods defined in the interface, while a class extending an abstract class need not implement any of the methods defined in the abstract class. Additionally, a class extending an abstract class can implement an infinite number of it's own methods.
abstract class can have abstract as well as concrete methods whereas an interface can have only abstarct methods.
interface can have only final and static variables whereas this is not the case with abstract classes.
also,only subclasses of an abstract class can override its methods whereas in case of an interface any class can do the same.
In an abstarct class u need to explicitly prefix the method with "abstarct" to show that it is in an abstarct method but this is not the case with interfaces,
servlets are better as compared to Cgi as CGI is process based which is quite expensive whereas servlets are thread based.and also use less resources as compared to the CGI.
hope that was helpful.
The main difference is that an interface is implicitly fully abst class. An interface have all the fields public final static & methods public abstract.All the methods in interface are abstract , you can't provide body to them.While in an abst class it totally depends on you wether you want to have any abst methods or not.