Java frameworks: Spring vs Quarkus

Introducing some of the most well-known and widely adopted frameworks.

After you’ve mastered your ints and hashmaps, you probably want to know how Java software is developed in the real world. Well, you probably won’t write as much code as you think. Most programming problems have already been solved in frameworks. But which are the most well-known Java frameworks? Let’s find out.

A mug of coffee with a Spring leaf design next to another mug with an atom Quarkus design

For most Java developers, frameworks are a part of everyday life.

Perhaps you’re just learning Java and you want to get the lay of the land, or you’re an operations engineer who wants to understand more about those Java workloads you’re running.

Well, here are the frameworks you will probably see in modern Java development.

Why frameworks?

A good framework helps you build solid foundations for your application and means that you don’t need to “reinvent the wheel” for every bit of functionality you need.

(We might think that we can forge a piece of metal into something that turns round and round, but it’s easier and cheaper to just buy a wheel.)

Of course, you can still write an app from scratch without a framework. But in most companies – especially larger ones – you’ll see frameworks in use.

Why?

Because a framework provides a common way to write an application. It helps developers work together, and it reduces the amount of boilerplate code that you need to write.

Let’s see two of the most well-known Java frameworks in use today: Spring and Quarkus.

🍃 Spring

Spring is an umbrella brand for a whole bunch of frameworks and libraries for Java. Specifically many new Java projects these days start on Spring Boot:

Website https://spring.io/projects/spring-boot
Stargazers 61,000+
GitHub https://github.com/spring-projects/spring-boot
License Apache 2.0
Examples GoThinkster RealWorld, Spring Petclinic

Spring started out as a dependency injection framework, but now it’s much more than that. The various projects in Spring help Java developers to do things like connect to a database, or write reactive (asynchronous) applications.

Let’s dive in to Spring.

What is Spring? What’s inside the box?

Spring has many projects, but the most well-known ones are:

  • Spring Framework. This is the main project, and is the basis for everything else in the Spring universe. Spring Framework is a dependency injection container, and a bunch of utilities.

  • Spring Boot. Spring Boot is the modern way to create a Spring application. You don’t need to use Boot to create a Spring app. But most people do, because it’s easier! It makes it easy to “bootstrap” a Spring project (it configures your Spring Framework container and auto-configures lots of third-party libraries too.)

The are lots of other projects under the ‘Spring’ name. Some of them help you work with data (Spring Data), write batch processing programs (Spring Batch), or create REST services (Spring REST).

What do you need to know?

What should you know about Spring?

  • Spring enables the Inversion-of-Control design pattern. Inside your application, Spring creates a virtual ‘container’ called the Application Context. Inside the container, it creates objects from your classes, and then wires them up together (simple, right?)

  • It’s stable and well-documented. Spring is supported by VMware, who employ developers that work on Spring and keep it patched and up-to-date.

  • Big community. There are almost 200,000 questions about Spring on Stack Overflow, an annual Spring conference, and lots of blog posts to learn from.

  • Good for cloud-native microservices. Spring Boot helped spread the trend of running Java applications without an application server. Spring Boot builds your application to a single .jar file. This makes it easier to implement microservices.

  • The inertia effect. Spring is used by lots of developers, so… it gets used by even more developers. If you know Spring, you won’t have a problem finding a job in Java today.

How to develop apps with Spring Boot

Most people start with Spring Boot. It’s the easiest way to start developing a Spring application:

  1. Generate your app. Go to start.spring.io, use the application generator. Add the Spring Web dependency. This generates a Spring Boot application with an embedded web server (so you can create APIs).

  2. Write your code. Load the project into your IDE. Add annotations to your code when you need Spring to do something.

  3. Compile your app to a JAR file. Use the Maven plugin to compile your application into a single JAR file.

  4. Deploy and run it. Run the packaged JAR file on a virtual machine with Java installed, run in the cloud (e.g. deploy it onto AWS Elastic Beanstalk) or package it into a container image and run on Kubernetes.

