Effective Java with Groovy

Collection of blog posts on how Groovy improves the developer experience of implementing Effective Java practices. GR8Conf EU TalkWhen float and double put you in trouble!Are you implementing equals and hashCode correctly?Favour Internal IteratorsEnabling OrderThe (in)famous nullImmutability…

What's in Groovy for Functional Programming

Collection of blog posts on functional programming with Groovy. ClosuresHigher order functionsCurryingFunction compositionPure functionsImmutabilityRecursionTail call optimisationMemoizationCollect - map operationFilterReduceMap filter reduceStrategy patternCommand patternExecute Around pattern…

Groovy Scripts - Reusable Code

Let's start with the following Groovy script which reads and prints all the properties from a file. import java.nio.file.Path Properties loadProperties() { Properties properties = new Properties() Path propertyFilePath = Path.of('my.properties') propertyFilePath.withInputStream { properties.load(it) } properties } Properties properties = loadProperties() properties.each { println it } The script needs…

Effective Java with Groovy - Immutability

It would seem like mutability is the default design approach when it comes to Java. However, reading "Effective Java" makes you change your mind. The book suggests - 'minimise mutability'. Also, what is highly useful is the reason for favouring immutability - "immutability is simple". Did you get surprised? Now,…

Effective Java with Groovy - The (in)famous null

If you have seen some of the enterprise applications written in Java, you know the amount of code goes into performing null checks. The 'null reference' feature of Java for sure is the #1 contributor to employment generation. The creator of null reference has already admitted that it was a…

Micronaut HTTP Client - Error Flow

We have seen Micronaut BlockingHttpClient in action and how to use exchange and retrieve methods to interact with an HTTP endpoint. What happens if your endpoint returns HTTP status code greater than or equal to 400 (they indicate that it's an error)? To explore this, let's create an endpoint that…

Groovy Scripts - Exploring Binding

In a previous post exploring scripting basics, we saw how binding was used to supply command-line arguments to scripts. In this post, let's explore the design of binding further. class BindingDemo { static void main(String[] args) { Binding sampleBinding = new Binding() println sampleBinding.variables sampleBinding.message = "Hello" println sampleBinding.variables println…