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: costanti

Stranger things in Java: costanti

In questo articolo, esploreremo alcune situazioni che coinvolgono l'utilizzo delle costanti in cui anche programmatori esperti potrebbero avere dei dubbi. Per quanto l'argomento possa essere considerato ben noto ai più, non tutti hanno esplorato alcuni scenari particolari come quello in cui l'ereditarietà multipla coinvolge costanti omonime. Rinforzare la propria base teorica è fondamentale per poter programmare con sicurezza.

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.

Stranger things in Java: il modificatore protected

Stranger things in Java: il modificatore protected

Il modificatore protected è un specificatore d'accesso utilizzato alquanto raramente, applicabile a variabili, metodi e costruttori, ma non a tipi Java (classi, interfacce, enumerazioni, annotazioni e record), a meno che essi non siano innestati in altri tipi. In questo articolo eviteremo di parlare dei tipi innestati e ci limiteremo a parlare di tale modificatore riferendoci soprattutto ai membri (variabili e metodi) delle classi per semplificare il discorso. In particolare faremo alcune osservazioni importanti riguardo tale modificatore, che è spesso usato senza la necessaria consapevolezza. Inoltre faremo una digressione anche sul pattern Singleton per aggiungere ad esso l'estensibilità.

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.

Superare Java 8: Text Block

Superare Java 8: Text Block

Con Java 13 è stata introdotta una nuova caratteristica chiamata text block, che permette di utilizzare la classe String in maniera più proficua e più semplice. Tale caratteristica permette alle stringhe di essere definite su più linee utilizzando una nuova sintassi. La formattazione delle stringhe multilinea è più naturale rispetto al passato: non sarà più necessario ricorrere continuamente a concatenazioni di stringhe, a caratteri di escape come \n, e ad una complessa gestione delle virgolette e delle spaziature. In questo modo la verbosità del codice diminuisce, ed è favorita la leggibilità e la facilità di scrittura. In Java 13 e Java 14, i text block potevano essere utilizzati come feature preview. A partire da Java 15 sono diventati a tutti gli effetti una caratteristica standard del linguaggio.

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.

Superare Java 8: Pattern matching per instanceof

Superare Java 8: Pattern matching per instanceof

In questo articolo vedremo una interessante novità introdotta nella versione 14 come caratteristica in anteprima (o feature preview, vedi relativo articolo). Si tratta della prima parte di una articolata caratteristica nota come pattern matching (che potremmo tradurre come corrispondenza di modello). Il pattern matching toccherà vari costrutti di programmazione in futuro, per ora è disponibile in anteprima solo il pattern matching che riguarda l'operatore instanceof. Questo cambierà radicalmente il modo in cui utilizziamo tale operatore.

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.

Superare Java 8: Caratteristiche in anteprima (Feature preview)

Superare Java 8: Caratteristiche in anteprima (Feature preview)

In questo articolo, vedremo alcune situazioni in cui l'utilizzo di un concetto che è alla base della programmazione Java come il costruttore, può nascondere alcune insidie. In particolare, dopo aver chiarito alcune definizioni fondamentali, esploreremo i rapporti tra i costruttori e l'ereditarietà, i costruttori e il polimorfismo, ed il lavoro del compilatore.

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.

Superare Java 8: Deduzione del tipo per le variabili locali (var)

Superare Java 8: Deduzione del tipo per le variabili locali (var)

In questo articolo parleremo della più importante novità introdotta con Java 10. Ufficialmente chiamata deduzione del tipo per le variabili locali (in inglese local variable type inference), questa caratteristica è meglio nota come introduzione della parola var. A dispetto del nome complicato, in realtà si tratta di una caratteristica piuttosto semplice da utilizzare. Tuttavia bisogna fare diverse osservazioni per vedere l'impatto che ha l'introduzione della parola var su altre caratteristiche preesistenti.

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.

Superare Java 8: Compact Strings

Superare Java 8: Compact Strings

Secondo alcuni sondaggi come quello di JetBrains, la versione 8 di Java è al momento quella più utilizzata in assoluto dagli sviluppatori di tutto il mondo, nonostante si tratti di una release del 2014.
Quello che state leggendo è il primo di una serie di articoli intitolata "Superare Java 8", ispirata ai contenuti del mio ultimo libro "Il nuovo Java". Questi articoli accompagneranno passo dopo passo il lettore all'esplorazione delle più importanti caratteristiche introdotte a partire dalla versione 9. L'obiettivo è quello di far acquisire la consapevolezza di quanto è importante aggiornare le proprie conoscenze relative a Java, spiegando gli enormi vantaggi che offrono le ultime versioni del linguaggio.
In questo articolo parleremo di compact strings, una meccanismo introdotto con Java 9, che rappresenta uno dei più validi motivi per abbandonare Java 8 ed aggiornarsi ad una delle versioni più recenti.