- OOP stands for Object Oriented programming
- Before OOPs there were procedural programming where it was all about the functions and variables written into a single file. Where variables stored data and functions performed operations on that data.
- After oops concept came up we divided the functions and variables into logical groups called class and started calling functions and variables as methods and properties respectively.
4 pillers of OOPs
- Encapsulation is the idea of bundling data and methods that work on that data within one unit. Eg class in java
- Note : Lesser that number of arguments to the methods, better the code.
” The best functions are those with no parameters!” – Robert C Martin
- Looking at something without being concerned about the inner details or mechanics.
- Example : While Driving a car, person need not be concerned about what happens internally when you press a accelerator or a break but what he needs to know is which function to call to actually perform those operations.
- Inheritance is a mechanism in which one class acquires the property of another class.
- For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class.
- Hence, inheritance facilitates Reusability and is an important concept of OOPs
Polymorphism (Many forms)
- Polymorphism refers to a programming language’s ability to process objects differently depending on their data type or class.
- Polymorphism allows you to define one interface and have multiple implementations
- There are two types of polymorphism in java
- Compile time polymorphism
- Run time polymorphism
Others Benefits of java : Robust
- One of the major advantages of Java over C++ is that it prevents memory leaks.
- Java manages memory on its own and does garbage collection automatically.
- Bad memory management in C++ is a big source of errors in programs.
Others Benefits of java : Secure
- Java code runs inside the JVM.
- This creates a sandbox that makes it hard for Java code to do evil things to the computer it is running on.