Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

Why Was the Date and Time API Introduced in Java 8?

Java 8 introduced the Date and Time API (java.time package) to address several issues with the older java.util.Date and java.util.Calendar classes. The new API makes date and time handling more robust, intuitive, and developer-friendly. Below is an explanation of why the new API was needed and the benefits it provides. Problems with java.util.Date and java.util.Calendar Java 8 Date and Time API (java.time): To address these shortcomings, Java 8 introduced a…

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

What is Stream in Java?

Java Streams, introduced in Java 8, provide a powerful way to process collections of data in a functional style. They allow operations such as filtering, mapping, and reducing, with the ability to execute these operations sequentially or in parallel. What is a Stream? A Stream is a sequence of elements from a source that supports aggregate operations. Streams are not data structures; they work on the data from collections, arrays,…

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

What is Lamda in java?

Lambda expressions were introduced in Java 8 as a core part of its functional programming features. They enable developers to write more concise, readable, and functional-style code by simplifying how we define and pass behavior. What is a Lambda Expression? A lambda expression is an anonymous function (a function without a name) that has: Syntax: Examples: Components of a Lambda Expression Functional Interfaces Lambda expressions work only with functional interfaces…

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

Java 8 features

Each feature introduced in Java 8 significantly improved productivity, performance, and ease of programming, making it a revolutionary release in the Java ecosystem.

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

Java 11 features

Java 11, released in September 2018, is a Long-Term Support (LTS) release, building on Java 10’s features while introducing several improvements and new functionalities. This guide details all the features, their importance, examples, and use cases. 1. Local-Variable Syntax for Lambda Parameters What Is It? Java 11 allows the use of var in lambda parameter lists, aligning it with local variable declarations. Why Was It Introduced? Example Without var: (x,…

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

Java 17 features

Java 17, released in September 2021, is a Long-Term Support (LTS) version, bringing stability, performance, and several key language and library enhancements. This guide provides a detailed explanation of all the new features, their significance, and examples. 1. Sealed Classes What Are Sealed Classes? Sealed classes restrict which other classes or interfaces can extend or implement them. This ensures controlled inheritance and provides more predictable class hierarchies. Why Was It…

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

Pass by Value vs Pass by Reference in Java

1. Pass by Value Example (Pass by Value for Primitives): public class PassByValueExample { public static void main(String[] args) { int num = 10; modifyValue(num); System.out.println(“Original value: ” + num); // Output: 10 } static void modifyValue(int value) { value = 20; // Changes local copy only }} Original value: 10 Explanation: Example (Pass by Value for Objects): class Person { String name;}public class PassByValueObjects { public static void main(String[]…

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

Heap Memory vs Stack Memory in Java

In Java, memory is divided into two main areas: Heap Memory and Stack Memory. Understanding their characteristics is crucial for efficient memory management. 1. Heap Memory Characteristics: 2. Stack Memory Characteristics: Heap vs Stack Memory Feature Heap Memory Stack Memory Stores Objects and class-level variables Method-level variables, references Lifetime Until no references exist (Garbage Collector) Until method execution completes Access Speed Slower Faster Size Larger Smaller Thread Access Shared across…

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

Inheritance Scenarios in Java

In Java, when parent and child classes are assigned to each other, the behavior of which method is called depends on the type of reference and the object it points to. This behavior is governed by polymorphism and method overriding rules. Below are the different scenarios with examples and explanations: Scenario 1: Parent reference, Parent object class Parent { void display() { System.out.println(“Parent’s display method”); }}public class Main { public…

Posted on: January 18, 2025 Posted by: rahulgite Comments: 0

How to create threads in java?

In Java, there are several ways to create and manage threads. Here’s an overview of the primary methods: 1. Extending the Thread Class class MyThread extends Thread { @Override public void run() { System.out.println(“Thread is running…”); }}public class Main { public static void main(String[] args) { MyThread thread = new MyThread(); thread.start(); // Start the thread }} 2. Implementing the Runnable Interface class MyRunnable implements Runnable { @Override public void…