-
How to Implement Singleton Design Pattern in Java (Step-by-Step)
What is singleton design pattern A Singleton Pattern says that just “define a class that has only one instance and provides a global point of access to it . If singleton class is loaded by two classloaders, two instance of singleton class will be created, one for each classloaders. Key Concepts 1. Significance of Serialization in Singleton Pattern Serialization in Java means converting an object into a byte stream so it can be: Deserialization is the reverse process (byte stream → object). Even if your class ensures only one instance, deserialization creates a NEW object, which violates the Singleton rule. Example: Singleton Class (Without Protection) 2.TestSingleton.java output false // false…
-
How Data Structures Make Your Code Faster
Before the concept of data structures, data was often managed using simple linear storage methods. What is Data Structure . A Data structure is specialized format for organizing , processing , retrieving and storing data . it defines the relationship between data and the operations. that can be performed of the data common data structures include arrays , linked lists ,stacks , queues , tree and graph . Benefits of data structures How the variable can store this line when compiler compiles this line . When jvm reads int a it reserve space in stack memory for variable a . When jvm executes a=10; Primitive data type memory allocation Example…
-
Function Functional Interface in Java 8 – Definition, Syntax & Real-World Use Cases
The Function functional interface is a predefined interface introduced in Java 8 as part of the java.util.function package. It represents a function that accepts one input argument and produces one result. This interface is widely used in lambda expressions, Stream API operations, and functional programming. A key feature of the Function interface is that it enables developers to define reusable transformation logic, where an input object is converted into another form. For example, converting a String into its length, a Student object into a grade, or an entity into a DTO. Function is functional interface that takes one argument and produces a result . Syntax: Program1 : Write a program…