We usually don’t think of Java as a language for creating web applications, but there are actually several high-quality Java web frameworks that are worth considering. The Java Virtual Machine is a solid platform that makes it possible to follow the “Write Once, Run Anywhere” (WORA) principle in web development.
In this collection, you can find six popular Java web frameworks with which you can build scalable and reliable apps.
1. Spring Framework
The Spring Framework is the most well-known Java framework, coming with tons of features, utilities, and resources. You can use it to create any kind of Java applications, including microservices and enterprise-level software built on top of Java EE. Besides Java, the Spring Framework supports two other programming languages running on the Java Virtual Machine: Kotlin and Groovy.
As the Spring Framework takes care of recurring programming tasks such as security, data processing, and messaging, you can focus on writing the business logic of your application. It’s a bit complicated to configure the Spring Framework, as it comes with many possibilities. However, if you want to get started fast you can make use of the Spring Boot that provides you with a ready-made configuration for building Spring applications.
- Uses POJOs (Plain Old Java Objects) that lead to a simpler and more flexible codebase.
- Supports modularity (with lots of packages and classes).
- Backward compatibility and easy testability.
- Huge ecosystem (Spring Boot, Spring Cloud) and community.
- Extensive documentation and multiple Spring tutorials.
- Steep learning curve.
- Configuration takes time and effort.
Struts is an open source MVC (Model-View-Controller) framework that allows you to create enterprise-level Java EE web applications. The initial Struts framework (Struts 1.x) was rebuilt in 2007 when it was merged with the WebWork web application framework. Struts 1.x and Struts 2.x are not interchangeable, as there are important differences between the two frameworks. You can download both from Struts’ Releases page.
The Struts framework is owned by the Apache Software Foundation and developed by a group of volunteer programmers. Struts 2 has a simple plugin architecture that makes it possible to extend the framework by adding a single JAR to the classpath of your Java app. The framework comes bundled with multiple plugins, many of which let you integrate Struts 2 with other Java frameworks such as Spring, JavaServer Faces, JUnit, and others.
- Stable and well-tested framework, existing since 2006 (Struts 1 since 2000).
- Works well with REST, SOAP, and AJAX.
- Integrates with other Java technologies via plugins.
- Supports themes and templates.
- Uses simple POJO-based actions.
- Hard-to-navigate documentation.
- Not suitable for smaller applications.
3. JavaServer Faces (JSF)
JavaServer Faces (JSF) is an MVC framework with which you can create component-based, event-oriented UIs for web applications. It’s part of the Java EE platform, which means you can create Java EE apps without adding third-party libraries to your project. JSF components are reusable and portable, thus you can use a component on any JavaServer Faces project.
The initial JSF 1.x used JSP (JavaServer Pages) as its default templating system. The current JSF 2.x has switched to Facelets which lets you create more modern UIs. Besides Facelets, you can also create JSF templates using the XML User Interface Language (XUL).
- High-quality code base developed and maintained by Oracle.
- Stable, reliable framework (existing since 2004).
- Official standard; part of the Java Community Process program.
- Generates professional-looking user interfaces.
- Extensive ecosystem and tools; high-quality documentation.
- Complicated life cycle model (it’s hard to make JSF and non-JSF components work together, as non-JSF components don’t recognize the stages of the JSF life cycle).
- Steep learning curve.
4. Play Framework
The Play Framework is a reactive Java framework that lets you build scalable web applications in Java and Scala. It addresses the issues of other Java web frameworks, such as complicated architecture, steep learning curve, and slow development cycles. The Play Framework is written in Scala and follows the MVC architectural pattern. By default, it uses the Scala-based Twirl template engine. However, you can also use other libraries such as React to create the front-end views of your application.
Play follows the principles of The Reactive Manifesto. Therefore, it allows you to build flexible, loosely-coupled applications that are more tolerant of failure (i.e. they stay responsive when a failure happens). The Play Framework’s reactive model is based on Akka Streams, so it can process asynchronous HTTP requests. This makes it more suitable for microservices and distributed applications than other Java frameworks.
- High developer productivity.
- Easy configuration; uses the convention over configuration software design paradigm.
- 100% stateless connections, no Java EE sessions.
- Easy unit testing, with JUnit and Selenium built into the framework.
- Flat learning curve.
- Highly opinionated (this is the cost of easy configuration).
- Some confusion over versioning (Play 1.x and Play 2.x are not compatible) in learning materials.
5. Google Web Toolkit (GWT)
Web apps created with GWT have cross-browser compatibility. The framework offers functionalities for typical web development tasks such as browser history management, bookmarking, UI abstraction, remote procedure calls, and many others. You can also save a lot of time by using GWT’s pre-designed classes to create dynamic behaviors such as drag-and-drop UIs.
- High quality is guaranteed by Google.
- Apps run in all browsers, including mobile browsers for Android and iPhone.
- Pre-designed widgets and panels and a set of command-line tools.
- Built-in support for internationalization, localization, and unit testing.
- Flat learning curve (you can get started with GWT’s in-house tutorial of building a simple app).
- Extensive documentation and tutorials, many of which created by Google.
Vaadin is a one of a kind Java framework that allows you to create beautiful web applications using pre-designed UI components. You can bind your data directly to the components, as Vaadin provides direct access to the DOM from the Java back-end. Vaadin has two parts: the Vaadin Flow framework and the mobile-first Components library. Besides, Vaadin comes with ready-made themes you can customize via a styling API.
- High developer productivity.
- Built on the Web Components standards (future-proof).
- Pre-designed UI components and themes.
- Automates client-server communication.
- Excellent documentation and an active community.
- Premium add-ons such as commercial components are not free.
- UI representation requires a lot of memory.
Web frameworks are an important part of web development, as they can save you a lot of time by providing functionalities for common tasks. They also come with other perks as well, such as plugins, add-ons, pre-built UI elements, or integrations with third-party tools.
To learn more about Java basics, check out our beginner’s introduction to Java EE, too.