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!
Month: October 2023
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 #20: Anonymous Object in Java
In Java, an anonymous object refers to an object that is created without explicitly assigning it to a variable. Instead, it is used for a single, immediate purpose and is not stored in a named reference variable. Anonymous objects are typically used when you need an object to perform a specific action or method call, … Continue reading MJ #20: Anonymous Object in Java
MJ #19: “super” keyword in Java
In Java, the super keyword is used to refer to the superclass or parent class of the current object. It can be used in several contexts to access superclass members, constructors, and methods. Here are some common usages of the super keyword: Accessing Superclass Members: You can use super to access members (fields or methods) … Continue reading MJ #19: “super” keyword in Java
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 #15: “static” in Java
In Java, the static keyword is used to create class-level members that are associated with the class itself rather than with specific instances of the class (objects). When a member (variable or method) is declared as static, it means there is only one instance of that member for the entire class, regardless of how many … Continue reading MJ #15: “static” in Java
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
MJ #13: Understanding and using array of objects in Java
In Java, an array of objects is an array that holds references to objects of a particular class. This means that each element of the array is not an object itself but rather a reference to an object of the specified class. Here, we will explain in detail how to create and work with arrays … Continue reading MJ #13: Understanding and using array of objects in Java