In this quick tutorial, we will show you how to run a Json REST API with Scala in 5 minutes and only 10 lines of code, thanks to the awesome Http4s library. 0) Prerequisites You need java and sbt installed on your machine. In this tutorial, I am using Java 11 and Sbt 1.5.5. 1) […]
Parse HTML in Java with XPath and Jsoup
In this tutorial, we will explain how to parse and extract content from an HTML source code. First we will download a real HTML source code with Apache HTTP client and then we will parse it with an awesome Java library called Xsoup. It is a mix of Jsoup and XPath. It is better adapted […]
In this tutorial, we will see a simple method to insert a Java object as a row into a SQL table. Thanks to Apache DB Utils and Apache Bean Utils, our mapping between Java JDBC and SQL will be automatic. 1) The Java object Let’s consider the following Java class Customer: (@AllArgsConstructor and @Data are annotations from the Lombok […]
In this tutorial, we will explain how to run PostgreSQL with Java and Testcontainers. Testcontainers is an awesome library that allows you to configure and start docker containers from Java. To run a PostgreSQL database, you need Docker on your machine. Add these dependencies to your pom.xml: Then, simply run: Replace databaseName, username and password […]
In this tutorial we will see how to very simply transform a JDBC result set into a list of Java objects. Let’s say you have the following SQL table customer: On the Java side, you have the following POJO called Customer: @NoArgsConstructor, @AllArgsConstructor and @Data are annotations from the Lombok project. They add constructors, getters and setters to the […]
In this tutorial, we will explain how to sort a list of Java objects based on a field of the object. Firstly, we will see a method using the method reference operator :: that takes only 1 line of code. Then we will see a more generic method based on a lambda comparator that needs […]
Java is a general purpose language that has a library for almost anything. Using the Java Regex library, you can easily extract the text between two predefined strings. To extract the text between two strings tag1 and tag2 from the string content, we only need 4 lines of code: You can print the variable extracted […]
Python is very light and convenient for manipulating regex. To extract the text between two strings tag1 and tag2 from the string content, we can use the Python regex library. We only need 2 lines of code: pattern = “(?<=tag1).*(?=tag2)” extracted = re.search(pattern, content).group(0) re is the Python regex library, you will need to import […]

It is very common to use a UUID as primary key for a SQL table. You can generate a unique random UUID on the client side and then insert it into the database. However, there is a simpler way: you can ask the database to automatically generate it on every insert. With PostgreSQL, it is […]

In this tutorial, we will explain how to easily limit the size of a PostgreSQL table (by size we mean number of rows). To achieve this, we will create a trigger on the table via Java JDBC. The trigger will be atomically executed after each SQL insert, and the insert that causes the trigger to […]