Home » Java » Page 11

Java

From layers to onions and hexagons

java-interview-questions-answers

In this post we will explore the transition from a classic layered software architecture to a hexagonal architecture. The hexagonal architecture (also called ports and adapters architecture) is a design pattern to create loosely coupled application components. This post was inspired by a German article from Silas Graffy called Von Schichten zu Ringen – Hexagonale Architekturen erklärt. Classic layers Layering ...

Read More »

Java’s Optional Does Not Supplant All Traditional if-null-else or if-not-null-else Checks

Java‘s addition of java.util.Optional has been welcome and had led to more fluent code for methods that cannot always return non-null values. Unfortunately, Optional has been abused and one type of abuse has been overuse. I occasionally have run across code that makes use of Optional when there is no clear advantage over using null directly. A red flag that ...

Read More »

Java 17: Pattern Matching for Switch

In Java 17 (released only a few days ago), Pattern Matching for switch has been introduced as a preview language feature, which allows case labels with patterns rather than just constants. Here is an example showing how you can match on type patterns: public static String typedPatternMatching(Object o) { return switch(o) { case null -> "I am null"; case String ...

Read More »

Java 17 the new LTS version is finally here!

Java 17, the new long-term support aka LTS is now available for use and support for many years to come. Let’s remind here that  Non-LTS releases get six months of support from Oracle. You can download it here JDK 17 GA Release (java.net) New Capabilities JDK 17 features everything that has been added since the last LTS release that was ...

Read More »

The Case of the Missing JEPs

The JDK Enhancement-Proposal (JEP) process is “for collecting, reviewing, sorting, and recording the results of proposals for enhancements to the JDK and for related efforts, such as process and infrastructure improvements.” JEP 0 is the “JEP Index” of “all JDK Enhancement Proposals, known as JEPs.” This post provides a brief overview of current JDK Enhancement Proposals and discusses the surprisingly ...

Read More »

Surprisingly High Cost of Java Variables with Capitalized Names

I’ve read hundreds of thousands or perhaps even millions of lines of Java code during my career as I’ve worked with my projects’ baselines; read code from open source libraries I use; and read code examples in blogs, articles, and books. I’ve seen numerous different conventions and styles represented in the wide variety of Java code that I’ve read. However, ...

Read More »

How much faster is Java 17?

Java 17 (released yesterday) comes with many new features and enhancements. However, most of those require code changes to benefit from. Except for performance. Simply switch your JDK installation and you get a free performance boost. But how much? Is it worth it? Let’s find out by comparing the benchmarks of JDK 17, JDK 16 and JDK 11. Benchmark methodology ...

Read More »

KivaKit resources

java-interview-questions-answers

A resource is a stream of data that can be opened, read from or written to, and then closed. KivaKit provides a resource mini-framework that allows easy and consistent access to many types of resources, and it makes it easy to create new resources. Examples of KivaKit resources include: FilesSocketsZip or JAR file entriesS3 objectsPackage resourcesHDFS filesHTTP responsesInput streamsOutput streams ...

Read More »

KivaKit command line parsing

java-interview-questions-answers

The kivakit-commandline module provides the switch and argument parsing used by kivakit-application. Let’s take a look at how this works. When an Application starts up (see KivaKit applications), the Application.run(String[] arguments) method uses the kivakit-commandline module to parse the argument array passed to main(). Conceptually, this code looks like this: public final void run(String[] arguments) { onRunning(); [...] commandLine = ...

Read More »