Stranger Things in Java: Constants

Stranger Things in Java: Constants

In this article, we will explore some scenarios involving the use of constants where even experienced programmers may have doubts. Although the topic may be well known, not everyone has explored particular scenarios such as solving multiple inheritance in presence of homonymous constants. Strengthening one's theoretical basis is essential to be able to program with confidence.

Stranger Things in Java: the protected Modifier

Stranger Things in Java: the protected Modifier

The protected modifier is a rarely-used access specifier. It is applicable to variables, methods and constructors, but not to Java types (classes, interfaces, enumerations, annotations and records), unless they are nested in other types. In this post, we will avoid talking about nested types and we will focus on this modifier referring mainly to class members (variables and methods) to make the discussion simpler. In particular, we will make some important observations regarding protected, which is often used without the necessary awareness. In addition, we will also digress on the Singleton pattern to add extensibility to it.

Going beyond 8: Text Block

Going beyond: Text Block

With Java 13, a new feature called text blocks has been introduced that allows us to use the String class in a more profitable and easier way. This feature allows strings to be defined on multiple lines using a new syntax. The formatting of multiline strings is more natural than in the past: it will no longer be necessary to use string concatenations, escape characters such as \n, and complex management of quotes and spaces. In this way the verbosity of the code decreases, and readability and ease of writing is improved. In Java 13 and Java 14, text blocks could be used as feature preview . Starting with Java 15 they have become a standard feature of the language.

Going beyond Java 8: Pattern matching per instanceof

Going beyond Java 8: Pattern matching for instanceof

In this article we will see an interesting novelty introduced in version 14 as a preview feature. This is the first part of a complex feature known as pattern matching. It will affect various programming constructs in the future, but for now only the pattern matching concerning the instanceof operator is available as a feature preview. This will radically change the way we use this operator.

Going beyond Java 8: Feature Preview

Going beyond Java 8: Feature Preview

Oracle is making several improvements to Java programming by accelerating the language development process with the six-months release model. From version 12, with switch expressions and text blocks, a new type of approach has been introduced for the launch of new features, using the so-called feature preview process. In practice, a new feature is introduced in order to be usable as a preview for experimental purposes. In this way, developers can test it, give feedback to Oracle, which in turn can improve it in future versions.

Going beyond Java 8: Local Variable Type Inference (var)

Going beyond Java 8: Local Variable Type Inference (var)

In this article we will talk about the most important new feature introduced with Java 10. Officially called local variable type inference, this feature is better known as the introduction of the word var. Despite the complicated name, it is actually quite a simple feature to use. However, several observations need to be made to see the impact that the introduction of the word var has on other pre-existing characteristics.

Going beyond Java 8: Compact Strings

Going beyond Java 8: Compact Strings

According to some surveys such as that of JetBrains, version 8 of Java is currently the most used by developers all over the world, despite being a 2014 release.
What you are reading is the first in a series of articles titled "Going beyond Java 8", inspired by the contents of my book "Java for Aliens". These articles will guide the reader step by step to explore the most important features introduced starting from version 9. The aim is to make the reader aware of how important it is to move forward from Java 8, explaining the enormous advantages that the latest versions of the language offer.
In this article we will talk about compact strings, a mechanism introduced with Java 9, which represents one of the most valid reasons to abandon Java 8 and upgrade to one of the most recent versions.