Serengeti logo BLACK white bg w slogan
Menu

Streamlining Java Development with Quarkus

Irem Aktas, Senior Software Developer
08.05.2024.

In modern software world, with the overall growing consumption habits and the continuous development of cloud technologies, developing lightweight applications that will quickly address the needs, deploying these applications smoothly to the cloud environment and, of course, ensuring seamless data exchange between them is becoming increasingly important day by day.

Before cloud technology became so popular, huge monolith applications were written in Java running in huge performance servers. While running the application, a huge memory was consumed by the JVM, garbage collection management had crucial importance, and application startup time was not a big issue since the application was only re-started when the maintenance was required.

Now that the cloud technology requirements have changed, the machine requirements have also changed. The new software world requires multiple small machines which can be deployed and scaled to hundreds of micro services and their instances, which means that more JVM instances can be quickly up and running in a single node server like other language running platforms like nodeJS, Go or Python.

Java, following its long-standing dominance in the league of programming languages, has now started to lose its popularity because of prolonged booting time and heavy JAR management.

However, Java is also evolving and following new tech trends with its new versions. For example, garbage collection enhancements with Java 17 and virtual threads with Java 21 have also created a great impact on performance improvements.

Quarkus was created in late 2018 as an open-source Red Hat product. It presents a great alternative to close the gaps in Java world, helping to create performant and responsive applications using strong features of Java. Quarkus looks promising with this catchy statement “Supersonic Subatomic Java”. So, what exactly are these “Supersonic” and “Subatomic” terms?

image

Supersonic: It is a good word to create speed perception. Quarkus provides speed for both developers working area and application startup time.

Quarkus saves development time. When a developer makes a change on code or configuration, it builds the code while the application is running, and the developer easily tests the changes without restarting the application.

In terms of application speed, when an executable jar is created by Quarkus or executable binary is created via GraalVM or Hotspot, Quarkus offers fast response and startup time. 

Subatomic: Since Quarkus has a very small core and everything else is an extension. Even Kubernetes as a primary member of Quarkus is an extension. In this way, the produced executable binary size and the amount consumed resources are very small.

With various of extensions, you can build any kind of applications with Quarkus, not just Function as a Service (FaaS), Micro-services or Server-less Reactive Systems.

Bootstrapping the application

After a long introduction, lets dive into the implementation details and continue with bootstrapping. There are multiple options to create a Quarkus project. You can either use Quarkus cli or gradle. Here we will continue with maven.

Using mvn command:

The command below is a sample of creating a Quarkus project:

% mvn -U io.quarkus:quarkus-maven-plugin:create \

        -DprojectGroupId=com.eaetirk.quarkus.starting \

        -DprojectArtifactId=rest-lead \

        -DclassName="com.eaetirk.quarkus.starting.LeadResource" \

        -Dpath="/api/leads" \

        -Dextensions=“resteasy-jsonb"

This is the generated project structure after running the mvn command:

rest-lead % tree

├── README.md

├── mvnw

├── mvnw.cmd

├── pom.xml

└── src

    ├── main

    │   ├── docker

    │   │   ├── Dockerfile.jvm

    │   │   ├── Dockerfile.legacy-jar

    │   │   ├── Dockerfile.native

    │   │   └── Dockerfile.native-micro

    │   ├── java

    │   │   └── com

    │   │       └── eaetirk

    │   │           └── quarkus

    │   │               └── starting

    │   │                   └── LeadResource.java

    │   └── resources

    │       └── application.properties

    └── test

        └── java

            └── com

                └── eaetirk

                    └── quarkus

                        └── starting

                            ├── LeadResourceIT.java

                            └── LeadResourceTest.java

For more information or to configure additional attributes, you can visit this link: https://quarkus.io/guides/maven-tooling

To add the extension, the command bellow can be used as a sample command:

% mvn quarkus:add-extension -Dextensions=“io.quarkus:quarkus-hibernate-orm-panache”

By default, Quarkus is generating automatically application class and its main method which will bootstrap Quarkus. In order to override the main method, you can create an application class with @QuarkusMain annotation as the sample below:

image 1

Using quarkus.io application configuration page:

Here is the link where you can create your application using the quarkus.io configuration application page:

https://code.quarkus.io/

image 2

With both project creation methods, maven wrapper files are being generated. If you don’t have maven installed on your machine, you can use the “./mvnw “ command under project directory directly to build or add extension, or start your project.

After creating the project, you will see that Quarkus has already created a sample Jakarta Rest resource which is ready to run. According to our very first sample, the class below is created by Quarkus:

image 3

You can start using the mvn wrapper to start the application in development mode as shown below:

rest-lead % ./mvnw quarkus:dev

image 4

After running the application, you can either use curl or postman to test your API.

rest-lead % curl -w “\n” http://localhost:8080/api/leads

Hello RESTEasy

image 5

Conclusion

In this chapter, we introduced Quarkus and covered how to create an application using Quarkus.

In the next chapter, we will continue our application by adding a persistence layer.

Thank you for reading 😊

References

https://quarkus.io/

https://quarkus.io/get-started/

https://code.quarkus.io/

Let's do business

The project was co-financed by the European Union from the European Regional Development Fund. The content of the site is the sole responsibility of Serengeti ltd.
cross