⚛ Quarkus

Quarkus is a framework for developing small, fast Java apps.

Website https://quarkus.io
Stargazers 10,000+
GitHub https://github.com/quarkusio/quarkus
License Apache 2.0
Examples quarkus-quickstarts

Quarkus consists of a runtime “core” which you use to develop your application.

Then you add extensions which give you features and functionality you want to add to your app.

What is Quarkus? What’s inside the box?

So what is Quarkus, really? When you create apps with it, what components do you use?

  • Quarkus Core. This is the runtime core which helps you build the scaffolding for your app. It manages the lifecycle of your application and handles capabilities like configuration management, etc.

  • Reactive Engine. Under the hood, Quarkus uses a tool called Vert.x to manage tasks from the various internal components. Vert.x is a Java toolkit for creating reactive applications. It helps applications to perform some tasks quicker, by allowing the application to work on another task, while it’s waiting for the result of another task. (It’s a bit more complicated than this, but you can read more.)

  • Quarkus Extensions. To add a framework or library to your Quarkus app, you need to add an extension. There are a growing number of extensions. For example, there is a JPA extension which lets you add Hibernate, so that you can save data to a database. Or, you can use the Arc extension to add support for CDI (Contexts & Dependency Injection).

What do you need to know?

  • Quarkus optimises your app at build time. Quarkus uses a special build process, which removes some unused code and classes. It also tries to do some of your app’s initialisation work upfront during the build, so that the compiled app has to do less work on startup.

  • Uses less memory, starts up faster. Some tests have shown that Quarkus uses less memory at runtime and starts up quicker. This means that it’s a good choice for developing microservices.

  • Compiles to a native binary on Linux. A Quarkus application can be compiled to a native binary on Linux. This means that your application can run on a Linux system without needing to run inside the Java Virtual Machine (JVM), so it can be much smaller and faster.

  • Uses Java standards that you might already know. Quarkus lets you code using some well-known Java standards, like CDI, JPA, JAX-RS and MicroProfile.

  • Live coding. While you’re developing, Quarkus can automatically compile your code changes and reload your application, without you having to stop and start it yourself. It’s very fast, and feels just like you are developing a PHP or Node.js app.

  • Tooling to create containers. The Quarkus build tooling lets you easily create a container (Docker) image for your application.

How to develop apps with Quarkus

To get started with Quarkus, you can create a skeleton project and add the extensions that you need.

Here’s how to do it:

  1. Generate your app. Go to code.quarkus.io to generate a new Quarkus application. Add the capabilities you want to your app, by choosing Extensions. Download the source code as a ZIP file.

  2. Write your code. Import the source code into your IDE. Write your code.

  3. Build your application to a JAR or native binary. Use the Quarkus Maven Plugin to package your app, and optionally into a native binary and/or into a container.

  4. Deploy and run it. Run it on a cloud provider, Kubernetes cluster, FaaS/serverless platform (like AWS Lambda or Azure Functions) or just a plain old virtual machine.

Wrapping up

Two of the biggest Java frameworks in use today are Spring (well, specifically Spring Boot) and Quarkus.

If you want to understand Java, then try to create a simple application in either of these two frameworks. It will give you a better idea of how Java programs are written in the real world.

Of course, there are many more frameworks in Java; too numerous to cover here. (But that’s maybe an article for another day!)

Happy Java programming.

Tom Donohue

By Tom Donohue, Editor | Twitter | LinkedIn

Tom is the founder of Tutorial Works. He’s an engineer and open source advocate. He uses the blog as a vehicle for sharing tutorials, writing about technology and talking about himself in the third person. His very first computer was an Acorn Electron.

Join the discussion

Got some thoughts on what you've just read? Want to know what other people think? Or is there anything technically wrong with the article? (We'd love to know so that we can correct it!) Join the conversation and leave a comment.

Comments are moderated.