Author: Vijay SRJ

  • How and why to use Collectors.teeing() method in Java?

    Java has been striving hard to reduce the verbosity of its code in the latest features. Once such feature introduced is the teeing() method introduced in Java 12. A tee means this : Input from two different sources can be combined and fed into another source. Let’s say you have a list of employees. You…

  • How to use Records in Java

    Java 14 came up with a new feature called Records to reduce boiler plate code. One criticism against Java is that it takes too much code to achieve something compared to other languages like Python. The recent features in Java have been primarily targeted to reduce its verbosity. Records are one such feature. Usually when…

  • How to write recursive queries in SQL?

    Let’s say you want to find out all the subordinates to a manager recursively. That is say Kiran reports to Guru and Gayathri reports to Kiran , then the subordinates of Guru are both Kiran and Gayathri. This can be done using recursive queries. Let’s see how to do it in PostgreSQL. This is supported…

  • How to do user authentication in Spring Boot using PostgreSQL database?

    Let’s say you want to create an application in Spring Boot and authenticate the users who use it against credentials stored in a PostgreSQL database. Below are the high level steps to implement it in Spring Boot: Create a spring boot project with authentication related dependencies. Add the database configuration in application.properties against which you…

  • How to convert a Java standalone application into a jar file through command line?

    Let’s say you created a standalone java application and you want to execute it as a jar file. You want to run the main method of a particular class in your application when the jar file is executed. This post explains the steps to convert a java application to a jar file using command line.…

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

  • HTTP Client – Java 11 – Making HTTP requests in Java is so easy now

    Until Java 11 , making HTTP requests was not intuitive . You had to use the non friendly URLConnection class. With Java 11 , it looks easier and cool. To make any HTTP request ,you need the following: A HTTP Request A HTTP response A HTTP client to send the request and get the response…

  • How to automatically update creation and update timestamp through hibernate?

    Let’s say you have two columns in all of your tables , one to track when a record was created and another to track when it was last updated. You have chosen hibernate as your ORM framework and created corresponding entity classes as well. Hibernate allows you to update these columns automatically ! You just…

  • How to represent a composite key in hibernate?

    Consider the below class representing a Student. It has a primary key id , a class id and a name field. Say you want to combine the id and class id into a composite key. You want the same student id to be used against a different class id. We can achieve this in hibernate…