Java 9: Enhancements to Optional

Previously, I wrote about the Optional class that was introduced in Java 8 to model potentially absent values and reduce the number of places where a NullPointerException could be thrown. Java 9 adds three new methods to Optional: 1. ifPresentOrElse The new ifPresentOrElse method allows you to perform one action if the Optional is present and a different action if ...

Read More »

Java 9: Enhancements to the Stream API

Java 9 adds 4 new methods to the Stream interface: 1. dropWhile The dropWhile method is similar to the skip method but uses a Predicate instead of a fixed integer value. It drops elements from the input stream while the Predicate is true. All remaining elements are then passed to the output stream. For example: IntStream.range(0, 10) .dropWhile(i -> i ...

Read More »

Java 9: JShell

JShell is a new tool introduced in Java 9 that evaluates Java statements entered on the command line. It is the first offical REPL (Read-Evaluate-Print Loop) implementation for the Java platform, and it is great for trying out Java code without having to fire up an IDE or write a full program! To run JShell, simply type jshell on the ...

Read More »

Caching method results with JCache

java-interview-questions-answers

In JCache there is a handy functionality that transparently caches the result of methods. You can annotate methods of managed beans with @CacheResult and the result of the first call will be returned again without calling the actual method a second time. import javax.cache.annotation.CacheResult; // ... public class Calculator { @CacheResult public String calculate() { // do some heavy lifting... ...

Read More »

Emerging role of PaaS (Platform as a service) in building cloud-native applications

Challenges & opportunities for cloud-native applications Current technology landscape for cloud-native apps is evolving and Platform-as-a-Service (PaaS) solutions are constantly changing to meet the demands such architecture. As customers need flexibility and openness in terms of choosing PaaS solution (without any vendor or technology lock-in), a key need is to provide a neutral view in terms of: Which PaaS solution ...

Read More »

Kotlin – Try type for functional exception handling

Scala has a Try type to functionally handle exceptions. I could get my head around using this type using the excellent Neophyte’s guide to Scala by Daniel Westheide. This post will replicate this type using Kotlin. Background Consider a simple function which takes two String, converts them to integer and then divides them(sample based on scaladoc of Try) : fun ...

Read More »

Choosing Java Cryptographic Algorithms Part 1 – Hashing

Abstract This is the 1st of a three-part blog series covering Java cryptographic algorithms. The series covers how to implement the following: Hashing with SHA–512 Single-key symmetric encryption with AES–256 Public/Private key asymmetric encryption with RSA–4096 This 1st post details how to implement SHA–512 hashing. Let’s get started. Disclaimer This post is solely informative. Critically think before using any information ...

Read More »

Fatjars, Thinwars and why OpenLiberty is cool

java-interview-questions-answers

Fatjars Building a Fatjar (or Uberjar) that contains everything you need to run your application nicely packaged together means you can just do: java -jar myapp.jar and off you go. No Application server. No classpath. This approach has been popularised by the microservices architectural style and frameworks like Springboot. “In short, the microservice architectural style is an approach to developing ...

Read More »

Getting to Working Software: Code Reviews – Benefits

Last time we talked about the different mechanisms and practices we put in place in order to get us to working software, the main metric in agile delivery. We talked about how “working software” means not just that software is functional, it’s built to last. One of the most effective of these practices is code reviews, and we’ll start, as ...

Read More »