Posts

Showing posts from February, 2024

The Power of Encapsulation and Role of Getter and Setter Methods

Image
                                      ENCAPSULATION   Encapsulation in Java is one of the four fundamental Object-Oriented Programming (OOP) concepts. Encapsulation helps in hiding the internal state of an object from the outside world and only exposing the necessary functionalities or methods to interact with that state. This concept is implemented through access modifiers such as public, private, and protected in Java. Encapsulation is used for variables. Example:- Advantages of Encapsulation๐Ÿ‘‡ Getters & Setters  Getter and setter methods in Java are used to access and modify the private variables (fields) of a class. They are also known as accessor and mutator methods.  Example:- ๐Ÿ“Œ Before java 8 we can use with direct private variable but after we can use with set method. Uses of   ๐Ÿ…ถ ๐Ÿ…ด ๐Ÿ†ƒ ๐Ÿ†ƒ ๐Ÿ…ด ๐Ÿ† ๐Ÿ†‚ and ๐Ÿ†‚ ๐Ÿ…ด ๐Ÿ†ƒ ๐Ÿ†ƒ ๐Ÿ…ด ๐Ÿ† ๐Ÿ†‚ Method๐Ÿ“ ☝Allow you to control...

The power of interfaces in Java

Image
  INTERFACE The interface keyword can be called as a keyword that can generate a class in java. An interface is like a blueprint for a behavior. It is used to specify a set of methods that a class must implement. Multiple inheritance cannot be done from extends (classes from classes), but multiple inheritance can be done from implements (classes from interfaces). Interfaces are provides a way to achieve abstraction  and multiple  inheritance in Java. Difference between Class and Interface Difference between Extends and Implements Example:- You can't create an object for an interface, also you can't create a constructor. ❌ But you can create object by upcasting, the side where the object is generated must be a class. Since an interface cannot be run, there is no use in having a method.  However, since methods can be overridden, meaningless methods can be created in the interface. After Java 8, you can keep the normal method, so the method does not have to be meani...

Abstract Thinking: Unlocking Efficiency and Clarity in Code

Image
  ABSTRACTION In Java, abstraction is a powerful concept that allows us to manage complexity by focusing on essential details while hiding unnecessary intricacies. Modifying a class or method with the keyword abstract can be simply called abstraction. Example:- ๐Ÿ‘‡Abstract method can be kept only inside an abstract class. ๐Ÿ‘‰You can use the abstract class as a super class reference after Upcasting . ๐Ÿ‘‡ ๐Ÿ’You can run the method of the abstract class through the super keyword. Super.calculate(); ๐Ÿ’And also you can run the method of the abstract class as,   Cal.Calculate(); ๐Ÿ’ An object cannot be created from an abstract class.   So abstract class cannot have constructor.                                  ❌ But after java 8 abstract classes cannot create object but they are given the opportunity to get a constructor. Advantages of abstraction๐Ÿ“

The Art of Polymorphism in Java

Image
  Polymorphism  The word polymorphism when taken separately as “ Poly ” and “ morphs ” means many and forms. Simply polymorphism means many forms. In Java Polymorphism is the ability of objects to take different forms depending on the specific types or context in which they are used.   This can simply be called the ability of an object to take multiple forms. Super level inheritance is used for polymorphism. Example-: Types of Polymorphism Polymorphism in Java can be categorized into two types. Compile-time Polymorphism & Runtime Polymorphism Compile- time Polymorphism also known as method overloading . Runtime Polymorphism also known as method overriding . You can get a better understanding of method overloading and method overriding click the link below and read my blog post .                   ๐Ÿ‘‰ Method Overloading and Method overriding ๐Ÿ‘ˆ Difference Between Compile-time Polymorphism & Runtime Polymorphism ...