Core JAVA
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Java overview
Java basics
Java Objects and classes
Java Constructors
Java basic datatypes
Java variable types
Java modifiers/Access Modifiers In Java
Java Basic Operators
Java Loops and Controls
Java conditions
Java numbers and characters
Java strings
Java arrays
Java date time
Java methods
Java file and IO operations
Java exceptions
Inner class
Java OOPs Concepts
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java Interface
Cohesion and Coupling
Association, Aggregation and Composition
Java Collections
Java ArrayList
Java LinkedList
Set and HashSet
LinkedHashSet and TreeSet
Queue and PriorityQueue
Deque and PriorityQueue
Java Map Interface
Java HashMap
Internal Working Of Java HashMap
Java Mutithread
Methods of Thread In Java
Join , run & Start Method in Threads
Difference b/w start & run Methods in Threads
Java Concurrency Package & its Features
CountDownLatch, CyclicBarrier, Semaphore and Mutex in Thread
Java Concepts of OOPs
What is OOPs
OOPs stands for object oriented programming. Any programming languages which follows principals of OOP is called OOP (object oriented programming) language. In world of OOP everything is an object. We look in detail on concepts of OOPs in this article.
Before OOP programming languages (java, C++ etc.) procedural programming languages were popular and in use for example C, COBOL, Fortran and etc. These programming languages used to write logic in procedure or steps without having any object or concept of object.
What Is Class and Object
OOP is based on objects and classes so it is important to know what is class and object, see below definition of class and object.
Class – Class is a blue print or skeleton or representation of any real world object for example Car class will be skeleton or blue print of any Car object in real world.
Object – Object is instance of Class and we can create as many objects as we want from Class for example car1, car2, car3 etc can be objects of Car class.
Example of Object and Class:
In this example Car is a class and car is object of Car class, created in main method.
public class Car { String color; int maxSpeed = 100 public Car(){ //Constructor without arguments } public Car(String color){ //Constructor with arguments System.out.println("Passed argument is: " + color); } public void startCar() { System.out.println("Car started using method startCar”); } public static void main(String []args) { // Below line of code will create an object car for Car class Car car= new Car( "red" ); } }
Object is created by this line of code in above example:
Car car= new Car( “red” );
Compile and run above code, below output will come:
Passed argument is: red
Advantage of OOPs
Below are few advantages of OOPs:
- OOP is structured and very easy to understand.
- OOP has everything in object of classes and we can relate these classes and their objects to real life objects for example Car, Tree, School etc.
- Reusable components can be easily developed using OOP.
- OOP makes code readable and verbose.
- OOP enables easy maintenance and update of code.
OOPs Concepts
Below are OOPs concepts, in coming articles we will see details of them:
- Inheritance – On class Inherits the properties and attributes of other class.
- Abstraction – Provides abstract details and leaves implantation to another class which uses abstract class.
- Polymorphism – If same thing takes more than one form even though name looks same called polymorphism.
- Encapsulation – Holding attributes and methods within class is called encapsulation.
Once we learn all these OOPs concepts we will try to understand what is association, aggregation(has-a) and composition(is-a), cohesion and coupling.
OOPs Diagram:
References
Oracle has reference article on OOPs: Java OOPs