BT

InfoQ Homepage News Writing Web Applications in Java - a Study of Alternatives

Writing Web Applications in Java - a Study of Alternatives

This item in japanese

Bookmarks

With the increasing popularity of compile-to-JavaScript languages, developers familiar with the Java Virtual Machine(JVM) languages and who want to develop web applications without the difficulties of a JavaScript development stack, have an increasing array of alternatives to JavaScript to choose from. A recently published analysis of GWT, TeaVM, JSweet, CheerpJ, and Vaadin Flow that examined performance and payload characteristics on a trivial application seems to indicate that the performance penalty vs. native JavaScript web applications is shrinking.

Java developer Renato Athaydes recently compared JVM alternatives to JavaScript. The target application that serves as reference for the comparison is a simple counter, implemented with the React JavaScript front-end library:

Simple React counter app

The counter app got implemented in five Java frameworks: GWT, TeaVM, JSweet, CheerpJ, and Vaadin Flow. The comparison between the five Java alternatives and the native JavaScript application followed a simple methodology: create the counter app using the most basic tools provided by the Java product/framework, and subsequently measure the application’s size, and performance. The application size is obtained through the browser’s network tab (counting all types of resources to avoid bias in favor of frameworks that rely on heavy, non-JavaScript resources). The performance is measured leveraging the auditing tool from Google Chrome’s built-in Lighthouse. LightHouse's performance score is evaluated on six weighted metrics, presented here in decreasing order of importance: Time to Interactive, Speed Index, First Contentful Paint, First CPU Idle, First Meaningful Paint and Estimated Input Latency.

The study shows that JSweet and TeaVM beat the native JavaScript React application on the First Contentful Paint(FCP) measure as reported by Lighthouse. Google reports that First Contentful Paint "measures the time from navigation to the time when the browser renders the first bit of content from the DOM. This is an important milestone for users because it provides feedback that the page is actually loading". While most implementations obtain what is deemed by LightHouse to be a good global performance score (> 90 with a maximum of 100), the CheerPJ framework performed poorly in comparison to its peers.

performance comparison

The resulting Java framework ranking can be explained in large part by the size of the produced JavaScript:

Imgur

Here, the Java frameworks rank in the same order. This is to be expected, as the time for the browser to parse the produced JavaScript correlates positively to size and negatively to performance.

The study does not include J2CL, a recent google-backed Java-to-JavaScript transpiler. Furthermore, the study relies on a trivial web application. While the results cannot be extrapolated to a large web application, it serves nonetheless to analyze the differences between the Java frameworks considered in the study.

CheerPJ's large size and subsequent poor performance can for instance be explained by the fact that it is not really a Java-to-JavaScript transpiler but a complete Java runtime shipped to the browser. On the bright side, CheerPJ allows developers to take a compiled jar containing a Swing app and run it in the browser, without plugins.

GWT (released in 2006) is a mature open-source technology used for instance by Google AdWords. GWT ships with a series of widgets and panels for user interface construction.

TeaVM claims to be an ahead-of-time compiler for Java bytecode that emits JavaScript and WebAssembly that runs in a browser. TeaVM does not require source code, only compiled class files. Moreover, the source code is not required to be Java, so TeaVM may compile Kotlin and Scala.

Jsweet self-describes as a transpiler from Java to TypeScript/JavaScript with 1000+ well-typed JavaScript libraries available from Java. Jsweet claims to allow developers to access generated APIs/objects from JavaScript, without requiring additional tooling or runtime. However, Jsweet does not fully emulate Java. Existing Java applications may have to be modified in some measure, in particular those which use Java-specific APIs such as Swing for the user interface.

Vaadin Flow is a set of components and tools for building web apps in Java. Vaadin Flow features built-in Spring support, automatic server-client communication with WebSocket support. Web applications may be written in pure Java, or a mix of Java and HTML. Vaadin's components are web components self-described as mobile-first, fine-tuned for UX, performance, and accessibility. However, Vaddin Flows ships a client-side engine weighing over "300k compressed (regardless of app size)". The latter explains the performance profile of Vaadin Flow.

The study methodology is inspired from the blog post A real-world comparison of front-end frameworks, which InfoQ previously reported on.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • That ship has sailed...

    by Greg Liebowitz /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    GWT was a brilliant, groundbreaking piece of engineering from 2006 until around 2010. Today however, Angular etc. is well into the mainstream and Java “back end” developers absolutely must learn to be full stack to stay current...

  • Re: That ship has sailed...

    by Bruno Couriol /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I hear you. However there have some recent development (cf. www.infoq.com/news/2019/05/j2cl-java-javascript...) by Google in the direction of Java-to-JavaScript transpilers, which seems to indicate that use cases exist. There is a large proportion of developers who master Java, and the JS ecosystem can be daunting at first -- notwithstanding adding Angular2 to the mix. Such technology may provide a quick path to implementing a different breed of applications (for instance in-house web applications with performance requirements less stringent than regular web apps) at a lower cost. Additionally, reuse of existing battle-tested Java code within a JavaSCript codebase may also be a productive way forward for some companies.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.