Saravanan's Corner: Blackberry Dev

Sunday, 13 July 2025

Java 21 Features

 Finalized Features:

  • Virtual Threads (Project Loom):
    Lightweight threads that simplify writing high-throughput, scalable applications by reducing the overhead of creating and managing threads. 
  • Record Patterns:
    Enable pattern matching for record deconstruction, making it easier to extract data from records. 
  • Pattern Matching for Switch:
    Enhances the switch statement, allowing for more complex pattern matching and reducing boilerplate code. 
  • Sequenced Collections:
    Introduces interfaces like SequencedCollectionSequencedSet, and SequencedMap to provide a consistent way to work with ordered collections and access their first and last elements. 
  • Foreign Function & Memory API (Final):
    Provides a stable API for interacting with native code, offering a more efficient and manageable way to integrate with non-Java code. 
  • Generational ZGC:
    Improves garbage collection performance by managing young and old object generations separately within the Z Garbage Co

Saturday, 12 July 2025

Latest version numbers

 Latest version of 

Spring Boot is 3.5.3

Spring Cloud2025.0.0

Stable Spring Framework is 6.2.8

Spring Data JPA3.5.1 

  • Hibernate ORM: 6.6 series is the latest stable, with 6.6.7.Final being a recent release within that series. 
  • Hibernate Validator: 8.0 is the latest stable. 
  • Hibernate Search: 6.0 series is the latest stable.
Apache Kafka is 4.0,
  • ZooKeeper Deprecation: ZooKeeper is deprecated and will be removed in a future version (planned for Apache Kafka 4.0). 
  •  removing ZooKeeper dependency and using KRaft by default for cluster management. 

Java 11 features

 Language Enhancements:

  • var in Lambda Expressions: Java 11 allows the use of var keyword for local variable type inference in lambda expressions, improving readability and consistency. 
Java
    list.forEach((var item) -> System.out.println(item)); // Example
2. New APIs:
  • String::isBlank()Checks if a string is empty or contains only whitespace characters. 
Java
    String str = "   ";    System.out.println(str.isBlank()); // true
  • String::strip()Removes leading and trailing whitespace, handling Unicode characters correctly. 
Java
    String str = "  hello  ";    System.out.println(str.strip()); // "hello"
  • String::lines()Returns a stream of lines from a string. 
  • Files::readString()Reads the entire content of a file into a string. 
  • HttpClientA new, asynchronous, and non-blocking HTTP client API supporting HTTP/1.1 and HTTP/2. 
  • Predicate::not()A static method that negates a predicate. 
Java
    Predicate<String> notEmpty = String::isEmpty;    Predicate<String> notEmptyNegated = Predicate.not(String::isEmpty);

  • New toArray method: A new toArray method in the Collection interface that takes an IntFunction argument for more convenient array creation. 

Design Patterns

 Design patterns - 


1. Creational design pattern : This design patterns defines that how object of classes are created.

1. Singleton design pattern

2. Prototype design pattern

3. Factory design pattern

4. Abstract design pattern

2. Structural design pattern: This design pattern defines that how your different classes are structured and interacted each other. 

1. facade design pattern

2. decorator design pattern (open close principal)


3. Behavior design pattern: This design pattern defines that how your classes communicate each other to have a business logic is running

1. chain of responsibility 

2. observer pattern

3. strategy design pattern (Single responsibility principal) 

4. adaptor design pattern

Strategy design pattern - ex: payment flow, 

client class will try to make payment using credit card or PayPal and in future if we want to add new payment method we can add without changing existing components











Factory design pattern
Decorator design pattern


Friday, 11 July 2025

Java 17 Features

 

☕ Complete List of Features in Java 17 (LTS) ☕ | by Brijesh Srivastava | Medium


Sealed Classes  - This feature provides more control over class hierarchies by restricting which classes can extend or implement a given class or interface
public sealed class Vehicle permits Car, Truck { }
Pattern Matching for switch -  Instanceof Pattern Matching (Finalized from Java 16) 

Java 17 introduces Pattern Matching for switch as a preview feature. This enhancement simplifies the use of switch statements by allowing patterns to be used in case labels. Pattern matching makes code more readable and reduces the need for explicit type casting.

Example:

1
2
3
4
5
6
7
public static String getShapeType(Object shape) {
    return switch (shape) {
        case Circle c -> "Circle with radius " + c.radius();
        case Rectangle r -> "Rectangle with width " + r.width() + " and height " + r.height();
        default -> "Unknown shape";
    };
}

This feature improves code clarity and reduces boilerplate when dealing with complex object hierarchies in switch statements.

Records (Finalized from Java 16) 

Key Features and Characteristics of Java Records:
  • Immutability:
    All components (fields) declared in a record are implicitly final, meaning their values cannot be changed after the record instance is created. This promotes thread-safety and predictable behavior.
  • Concise Syntax:
  • Records automatically generate common methods like the canonical constructor, accessor methods (named after the components), equals(), hashCode(), and toString(). 


 Text Blocks – Multi-line string literals (""")

5. JEP 356: Enhanced Pseudo-Random Number Generators (PRNGs)

Java 17 introduces enhanced pseudo-random number generators (PRNGs), providing a more robust API for generating random numbers. This new API includes support for stream-based APIs and new algorithms like LXM, which offer better statistical properties for certain applications.

Example:

1
2
RandomGenerator random = RandomGenerator.of("L64X128MixRandom");
System.out.println(random.nextInt());

These improvements enhance randomness quality, particularly for applications requiring secure random numbers or better distribution for simulations.

Performance & Memory Improvements - ZGC (Z Garbage Collector) Enhancements — Lower latency, better scalability.


New APIs in Java 17

In addition to these language and performance enhancements, Java 17 introduces several new APIs to make development easier and more powerful:

  • Foreign Function & Memory API: An API for working with native memory and calling native code outside the JVM.
  • Vector API: A new API for vector computation, offering better performance for certain workloads.
  • Enhanced JDK Flight Recorder: Expanded support for monitoring and troubleshooting applications at runtime.