Effective Java with Groovy - Enabling Order This post shows how does Groovy make it convenient for you to implement Comparable and Comparator interfaces.
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
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"
Effective Java with Groovy - Favour Internal Iterators Let's start with the following code making use of the traditional for loop. List<String> languages = List.of("Java", "Groovy", "Kotlin"); // List.of() requires Java 9 or above for (int i = 0; i < languages.size(); i++) { System.out.println(
Groovy Scripts - Functions and Variables In a previous post, we explored the simplicity of scripting mode offered by Groovy. We arrived at the following code. String message = args.length > 0 ? "Hello ${args[0]}" : "Hello" println message Let's make the functionality slightly more sophisticated. Say, we want to send
Effective Java with Groovy - Are you implementing equals and hashCode correctly? Consider the following Groovy code. class Product { String sku String description BigDecimal price } Now let's put the Product class into use as follows. Product book1 = new Product(sku: 'P101', description: 'Effective Java', price: 599.0) Product book2 = new Product(sku: 'P101', description:
Micronaut HTTP Client - just the response body In a previous post, we used io.micronaut.http.client.BlockingHttpClient to get response from an HTTP endpoint. We used the exchange method as follows. HttpResponse response = client.toBlocking().exchange("/greeting", String) If you are using Java instead of Groovy, you will pass "String.class" instead
Groovy Scripts - How do they work? If you are already familiar with Groovy, you know that Groovy supports script mode where you can write Groovy code without explicitly creating a class. This mode is suitable when you want to house the entire code in a single class. If you are new to Groovy, you might want
Effective Java with Groovy - When float and double put you in trouble! Let's start with a Java program! What do you think the following program would print? float price = 0.1f; float amount = 0f; for (int i = 0; i < 10; i++) { amount += price; } System.out.println("Total price: " + amount); Well, the developer indeed intended the amount to
SDKMAN - A must-have for all developers using JVM Did you ever have to work with multiple Java projects and each of them was on different version Java or any JVM tools? SDKMAN is a CLI tool for managing multiple versions of Java and JVM tools. I started using this tool in its earlier form known as GVM(Groovy