Tag: java

  • How to write a generic REST client in Spring Boot?

    We live in the world of microservices. REST APIs are all over and they communicate with each other. To communicate with each other in the Spring World , they use RestTemplate or Spring WebClient or Java’s own HttpClient(Java 11) or any other third party libraries. We call them REST clients. It will be nice if…

  • The best way to use Optional in Java

    Null pointer exceptions. They have often been a headache to java developers. Your application breaks out of nowhere and throws null pointer exceptions. You rub your forehead then and add that null check you missed out. Java wanted to solve this problem. And they introduced the Optional keyword. They described it as a “Container” that…

  • How do javascript functions differ from Java functions?

    How do you avoid repeated coding in a programming language? By using functions. You write the piece of code with the logic you want to execute inside a function and then call it wherever you want. Javascript functions achieve the same but differ a bit from languages like Java. Here are the features in javascript…

  • Java 16 features every Java developer should know

    Java 16 features every Java developer should know

    Java 16 just released. Though a lot of new features were introduced only six of them need to be understood by day to day java developers. Here are those features: Records Pattern matching for instanceof Sealed classes (Second preview) jpackage packaging tool Stream.toList() method Day Period support added to java.time Formats 1.Records: If you want…

  • How to replace accented characters with the original characters in Java?

    Let’s say you have written an application which processes regular text. If user enters an accented word like “tête-à-tête” your application would break! How to remove the accents in the above characters? That is you want the word “tete-a-tete” and not “tête-à-tête”. Java provides a way. Below are the steps: STEP1: Normalize the word Normalizing…

  • 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…

  • 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…

  • How to create a Windows Native Java application (generating .exe file)?

    Let’s say you have created a Java application and packaged it into a jar. You want to install this jar in another machine. Traditionally , you need to first install java in that machine and then copy the jar . The application can be launched by running the jar. Or you can use third party…

  • Future vs Completable Future in Java

    The best way to run asynchronous threads in Java had been to use the Executor Service framework until Java 8. Executor Service returns a Future object which can be used to retrieve the result of an asynchronous thread. But it comes with few drawbacks. Among the many features introduced in Java 8 , one of…

  • How to measure time in a single unit of time in Java?

    Let’s say you want to find out the number of weeks since your birthday , or the number of decades , or the number of hours . And you want to do this in a single line of code. Java 8 allows you to do that. It provides an API named ChronoUnit under java.time.temporal package…