MJ #23: Enums!

In Java, an enum, short for "enumeration," is a special data type that represents a fixed set of constant values. It's a way to define a collection of named values, which can make your code more readable and maintainable. Enums are often used when you have a set of values that are related and known … Continue reading MJ #23: Enums!

MJ #22: Need of Inheritence

In Java, interfaces serve as a fundamental concept in object-oriented programming, and they are used to define a contract or a set of rules that a class must adhere to. Here are several key reasons for using interfaces in Java: Abstraction: Interfaces allow you to create a level of abstraction in your code. They define … Continue reading MJ #22: Need of Inheritence

MJ #21: Inheritence simplified

Inheritance is one of the fundamental concepts in object-oriented programming (OOP), allowing you to create a new class (derived or child class) that inherits properties and behaviors (attributes and methods) from an existing class (base or parent class). This promotes code reuse and the creation of a hierarchical structure of classes. Here's a simple Java … Continue reading MJ #21: Inheritence simplified

MJ #18: Working with constructors in Java

Constructors in Java are special methods within a class that are used to initialize objects. They have several important purposes and usages: Object Initialization: The primary purpose of constructors is to initialize objects when they are created. When you create a new instance of a class using the new keyword, a constructor is called to … Continue reading MJ #18: Working with constructors in Java

MJ #17: Usage of “this” keyword

In Java, the "this" keyword is used to refer to the current instance of the class. It can be particularly helpful when there is a need to disambiguate between instance variables and parameters with the same name. Here's an example to illustrate the usage of the "this" keyword: package com.sarthak.concept.thisKeyword; public class Person { //declaring … Continue reading MJ #17: Usage of “this” keyword

MJ #16: Understanding Encapsulation with Example

Encapsulation is one of the fundamental principles of object-oriented programming (OOP) and is a key concept in Java. It refers to the bundling of data (attributes or fields) and methods (functions or procedures) that operate on that data into a single unit called a class. This unit hides the internal details of how the data … Continue reading MJ #16: Understanding Encapsulation with Example

MJ #14: String, String buffer and String Builder classes in Java

In Java, the String, StringBuffer, and StringBuilder classes are used to work with strings, but they have different characteristics and are suitable for different scenarios. Here's an overview of each of these classes: String Class: String is an immutable class in Java. This means that once you create a String object, its content cannot be … Continue reading MJ #14: String, String buffer and String Builder classes in Java