Difference in Core Java

Difference in Core Java


Method Overloading
Method Overriding
Overloading occurs when two or more methods in one class have the same method name but different parameters.
Overriding means having two methods with the same method name and parameters (i.e., method signature). One of the methods is in the parent class and the other is in the child class.
It is a compile time polymorphism.
It is a run time polymorphism.
It may or may not need inheritance in Method Overloading.
It always requires inheritance in Method Overriding.
In Method Overloading, relationship is there between methods of same class.
In Method Overriding, relationship is there between methods of super class and sub class.
The static method can be overloaded.
The static method cannot be overridden.
Example:
class Add
{
   int sum(int a, int b)
   {
     return a + b;
   }
  int sum(int a)
  {
    return a + 10;
   }
}
Example:
class A  // Super Class
{
  void display(int num)
  {    
   }
}
//Class B inherits Class A
class B //Sub Class
{
  void display(int num)
  {    
   }
}


Abstract Class

Interface

An Abstract Class is always used to serve as a base class as it can’t be instantiated.
An Interface is one type of template having only signature of methods.
An Abstract class contains abstract methods and non-abstract (concrete) methods.
An Interface contains all abstract methods i.e. all methods have to be abstract.
You can define & use any variable in abstract class.
An Interface does not allow declaration & use of variable as interface does not contain fields.
An abstract class can have a constructor.
An interface cannot have a constructor.
If any class already has a base class, it cannot inherit abstract class.
Though class has a base class, it can implement any number of interfaces.
To access an abstract class is fast than interface.
Interface is slower in compare to abstract class.
A class may inherit only one abstract class.
A class may inherit several interfaces.

Array

Vector

Array is a static, whose size can be fixed.
A vector is a dynamic array, whose size can be increased.
Array is not class. It is a primitive data type
A vector is a class.
In array elements cannot be deleted and inserted.
In vector elements can be deleted and inserted.
Array can store only homogeneous values.
Vectors can store any type of objects.
Memory consumption is less in array.
Memory consumption is more in vector.
Array can be one, two or multi-dimensional.
Vector is one dimensional.


APPLET
APPLICATION
It is small program uses another application program for its execution.
An application is the programs executed on the computer independently.
Do not use the main method
Uses the main method for execution
Cannot run independently require API's (Ex. Web API).
Can run alone but require JRE.
Prior installation is not needed
Requires prior explicit installation on the local computer.
Applets cannot read from and write to the files on the local computer.
Applications are capable of performing those operations to the files on the local computer.
Cannot communicate with other servers.
Communication with other servers is probably possible.
Applets cannot access files residing on the local computer.
Can access any data or file available on the system.
Requires security for the system as they are untrusted.
No security concerns are there.

AWT
Swing
AWT stands for Abstract windows toolkit.
Swing is also called as JFC’s (Java Foundation classes).
AWT components are called Heavyweight component.
Swings are called light weight component because swing components sits on the top of AWT components and do the work.
AWT components require java.awt package.
Swing components require javax.swing package.
AWT components are platform dependent.
Swing components are made in purely java and they are platform independent.
This feature is not supported in AWT.
We can have different look and feel in Swing.
These feature is not available in AWT.
Swing has many advanced features like JTabel, Jtabbed pane which is not available in AWT. Also. Swing components are called "lightweight" because they do not require a native OS object to implement their functionality. JDialog and JFrame are heavyweight, because they do have a peer. So components like JButton, JTextArea, etc., are lightweight because they do not have an OS peer.
With AWT, you have 21 "peers" (one for each control and one for the dialog itself). A "peer" is a widget provided by the operating system, such as a button object or an entry field object.
With Swing, you would have only one peer, the operating system's window object. All of the buttons, entry fields, etc. are drawn by the Swing package on the drawing surface provided by the window object. This is the reason that Swing has more code. It has to draw the button or other control and implement its behavior instead of relying on the host operating system to perform those functions.
AWT is a thin layer of code on top of the OS.
Swing is much larger. Swing also has very much richer functionality.
Using AWT, you have to implement a lot of things yourself.
Swing has them built in.



Comments

Popular posts from this blog

પટેલ સમાજનો ઈતિહાસ જાણો : કોણ અને ક્યાંથી આવ્યા હતા પાટીદારો

Python HTML Generator using Yattag Part 1

Java Event Delegation Model, Listener and Adapter Classes