Author: Vijay SRJ

  • How to protect REST API using Basic Authentication?

    How to protect REST API using Basic Authentication?

    REST APIs are one of the primary means of communication between different apps in modern web applications. Anyone can send a request to a public REST API and get a response. This poses security risk. We need only legitimate users to hit our REST APIs and get the information they need. We can do this…

  • How to connect to database from a REST API?

    How to connect to database from a REST API?

    Web applications store data in a database. Doing so , data is stored permanently somewhere so that you can process it later. Even if your application server goes down , you still have the data in your database. Spring makes it easy to connect to any database. You require very minimal code to do this.…

  • How to create a REST API in Spring Boot?

    How to create a REST API in Spring Boot?

    Let’s say you want to create an ecommerce store. And you want to expose REST APIs to the end users to do CRUD(Create, Read , Update and Delete) operations on your store items. You can do this with minimal effort in Spring Boot. Let’s create the REST APIs. Creating a REST API in Spring Boot…

  • How to do server side validation in Spring Boot for REST API requests?

    Let’s say you are creating a REST API to add a batsman profile to a cricket database. The API takes in batsman details like name , age ,number of matches, batting average, experience and runs . Before adding these details to our database you want to validate these details. Like name should be a valid…

  • Java 21 – Scoped Values

    How do you pass a value from one part of your code to another. Let’s say from one class to another. By using method arguments. Is there any other way that you can access a shared variable? For example, Let’s say you need to pass the user name who logged into your web app from…

  • How to connect to database using ConnectionDetails interface in Spring Boot?

    Let’s say you want to connect to a database in your Spring Boot application. You first add Spring Data dependency. Then to configure the database details , you had two options: Starting Spring Boot 3.1.1 you have one more option. Using ConnectionDetails interface. Let’s see how to do that with an example. STEP 1: Add…

  • Java 21 – Structured Concurrency

    Let’s say you want to perform a group of tasks in Java. And all these tasks are part of a single unit of work. And all these tasks can be executed independently. How can this be done in Java? You can execute each task sequentially. So you execute task 1 , then task 2 and…

  • Java 21 – Virtual Threads

    Java supports concurrency. You can perform multiple tasks at the same time in a program. And how does Java implement this? Using Threads! A thread is the basic unit of concurrency in Java. If you want to perform multiple tasks in parallel you create one thread for each task and perform them in parallel. And…

  • Java 21 – Sequenced Collections

    How do you get the last element of a list in Java? Using a code similar to below: That doesn’t look elegant! And how do you get the last element for a Sorted Set? That looks much more elegant but then different collections are having different ways to get the last element. There is no…

  • Java 21 – String templates

    Contents: The Problem “String” is a basic and widely used data type in any programming language. Most of the data we deal with are texts which are represented by String datatype. One of the operations we often do on text is replacing part of the text with dynamic values . This is called interpolation. Languages…