What are the changes in Java 13?

Hier gibt es diesen Artikel auf Deutsch

As the relase cycle of Java has changed we can now be excited for a new Java Release every half a year. So in September 2019 Java 13 will already come out. But don’t worry: Java developers do not need to be stressed: Today many years still use Java 8 *cough cough* uhm I mean Java 11 and the next LTS = Long Term Support-Version will be Java 17 in 2021.

So we will get two new versions of Java each year but at the same time they are mostly small releases with only a few additions. And some of the innovations are marked as preview, so you can still expect changes there after the community has been able to give feedback.

Enough talk, what are the new changes?

The following so called JPE’s = Java Enhancement Proposals are going to be relased with 13:

  • Switch Expressions (preview)
  • Text Blocks (preview)
  • Z Garbage Collector: Uncommit Unused Memory
  • Dynamic CDS Archives
  • Reimplementation of the Legacy Socket API

The first two points are especially interesting for developers. That’s why I wrote a whole chapter about those.

The ZGC = Z Gargabe Collector is a new… uhm, well a new Garbage Collector, as the name implies 🙂 It promises to clean big chunks of data on the heap very quickyl. Not only that but it will also free this space if it’s not being used anymore, something that apparently has not been done yet by the old garbage collector and some applications have used a lot of memory unnecessarily after a long time running.

Dynamics CDS Archives are an extension to the with Java 5 introduced CDS = Class Data Sharing. In CDS some specific information about application is stored in CDS archives to reduce the start time of applications. Until Java 10 only the Bootstrap Class Loader was able to use those archives. With Java 10 the AppCDS = Application Class Data Sharing has been published and now also other class loaders have access to those archives. To create those archives the application needed to be run in trial runs to figure out what classes could actually be loaded in an effective way. Now with Dynamics CDS these trial runs are not needed anymore.

And there is also a new implementation of the Socket API that still comes from JDK 1. NioSocketImplementation replaces the old PlainSocketImplementation. As the name suggests it’s derived from the New I/O-Implementation.
You can find more information for example here: https://docs.oracle.com/javase/8/docs/technotes/guides/io/index.html

How do I activate preview changes?

Preview means that there might still be changes in the future for those enhancements. To enable these preview features in Java 13 you need to add a flag to the compilation of your program:

javac --release 13 --enable-preview MyClass.java

You also need to add this flag when you start your application:

java --enable-preview MyClass

If you are using Maven you need to add the flag in the pom.xml to the maven-compiler-plugin part.


What are Switch Expressions?

Switch Expressions have the difference to the traditional Switch-Case statement so that you can directly return the values (and I actually mean the „return“ statement).

Note the new keyword yield instead of break.

Switch-Case example:

String name = "";
 switch(personalId) {
     case 1:
     case 2:
         name = "Fritz";
     case 3:
         name = "Hanswurst";
 return name;

Example with Switch Expression:

return switch(personalId) {
     case 1, 2: yield "Fritz";
     case 3: yield "Hanswurst";
     default: yield "Defaultname";

Since Java 12 you can also use the arrows to make the statement even simpler:

return switch(personalId) {
     case 1, 2 -> "Fritz";
     case 3 -> "Hanswurst";
     default -> "Defaultname";

To be honest I myself barely use the Switch-Case statement. But from now on with the new Switch Expressions I will do everything in Switch statements, I promise!

What are Text Blocks?

Text Blocks simplify the usage of strings so that you can define a string in multiple lines without having these annoying + and „\n“ signs (for page break). For example you could do it to an SQL statement to make it more readable. This is already possible in various other programming languages like Groovy, Scala, Kotlin, C#, Swift or Python.

To create a Block simply use three quotation marks. Important: The opening quotation marks need to be in their own line!

So it was like this:

String meineSeite = "<html>n" + 
                    "<body>n" + 
	            "<p>Meine super Seite!</p>n" + 
		    "</body>n" + 

And now with text blocks – A wonderful new change! The world will never be the same! People will go out dancing in the streets! There will be festivals all dedicated to the Java god! So cherish this holy gift that we have received in the form of Text Blocks!

String meineSeite = """
		        <p>Meine super Seite!</p>

Cool, right? 🙂


How to create an icon in an Angular project using FontAwesome

So I just learned that if you want to insert an icon into a frontend website you don’t use images anymore but you use the icon like it was a font – For example by using the FontAwesome library.

Boostrap 4 does not support Glyphicons anymore, you can use Font Awesome instead. But if you just follow the FontAwesome instructions you will fail in an Angular project.

Instead check the hint on this page:

Font Awesome now has an official Angular component that’s available for all who want to easily use our icons in projects. If you are using Angular, you need the angular-fontawesome package or Web Fonts with CSS.

Okay this means in an Angular project you need to use the following packageAngular FontAwesome

The best page that I have found for me as I am using NPM was this page.

So basically you need to:

  1. Install FontAwesome in NPM
  2. Import the module AngularFontAwesomeModule in your app.module.ts
  3. Add the CSS in the angular-cli.json file

The details are all described in the link above.

Power Off Icon
  1. To finally add an icon you can add a power-off icon in the app.component.html file:
<fa-icon [icon]="faPowerOff"&gt;</fa-icon&gt;
  1. AND you need to add the code in the related app.component.ts file:
    import { faPowerOff } from '@fortawesome/free-solid-svg-icons';
    export class AppComponent implements OnInit {
      faPowerOff = faPowerOff;


Please realize you need to install the correct version of AngularFontawesome in NPM for your Angular version. Check this page for the compatibility table.

I used Angular 5 so I had to install it like this:

npm install @fortawesome/angular-fontawesome@0.1.1

The entry will then be added to your package.json file.