Java is an object oriented programming language which can be downloaded and installed in your local Machine from java.com
To explain java binaries and tools requires block diagram which gives clear picture. For now I brief few important tools.
- JDK - java development toolkit
- JVM - Java virtual machine
- JRE - Java Run time environment
Basic OOPS characteristics are
Inheritance
Encapsulation
Abstraction
and Polymorphism
The above concepts collectively makes application software extendable and changeable with less effort.Also helps in Developing design patterns. Design patterns gives solutions for common challenges usually a programmer faces while development applications.
Factory design pattern, Abstract design pattern, Builder pattern etc. I explain these Design patterns in another article.
Inheritance:
Inheritance is all about reusing one class behavior and members in it's child class. In java terminology these classes are called as super class and sub class. If class B extends class A then, class A becomes super class and class B becomes class A's sub class.
public class A{
public A(){
}
-------
}
public class B extends A{
public B(){
}
-------
}
Encapsulation is a technique of putting the source code all together within a unit. Java uses class and interface as keywords to represent unit. Data Hiding is one of the buzzwords which is possible only with implementation of Encapsulation in the program.
Abstraction:
Abstraction is the concept of hiding the irrelevant data from client/user visibility. To implement this feature java uses abstract keyword. this can be be prefixed to a class and methods. Once the class is abstract class then it's object can not be created. And id one or all methods of same class are followed by abstract keyword it can not be implemented.
The point here is java programming language gives implementation freedom to the developers where ever expected.
Sometimes java program is written to a another programmer rather a end user. Usually this code is called Application programming interface in short API. When a programmer writes a program with the intention to be used by another programmer, He/She may not need all the details [line by line] instruction's description is not required. Right?
The punch line is abstraction helps in showing only relevant data to the client of our program.
One of the mostly used design pattern is abstract factory design pattern.
Polymorphism:
In generic terminology poly means many morph means forms. It means many forms of a single method names.
Polymorphism can be achieved within the class or using inheritance i.e extends keyword.
Overloading and overriding:
Overloading rules:
within the class a same method can be duplicated but accepts different arguments and returns different result
- Number of arguments must be different
- Or Sequence of arguments must be different
- Or Type of the arguments must be different.
Let us take a method .
int add(int a, int b){
return a+b;
}
float add(float a, float b){
return a+b;
}
Overriding:
Overriding is possible only by using inheritance.For an instance super class has add(int a, int b). and sub class also needs add operation but computes differently. Then programmer simply overrides the add() of super class overrides the add() with his new implementation.
public class SuperClass{
int add(int a, int b){
....
}
}
public Subclass extends SuperClass{
@Overrides
int add(int a, int b){
// computes his own add operation
}
}