Where To Use the Underscore in Java

This series of articles called “Stranger things in Java”, is inspired by the contents of my book “Java for Aliens”. These articles are dedicated to insights into the Java language. Deepening the topics we use every day will allow us to master Java coding even in the strangest scenario.

In this article, we will try to clarify the use of the underscore symbol "_" in Java programming. So, let's examine the use cases of this symbol within a Java program. Let's start with the best-known case.

How to Define Constants in Java

There seems to be a lot of confusion around the topic of constants in Java. Some people make use of integers or Strings to define constants, while others make use of enums.

I’ve also come across constants defined in their own interface – where classes that make use of the constants have to implement the interface. This strategy is often referred to as the interface constant design pattern.

Project Valhalla: A First Look at LW2 Inline Types

I summarized some recent Project ValhallaLW2 "inline types" progress that was made public recently in my blog post "Valhalla LW2 Progress - Inline Types." In this post, I illustrate some of the concepts summarized in that post with code examples executed against recently released Valhalla Early Access Build jdk-14-valhalla+1-8 (2019/7/4). All code examples featured in this post are available on GitHub.

The OpenJDK Wiki page "LW2" provides an illustrative example of inline types via source code for a class called "InlineType." My example makes some minor adaptions and additions to this class and is available on GitHub as a class called InlineTypeExample. Some items that stand out immediately when reviewing this source code are the presence of the keyword inline and the presence of the ? in the Comparable's generic parameter.

Optimizing Memory Access With CPU Cache

Nowadays, developers pay less attention to performance because hardware has become cheaper and stronger. If developers understand some basic knowledge about CPU and memory, they can avoid simple mistakes and it is easy to improve the performance of their code.

At the end of this article, I also ask a question that I do not know the answer to, so any suggestions are welcome!