sebastiandaschner news

saturday, december 23, 2017

Hello from Java, Indonesia! No, really :-)

I’m writing this while sitting in a coffee shop in Surabaya. In the last days I took some time off to visit Bali and the island of Java for the first time. Besides technology, I can definitely recommend Java as a travel destination, as well. It comprises stunning tropical landscapes, vulcanos, waterfalls, good coffee and more-than-friendly people. On Twitter I challenged every Java Champion to visit Java at least once.

The days in December have been relatively quiet. I gave my last conference presentation of 2017 at the IT-Tage conference in Frankfurt. Besides that I was recording new video courses that will be available soon and was making new plans for the next year.


What’s new


Using EnumMaps for mappings with enum keys

Here’s a type that has been around in the JDK for a while and can come in handy when we want to define maps with enum types as keys. An EnumMap is a such as specialized Map.

We’ll create a map for a given enum:

public enum CoffeeType {

The EnumMap needs to be aware of the enum class at creation time:

Map<CoffeeType, String> favoriteCoffeeOrigins = new EnumMap<>(CoffeeType.class);

favoriteCoffeeOrigins.put(CoffeeType.ESPRESSO, "Ethiopia");
favoriteCoffeeOrigins.put(CoffeeType.POUR_OVER, "Colombia");
favoriteCoffeeOrigins.put(CoffeeType.FRENCH_PRESS, "Indonesia");


An EnumMap is much more efficient compared to a HashMap implementation. All basic map operations of this Java implementation are executed in constant time.


Forward local ports to Kubernetes pods

The kubectl port-forward command is a very helpful tool for troubleshooting applications that run in containers orchestrated by Kubernetes. We can forward a local port directly to a specific pod — regardless of the number of replicas, state of services or ingresses:

kubectl port-forward hello-cloud-XYZ-123 8080:8080

This will forward all connections to localhost:8080 to the pod hello-cloud-XYZ-123 on port 8080. Additionally, a namespace other than default can be selected via the option --namespace.


Thanks a lot for reading, Happy Holidays and see you in 2018!


Did you like the content? You can subscribe to the newsletter for free:

All opinions are my own and do not reflect those of my employer or colleagues.