Month: June 2020

  • Day 100 – Wrapping It Up

    Feeling a sense of relief, today is the 100th day of another 100 day project : Post one technical post per day for 100 days. On the third day after lockdown was announced in Tamilnadu, I started working on this idea. This has kept my mind occupied. I have stopped following news about corona spread…

  • Introducing JCli – A command line tool for creating Java applications

    Imagine you could create your java applications from command line using a tool. Just like you would use ng tool for Angular and npm for node js. This would save a lot of developer time. With this in mind I experimented with creating a command line tool called “jcli” (java client) using Java and picocli…

  • How to use Optional keyword to avoid NullPointerException in nested objects in Java?

    Let’s say you have a nested object in your application . And you want to retrieve the value of a field in the deepest nested object. We will see how to do this using pre-Java 8 and post-Java 8 code (using Optional keyword) Lets consider an Employee object, Let’s say the Employee object has an…

  • How to create Immutable collections in Java?

    Let’s say you want to create a list of objects which cannot be modified. There are three ways to do this in Java: Using Collection Factories Using methods in Collections utility class Using methods in Collectors utility class Using Collection Factories: Java 9 came up with collection factories to create immutable collections. To create an…

  • How to use services in Java Modules?

    Java 9 came up with the module system. This post gives a minimalist explanation of how to create modules in java. Let’s say you have decided to use modules in your application. And you are going to buy and sell coconuts using these modules as done in the post highlighted. And so you have created…

  • How to create Java Modules?

    Java 9 introduced the Module system under the project name Project Jigsaw. This altered the existing structure of Java projects. Java projects can be now encapsulated into modules and each module can be separately packaged into a jar or a run time (customized JRE). Until the module system came out , every Java project has…

  • On Maven Wrapper

    Let’s say you have built a project using maven. You used a specific version of maven to build it. Now you want to send this project to your friend. To build your project , your friend first needs to install maven in his machine. And also he might need to use the specific version you…

  • How to use the var keyword in Java?

    Java is statically typed. It means the type of a variable is known at compile time. And it is strongly typed , an integer variable will always be an integer variable . Starting Java 10 , Java introduced the concept of local variable type. Since then you can use var keyword to represent variables. This…

  • Sealed classes and interfaces in Java

    Let’s say you are creating a base class and you want it be extended by other developers to reuse the code. Say you developed a base class named Animal and you want to allow another developer to create a Cat class which can extend this base class. So you made the base class as public…

  • How to create a command line tool using Java?

    How to create a command line tool using Java?

    Java applications can be run using command line , but you can pass only arguments . Based on the position of the arguments , you can retrieve them in your application and code your logic. What if you can pass flags to your java application and let it execute logic based on that. Like in…