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();...

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...