Mar Java Mit Java Blog

Vector vs. Collections.synchronizedList(): Understanding the Differences

In Java, developers often need thread-safe data structures to handle concurrent access. Historically, Vector was the go-to synchronized collection, but modern Java provides Collections.synchronizedList(new ArrayList<>()) as an alternative. While both provide thread safety, they...

Understanding AccessController.doPrivileged() in Java 8, 17, and 21

Introduction In Java, security and permission management have been crucial components for building secure applications. One such API that developers have relied on for decades is the AccessController.doPrivileged() method. However, with the evolution of...

Java code to bytecode to constant pool hashes

From Java Code → Bytecode → Constant Pool Hashes Code Example 🎯 Let’s take the simplest code: Java Code public class Demo { public static void main(String[] args) { Demo d = new Demo();...

Length-Prefixed Strings in Protocol Buffers — Deep Dive

Length-prefixed strings are one of the key reasons why Protocol Buffers (ProtoBuf) are smaller and faster than JSON or XML. In JSON or XML, strings are wrapped in quotes and require closing tags or...

How gRPC handles backward compatibility with proto files

The most important point about gRPC. Both Server and Client MUST have the proto file — or at least the generated classes from the proto file. Why is this necessary? Because gRPC doesn’t send...

Is Protobuf efficient for smaller keys

You’re absolutely right to think that if keys are small and values are long, Protobuf’s advantage becomes less obvious — but it still helps in most cases. Let’s break it down 🔍: Scenario Imagine...

How Protobuf Stores Data in Binary Format

Unlike JSON, Protocol Buffers (Protobuf) use a compact binary format that removes redundant information. Here’s how data is structured and stored efficiently. 1️⃣ Protobuf Message Structure Let’s take a JSON-like structure: In Protobuf, we...

Java Example: Using Protocol Buffers

This example shows how to define, compile, serialize, and deserialize a Protocol Buffers (Protobuf) message in Java. 📌 Step 1: Define the Protobuf Schema Create a file named person.proto: Explanation: 📌 Step 2: Compile...

What kind of code is removed in GraalVM

In GraalVM Native Image mode, the compiler removes unused code to reduce binary size. This means if a class, method, or field is:❌ Not directly used anywhere in the code AND❌ Not explicitly registered...

Why Doesn’t Reflection Work in GraalVM’s Native Image?

1. How Reflection Works in Traditional JVMs In a traditional JVM, reflection allows the application to:✅ Discover and inspect classes, methods, and fields at runtime✅ Dynamically instantiate objects and invoke methods✅ Access private members...