Author: Vijay SRJ

  • How to integrate SQLite Database with Spring Boot?

    Spring Boot doesn’t provide a straightforward way to integrate SQLite database compared to other databases such as MySQL , MongoDB etc. SQLite is the most used database engine in the world as SQLite website claims. And yet it is a surprise Spring Boot doesn’t treat it the same way as it treats other databases. To…

  • What is lombok and how to use it?

    Feeling bored of asking your IDE to generate getters and setters for your Java POJO classes? And also implementing toString(), equals() and hashCode() methods ? Lombok comes to the rescue. It automatically generates all of them for you. All you have to do is install lombok and then add the required annotations. How to install…

  • How to ignore Code Coverage for Lombok generated code?

    Recently I started using lombok code in one of my projects. It reduced verbosity to a great extent . But one issue kept popping up. The Code Coverage tool which I was using (JaCoCo) was showing zero percentage code coverage for the domain classes annotated with @Data annotation provided by lombok. I tried writing junit…

  • How to write custom queries in Spring Data at method level?

    Say you want to write a custom JPA query for one of your data requirements. Spring Data provides great abstraction over JPA to perform CRUD operations. You can easily retrieve entity objects from database based on field values using methods like ‘findByName’ , ‘findByNameAndAge’ etc in your interface extending Spring Data repositories. If you need…

  • How to load initial data in Spring Boot with and without defining schema?

    Let’s say that you want to populate your database with initial set of values as soon as your spring boot application starts. You may particularly need it if you are using an in memory database like H2. The process differs a bit when you define the schema yourself or let Spring Data define it. Spring…

  • How to convert LocalDate to Util Date and vice versa in Java?

    Java 8 introduced LocalDate to represent date without the time information . But sometimes we may need to convert LocalDate to the legacy java util Date in our code . This post explains how to convert from LocalDate to java.util.Date and vice versa. The below code converts local date to Util Date: And the below…

  • How to implement Visitor pattern in Java?

    Let’s say you are running a shop. You sell books, phones , shirts and other stuff. You already have a software to manage your stock. You store the original price, selling price , quantity and name of each item in your database. One day you decide to launch a massive discount sales. And you want…

  • How to implement Interpreter pattern in Java?

    Let’s say you are writing code for an application. You have decided to use only plain JDBC to peform database operations. No ORM (Object Relational Mapping tools). And so you write plain queries in your application code. When you run your code , your application starts throwing Query Syntax errors. You go back to the…

  • How to implement Iterator pattern in java?

    Let’s say you run a small theatre. Your theatre is unique , only those who have membership can watch movies in your theatre. Anyone of any age can be a member. You are not just screening latest movies but curated collections tailored for movie lovers. You have a database of all members . There are…

  • How to implement Memento pattern in Java?

    Let’s say you are designing a shirt online using a tool. You have created a design and saved it. And suddenly you realize you want the old design back. You find a menu to revert , you click it and you get back your old design. Let’s get under the hoods and see how this…