Browsed by
Category: Java

Generate QR codes (Java)

Generate QR codes (Java)

A QR code (Quick Response code) is a type of a barcode invented in 1994 by the Japanese automotive company Denso Wave. In this article, we’ll get a basic information about QR codes in general and will learn how to generate QR codes in a Java application.

N+1 select: JOIN FETCH (Hibernate)

N+1 select: JOIN FETCH (Hibernate)

Using object-relational mapping tools like Hibernate can significantly simplify and speed up the development process. For a developer, it’s easier to operate with object entities rather than switching to relational tables every time he needs to access a database. Nevertheless, it has its disadvantages. The main disadvantage is a high chance to ruin the performance if used without a good understanding of how it works under the hood. This tutorial covers the common problem called “N+1 select” and describes one of the solutions – JOIN FETCH.

Asynchronous methods using @Async annotation (Spring)

Asynchronous methods using @Async annotation (Spring)

Let’s imagine that you need to call a time-consuming service method from a controller and its result can be postponed. For example, it can import a huge number of records to a database and you can’t force the client to wait minutes/hours for a response. In such a case, it makes sense to make such a method asynchronous, i.e. a separate thread will be created to process the task, but the controller will immediately return to the user. Spring can easily help to configure asynchronous methods using @Async annotation.

Stateless OAuth2 Google authentication (JWT)

Stateless OAuth2 Google authentication (JWT)

Stateful authentication stores authentication sessions in some internal storage (in-memory, database, Redis, etc.) and returns a session identifier to a user.
In this tutorial, we’re going to cover stateless OAuth2 Google authentication when after a successful authentication a user receives an independent token (JWT in 99% of cases) with all required information in it. Both types of authentication have their own advantages and disadvantages. Stateless authentication is widely used for SPA applications and mobile clients.

JSON Web Token (JWT) and Java

JSON Web Token (JWT) and Java

JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed.

One of the mostly used use-cases for JWT is authorization. A client authenticates and a server returns a generated token in response. The client stores the token and sends it with every further request.

Reduce Java boilerplate (Lombok)

Reduce Java boilerplate (Lombok)

Have you ever had a feeling that a significant amount of code you write is redundant? It’s not a secret that Java can be quite verbose and often you just follow a contract of this programming language. Luckily, you’re not the only one who worries about it. As a result, a great solution to deal with it appeared to reduce Java boilerplate – Lombok.

Java Bean Validation

Java Bean Validation

Overview Data validation is a crucial process in software development. Invalid data may easily break the application. So, ideally, the input data should be validated as soon as possible and handled in a corresponding way. Since data validation is one of the most common programming logic, it makes sense to find a way to reduce code duplication. Bean Validation 2.0, defined by JSR 380, is a specification of the Java API for bean validation. It defines a way to validate…

Read More Read More

Aspect-oriented programming (AOP) with Spring Boot

Aspect-oriented programming (AOP) with Spring Boot

Overview Aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. Cross–cutting concerns are parts of a program that rely on or must affect many other parts of the system. Commonly used cross-cutting concerns are: logging transaction management performance monitoring security checks etc. AOP concepts Aspect: The concern that cuts across multiple classes or modules. Transaction and security are examples. Spring Transaction is implemented as Aspects. Join point: A point during the execution of the program at which you…

Read More Read More

Sessions in Redis (Spring Boot)

Sessions in Redis (Spring Boot)

Overview HTTP is a stateless protocol. It means that every time a new request is sent from the client to the server the state information of the previous request is lost. Sessions are used to store some state between requests. When a client successfully authenticates into a website, a new session is created. The next time the client visits a website, he will get access immediately without passing credentials again. How does this work technically? After successful authentication, the new…

Read More Read More