Author: Vijay SRJ

  • 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, Why and When to use Stream.toList() method in Java?

    Java 16 introduced a new method toList() to Stream interface. How is this going to help Java Developers? Let’s see it through an example. Let us take the use case where you want to iterate through a stream of objects, filter it based on certain criteria and save the results in a list. Traditionally you…

  • How to use Pattern Matching for instanceof operator in Java?

    Let’s say you have a generic method which accepts any object as a parameter. Based on the type of the object , the method performs custom operations. Traditionally to implement this you need to do the following steps: Check the passed parameter using instanceof operator for the specific type If it matches , cast the…

  • How to redirect to an external URL from Spring Boot REST Controller (Post/Redirect/Get pattern)?

    Let’s say you want to redirect users to an external URL when they make an API request. How to do this in Spring Boot? There are two ways you can do this. One using ResponseEntity object Two using RedirectView object. Here is how to do it with ResponseEntity object: STEP1: Create a REST Controller which…

  • A Test Match with Superlatives – India vs England Third Pink Ball Test

    England scores the lowest test innings total vs India Ashwin becomes the second fastest in the world and the fastest Indian to scalp 400 test wickets Joe Root gets his first fifer in test cricket and ends his bowling with an incredible 5/8 The first test match played in the world’s largest cricket stadium The…

  • How to save time typing document.getElementById().value and document.createElement() in javascript?

    If you are using vanilla javascript , you may frequently use document.getElementById(elementid).value to retrieve the value of a html element. Also to dynamically create a html element you would use document.createElement(elementtype) You can avoid typing these manually by following a simple trick. The trick is to create a function which executes the above code and…

  • Unmasked

    My daily weekday routine usually goes like this these days: I wake up , do yoga on days when I wake up early , get my daughter ready for her online class (LKG) , attend class along with her , then take care of her till evening until my wife arrives from office. On days…

  • How to do user authorization in Spring Boot?

    Let’s say you have created a Spring Boot application and protected it using a login form. If any user tries to access your application they are presented with a login form . If the user name and password match , they are allowed to access your screens. If you want to know how to implement…

  • 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 interpret and modify REST requests in Spring Boot in a centralized way?

    Let’s say you have created a bunch of REST services in your Spring Boot app. And you want to perform a common action on all the requests. May be you want to log the incoming requests to a log file. Instead of doing this action for every REST service you can do it in a…