- Immutable Objects Using Record in Java
It is often useful to have objects that, once created, don't change their content. To see a complete description on how to build such class, you can read my previous article "Immutable Objects in Java".
Let’s imagine we want to build a PersonClass
with two fields: firstName
and lastName
. To create immutable instances, this class must:
- Smart-Doc: Generating gRPC API Documentation in Java Projects
Foreword
In modern Java microservices, gRPC simplifies inter-service communication with its efficient binary protocol and multi-language support. However, maintaining gRPC API documentation can be challenging as projects grow. Among various AI tools, smart-doc stands out as the optimal solution for generating gRPC API documentation in Java projects.
Advantages of Smart-Doc in Java Projects
1. Fast Speed
Smart-doc is designed to quickly scan code and generate documentation without additional runtime dependencies. It directly extracts .proto
files, compiles them into Java code using protoc
, and then generates documentation by parsing the Java code and comments. This process is much faster than AI tools.
- Undocumented Java 16 Feature: The End-of-File Comment
While working on some code where I wanted to obscure parts of it using Unicode escapes instead of the actual source, I accidentally stumbled upon an undocumented feature that’s been around since Java 16: what I call the end-of-file comment.
In Java, we typically have three types of comments:
- Lock-Free Programming: From Primitives to Working Structures
Working with multiple threads is one of the most complex problems we may encounter in our daily work. When put against the wall of multithreading, most people right away reach out for blocking approaches. In Java, it takes the form of the synchronized keyword, or some other less painful mechanisms, like ReentrantLock. Locks are not the only option: Lock-free programming is also the way.
In this text, I will show problems, techniques, and best practices related to Lock-Free Programming. I will also provide a real-life example of how to implement a Lock-Free stack. Besides, I will share common patterns on moving from Lock-Free to Wait-Free.
- 1-Line IO in Java
Here is a quick coding challenge for all Java developers: How many lines of code do you need to implement the following tasks, using the JDK and any library of your choice?
(Rules of the game: Lines of code are counted using standard formatting, you need to close any opened resources, the code may throw IOExceptions, except if stated otherwise):