الأحد، 20 يوليو 2025

Java 8 - How to convert Calendar to LocalDateTime?

1. Overview

In this article, You'll learn how to convert Calendar to LocalDateTime object in java 8 DateTime api

LocalDateTime api can be used completely replacement to the Date class as all features of Date functions are done in a simple and precise way such as adding minutes to the current date.

Java 8 - How to convert Calendar to LocalDateTime?

Ultimate Guide to Java Virtual Threads: Build Scalable Applications with Ease

Are Java Virtual Threads the Future of Concurrency? Absolutely. Here's Why You Should Care.

If you're a Java developer, you already know: every line of code runs on a thread. Threads are the fundamental unit of scheduling and concurrency in any Java application.

Traditionally, developers have relied on multiple OS-level threads to handle concurrent tasks. For example, Spring Boot with embedded Tomcat comes configured with 200 threads by default, allowing it to process up to 200 concurrent requests. Sounds powerful, right?

But here’s the catch...

🧠 Why Traditional Threads Limit Scalability

Each request in a Java web application is processed by a dedicated OS thread. If each request takes 1 second, a 200-thread system can handle 200 requests per second — that’s your application throughput.

So, why not just add more threads?

Because OS threads are heavyweight:

Each thread consumes significant memory.

The OS has limits on how many threads can be created.

Managing thousands of threads leads to context switching overhead, degrading performance.

That’s where Java Virtual Threads come into play — a game-changing concurrency model introduced in Project Loom.

السبت، 19 يوليو 2025

Mastering @JsonFormat in Jackson: A Complete Guide with Examples

If you're working with Java and JSON, the Jackson library is likely part of your tech stack. One of the most powerful yet underused annotations it provides is @JsonFormat.

In this ultimate guide, we’ll break down what @JsonFormat does, when to use it, and how to handle advanced scenarios with fully working examples. This post is optimized for SEO to help developers find quick and accurate answers.


✅ What is @JsonFormat in Jackson?

@JsonFormat is a Jackson annotation that helps control how Java fields are serialized (Java to JSON) or deserialized (JSON to Java). This is especially useful for dates, enums, and number formats.

Import Statement:


import com.fasterxml.jackson.annotation.JsonFormat;

Dependencies

Make sure you include the correct Jackson modules for java.time:


 <dependency>
   <groupId>com.fasterxml.jackson.datatype</groupId>
   <artifactId>jackson-datatype-jsr310</artifactId>
   <version>2.15.3</version>
 </dependency>
 

And register it:


 ObjectMapper mapper = new ObjectMapper();
 mapper.registerModule(new JavaTimeModule());