Quarkus - Interview questions and answers

 
1. What is Quarkus Framework? 

The Quarkus is a full-stack, Kubernetes-native Java framework made for Java virtual machines and native compilation, optimizing Java categorically for containers and enabling it to become an efficacious platform for serverless, cloud, and Kubernetes environments.
The goal of Quarkus is to make Java a leading platform in Kubernetes and serverless environments while offering developers an amalgamated reactive and imperative programming model to optimally address a wider range of distributed application architectures.  
 

2. Why do we use Quarkus?

The Quarkus optimizes Java and makes it efficient for containers, cloud, and serverless environments with memory consumption optimization and an expeditious first replication time. Quarkus optimizes Java and makes it efficient for containers, cloud, and serverless environments with memory consumption optimization and a fast first response time. The Quarkus has a low learning curve for Java developers.


3. What server does Quarkus use?

Quarkus uses Vert. x and Netty at its core. And, it utilizes a bunch of reactive frameworks and extensions on top to avail developers. Quarkus is not just for HTTP microservices, but additionally for event-driven architecture. Its reactive nature makes it very efficient when dealing with messages (e.g., AMQP).
 

4. What are the advantages of Quarkus?
  • Quarkus is production-ready.
  • Fast start-up time - use it in your Kubernetes distribution or serverless.
  • Reduce cloud costs - lower memory consumption, increase container density, reduce VM size.
  • We don’t need to re-skill your Java developers, pick it up in 1 week.  
  • Unifies and supports imperative and reactive (non-blocking) styles


5. What is the Quarkus Dependency Injection?

Dependency injection in Quarkus is predicated on Quarkus ArC which is a CDI-predicated build-time oriented dependency injection solution tailored for Quarkus architecture.

For Example,
@ApplicationScoped
public class UserRepositoryImpl implements UserRepository {
private final MongoClient mongoClient;

@Inject
public UserRepositoryImpl(MongoClient mongoClient) {
this.mongoClient = mongoClient;
}
The @Inject annotation lets us define an injection point that is injected during bean instantiation. The injection can occur via three different mechanisms.

1. Direct field injection:
public class Payment {
private @Inject
ShoppingCart cart;
}
2. Initializer method parameter injection:
public class Payment {
private ShoppingCart cart;

@Inject
void setShoppingCart(ShoppingCart cart) {
this.cart = cart;
}
}
3. Bean constructor parameter injection:
public class Payment {
private final ShoppingCart cart;

@Inject
public Checkout(ShoppingCart cart) {
this.cart = cart;
}
}


6. What is the use of @Singleton annotation?

@javax.inject.Singleton is an annotation used to create a CDI with a singleton scope

For Example,
@Singleton
public class UserResource {

@Inject
EntityManager entityManager;

public List<User> getUsers() {
return entityManager.
             createQuery("SELECT c FROM User c").getResultList();
}

public User getUser(Long id) {
return entityManager.find(User.class, id);
}//TODO}


7. What is the use of @ApplicationScoped annotation?

@ApplicationScoped object is created once for the duration of the application.it can be used multiple times in the application once created.

For Example,
@ApplicationScoped
public class UserRepositoryImpl implements UserRepository {
private final MongoClient mongoClient;

@Inject
public UserRepositoryImpl(MongoClient mongoClient) {
this.mongoClient = mongoClient;
}//TODO}


8. What is MicroProfile in Quarkus?

A primary value of Eclipse MicroProfile is the faculty to inscribe portable microservices that can run on multiple MicroProfile implementations. This offers developers a superb cull of runtimes to optate from and decide on one (or more) predicated on technical or business requisites. 
Quarkus is a MicroProfile implementation that fixates on efficiently running Java applications in containers in general and Kubernetes in particular. 


9. What is Quarkus reactive?

Reactive is a set of principles to build robust, efficient, and concurrent applications and systems. These principles let us handle more load than traditional approaches while utilizing the resources more efficiently while additionally reacting to failures gracefully.

In Quarkus, Mutiny is an intuitive, reactive programming library. 
Quarkus uses Mutiny as its central reactive programming model. So, it supports returning Mutiny types (Uni and Multi) from HTTP endpoints.   


10. What is the difference between mono and flux in Quarkus reactive?
  • Uni — handle the stream of 0..1 item 
  @POST
public Uni<Response> addUser(User user) {
return user.persist().
map(r -> Response.accepted().build());

}
  
