Home » Java » Page 8

Java

Java 8 – Convert IntStream to Array

A quick guide on how to convert IntSteam to Array in java 8. 1. Overview In this tutorial, We’ll learn how to convert IntStream to Array of ints in java 8. IntStream is used to create infinite streams with the number series pattern. But, some of the time we might need to convert the number series to an array. 2. Java ...

Read More »

Java 8 – Convert IntStream To List and Other

A quick guide on how to convert IntStream to List in java 8. 1. Overview In this tutorial, We’ll learn how to convert IntStream to List in java 8 and java 16 above versions. IntStream is used to create the infinite streams in java 8 and it has the method to convert it to array usingtoArray() method. But there are ...

Read More »

Get logged-in user info in Jakarta EE – the simplest way

java-interview-questions-answers

The security before Java EE 8 / Jakarta EE 8 used to be a bit complicated and confusing. Every specification provided its own way to retrieve information about the logged-in user. The situation greatly improved with the introduction of the Security API that provides a unified way to do that – simply inject the SecurityContext CDI bean. There’s still a small catch ...

Read More »

Mockito when-then vs do-when

Writing unit test is very important for better software quality. For unit tests Mockito is one of the most common choices of developers. Mockito providers different way to mock methods, like do…when and when..then. Most of the time we face the question to use when-then vs do-when. We will see all the differences in detail. In Mockito we can mock ...

Read More »

Java Math pow() method Example (Recursive and Loop Iterative)

A quick guide to Math.pow() method in java. Custom implementation of Math pow() using iterative and recursive approaches. 1. Overview In this post, You will learn how to calculate the power of a number using the Math pow() method in java.  In other words, in Some interviews, these questions are asked as writing a program to find/calculate the power of ...

Read More »

How to properly inject CDI beans into JAX-RS sub-resources

java-interview-questions-answers

Jakarta REST (JAX-RS) defines it’s own dependency injection using the @Context annotation. REST resources also support CDI injection if you enable CDI on the REST resource class (e.g. using a bean-defining annotation like @RequestScoped). But injection doesn’t work out of the box on JAX-RS sub-resources. How to create sub-resources so that both injection mechanisms work also in sub-resources? I’ll show you, it’s very easy. How to ...

Read More »

Add Grpc to your Spring Application

spring-interview-questions-answers

On the previous example we had a Java application spinning up an http server and upon this Java process operating a GRPC application. If you use frameworks like Spring you might wonder how you can achieve a Grpc and Spring integration.There are libraries out there that do so, we shall use the grpc-spring-boot-starter from io.github.lognet.We shall start with the dependencies. ...

Read More »