  • Multi — handle the stream of 0..n items (potentially unbounded)
@GET
@Produces(MediaType.APPLICATION_JSON)
public Multi<User> userList() {
return User.streamAllUsers();
}
    

11. What is Quarkus extension?

A Quarkus extension is simply a module that can run on top of a Quarkus application. The most common use case for such an extension is to get a third-party framework running on top of a Quarkus application.  


12. What is GraalVM?

GraalVM is a universal virtual machine for running applications written in  JVM-based languages like Java, Scala, Groovy, Kotlin and LLVM-based languages such as C and C++ and JavaScript, Python, Ruby, R.


13. What is a native image?

A native image is a platform-specific standalone executable engendered from JVM predicated languages like Java, Kotlin, or Scala.
This executable includes the application classes, classes from its dependencies, runtime library classes, and statically linked native code from JDK.


14. What is Kogito?

Kogito is the open-source Quarkus extension that allows the implementation of the core business logic in a business-driven manner. Kogito precompiles business assets (eg., BPMN file or a rules decision table). It automatically engenders the native executable with its own REST endpoint that sanctions interaction with its respective processes, tasks, and rules. 


15. What is code.quarkus.io?

code.quarkus.io is used to create a quick Quarkus project like Spring Initializr.


16. How To Create a Quarkus Project?

Step 1. Launch Quarkus Initializr using https://code.quarkus.io/ link
Step 2Specify Project Details 


Look at the above image, we have specified the following details:
  • Build Tool: Maven
  • Group: org.knf.dev.demo
  • Artifact: code-with-quarkus
  • Search & Pick extensions: RESTEasy JSON-B
Once, all the details are entered, click on Generate your application button will generate a Quarkus project and download it. Next, Unzip the downloaded zip file and import it into your favourite IDE.

Step 3Import the project to your favourite IDE.I am using IntelliJ IDEA.


17. What is AMQP?

Advanced Message Queuing is a fast, flexible and cost-effective open standard that allows messaging interoperability between systems, regardless of message broker vendor or platform used. The main features of AMQP are message orientation, queuing, routing, reliability, and security.


18. What is Panache?

Panache is a Quarkus-specific library that simplifies the development of our Hibernate-based persistence layer. Using Panache, we can reduce boilerplate code in  Java or Kotlin classes.

For example,

User Entity:
@Entity
public class User extends PanacheEntity {

@Column(length = 60, unique = true)
public String name;

public User() {
}

public User(String name) {
this.name = name;
}
}
User Repository:
@Singleton
public class UserDao implements PanacheRepository<User> {

}
User Endpoint:
@Path("/users")
public class UserEndPoint {
@Inject
private UserDao userDao;

@GET
public List<User> get() {
return userDao.listAll(Sort.by("name"));
}

@GET
@Path("{id}")
public User getSingle(@PathParam Long id) {
User entity = userDao.findById(id);
if (entity == null) {
throw new WebApplicationException("User with id of " + id +
" does not exist.", 404);
}
return entity;
}
}
It is Homogeneous to Spring Data JPA.


19. What is the use of @ConfigProperty annotation?

@ConfigProperty is used to inject the configuration properties in the application.

For example,

application.properties:
knf.application.key = knowledgefactory.net
knf.application.secret = 5babae4e646ff5d59119dc47c9b64ca7

Injecting the configuration properties in the application:
@ConfigProperty(name = "knf.application.key")
private String key;

@ConfigProperty(name = "knf.application.secret")
private String secret;


20. What does @inject annotation mean?

The @Inject annotation lets us define an injection point that is injected during bean instantiation. The injection can occur via three different mechanisms.

1. Direct field injection:
public class Payment {
private @Inject
ShoppingCart cart;
}

2. Initializer method parameter injection:
public class Payment {
private ShoppingCart cart;

@Inject
void setShoppingCart(ShoppingCart cart) {
this.cart = cart;
}
}

3. Bean constructor parameter injection:
public class Payment {
private final ShoppingCart cart;

@Inject
public Checkout(ShoppingCart cart) {
this.cart = cart;
}
}

Quarkus Related topics,

Popular posts from this blog

Spring boot video streaming example-HTML5

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Spring Boot + Mockito simple application with 100% code coverage

Spring Boot + OpenCSV Export Data to CSV Example

Custom Exception Handling in Quarkus REST API

DataTable-Pagination example with Spring boot, jQuery and ajax

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Node JS mini projects with source code - free download

Spring boot web project free download:User Registration System

Java - Blowfish Encryption and decryption Example