VJUG Talk: "How Should Java Developers Build Front-Ends for Web, Mobile & Desktop Today?"
Logistics
Conference
The Virtual Java User Group (VJUG) regularly hosted online talks. On April 7, 2021, I presented “How Should Java Developers Build Front-Ends for Web, Mobile & Desktop Today?”. I looked at various frameworks from a Java developer’s perspective and suggested which one to use in three common scenarios: building a web app from scratch, building native iOS and Android apps, and what to do on the desktop when you already had a web application.
Abstract
Users accessed applications on PCs and mobile devices at the time. There were two obvious ways to build front-ends for these devices: web applications and native applications. Cross-platform UI toolkits combined advantages from both approaches — examples were (in alphabetical order) Google’s Flutter, JavaFX, Facebook’s React Native, and Microsoft’s Xamarin. Important web frameworks were Google’s Angular, JSF, Facebook’s React, Thymeleaf, Vaadin, and Vue.js. I looked at various frameworks from a Java developer’s perspective and suggested which one to use in three common scenarios.
In 2019, I developed a mobile app prototype with Flutter and a progressive web application prototype — the videos are below. I then decided to use Flutter for native mobile apps in my SaaS start-up. Based on my experiences, I highlighted typical Flutter issues and how to solve them.
Why Should You Listen To Me?
I wasn’t affiliated with the projects I discussed, and I didn’t sell books or training courses. I shared industry analysis and my own project experiences to give you options for your next project. I used 12 criteria for my evaluation. You can use my criteria, pick your own, or weigh them differently than I did. But you need to apply your criteria in your own environment and make your own choice.
Summary
Here was my advice for “Building a Web App From Scratch”:
Here was my advice on “Building Native iOS and Android Apps”:
And here was my advice on “What to Do on Desktop When You Have a Web Application”:
Historical note (as of May 2021): After the talk, attendees could rate it live and leave feedback via Mentimeter. That poll is no longer reachable today.
Slides
The slides were available as a PDF (3.1 MB); the PDF version is available for download here.
Historical note (as of May 2021): Back then, the slides were also available in their original Keynote format (15 MB) — with less text, but animated and with a look behind the curtain of individual effects; that file is no longer available today.
Video
The talk is on YouTube; my part of the presentation starts at 3:51 into the video. It ran for 50 minutes, with 8 minutes of questions and answers afterward:
Flutter Hot Reload
Flutter Hot Reload made code changes go live in the device/simulator immediately. It was the main reason why working with Flutter could be such fun! I showed it in the talk — here it is again.
Mobile App Prototype with Flutter
Even though it was a bit older by then, this was still a good example of what a native Flutter app could look like. I wasn’t ready to show the app I was working on at the time.
In the summer of 2019, I built native iOS/Android apps with Flutter to validate a business problem. It took about six weeks and was my first Flutter project. I used Google’s cloud service Firebase for login, NoSQL database, and file storage. I built the back-end myself with Java, JHipster, Spring Boot, and Angular.
Progressive Web Application Prototype
At the end of 2019, I built a progressive web app (PWA) to speed up app development. A PWA used the “Service Worker” in a browser to install on a device and cache data. That took about four weeks and was my first PWA. I used Google Workbox for this but developed my own offline storage solution in the browser. I built the back-end with Java, JHipster, Spring Boot, and Angular.
Historical note (as of May 2021): At the time, I was looking for a new project starting in October 2022, in Milton Keynes, London, or remote.
Additional Talk Information
How Can We Build Front-Ends Today?
Declarative Front-Ends
These five frameworks showed different approaches to declarative front-ends:
Apple’s SwiftUI
SwiftUI was Apple’s take on declarative front-ends. Here’s the counter example from the talk, with slightly changed formatting:
@State var count: Int = 0
var body: some
View {
VStack(alignment: .center,
content: {
Text("Counter: \(count)").padding()
Button(
action: { self.count++ },
label: { Text("Increment") }
)
}
)
}
Google’s Flutter
Flutter was Google’s cross-platform implementation of declarative front-ends. It reached the stable version 1.0 for mobile in December 2018. Here’s what the SwiftUI counter sample looked like in Flutter:
int _counter = 0;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text( 'Counter: $_counter' ),
TextButton(
onPressed: () =>
setState({
_counter++
}),
child: Text( 'Increment' ),
),
],
);
Google’s Jetpack Compose
Jetpack Compose was Google’s Android implementation of declarative front-ends. So Google had two different horses in this race: Jetpack Compose and Flutter. Of course, it’s Google! 😒
Jetpack Compose entered beta on February 24, 2021. According to Google, it already had stable APIs and was feature-complete at the time.
I adopted the counter sample from this tutorial to look like the SwiftUI sample above:
val count = +state{0}
Column(Spacing(16.dp)) {
Container() {
Column() {
Text(
text = "Counter: ${count.value}",
modifier = Spacing(8.dp)
)
Button(
text = "Increase",
onClick = {
count.value++
}
)
}
}
}
Microsoft’s .NET Multi-platform App UI (MAUI)
.NET MAUI was part of .NET 6, expected for November 2021 at the time. And if “Maui” rang a bell for you — it’s the second-largest island of Hawaii.
Microsoft called its implementation of declarative front-ends “Model-View-Update” (MVU). Here’s what I thought the SwiftUI sample from above would look like in MVU. I adapted the sample from the announcement post:
readonly State<int> count = 0;
[Body]
View body() => new StackLayout {
new Label( "Counter: {count}" ),
new Button(
() => $"Increment",
() => count.Value ++
)
};
Facebook’s React
And finally, here’s what the counter looked like in Facebook’s React for web applications. I adapted it from this Stackblitz sample. Some HTML code shows up because I didn’t use components, to keep things simple. If I had, it would have looked just as declarative as the other examples:
class App extends React.Component {
state = {
counter: 0
}
render() {
return <div>
<p>Counter: {this.state.counter}</p>
<button onClick={
() => this.setState({
counter: this.state.counter + 1
})
}>Increase</button>
</div>
}
}
Web Applications
Popularity
I recorded all numbers on Wednesday, April 7, 2021.
Here are the terms I used with Google Trends:
- Angular: Web framework
- Jakarta Server Faces: Topic
- React: JavaScript library
- Thymeleaf: Software
- Vaadin: Topic
- Vue.js: Topic
Here’s the link for Stack Overflow Trends: all web frameworks
Here were the search queries for the Udemy course data:
I restricted the Amazon US book data to English books in the category Computer & Technology Books.
Here are the links for Stack Overflow Jobs:
Unlike the Stack Overflow search, the Indeed job search was a primitive full-text search in both the header and the body. I searched manually and then adjusted some values:
- A job with the title React Developer could still have Vue in the body. This was counted both as a result for React and Vue.
- Searching for React also showed results for React Native. I subtracted the number of React Native results from the React results.
- About half the search results for Flutter in the UK were for Flutter Entertainment, the world’s largest online betting company. This may have inflated results in other countries, too.
- About a third of the JSF results were defense industry jobs that referenced the Joint Strike Fighter aircraft program. This may have slightly inflated results in other countries, too.
- “Vue” has multiple meanings in French and Spanish. So in France, Canada, and Spain, I searched for “vue.js” instead.
You could find the detailed search results with links here:
Ranking
I ranked React fastest, for two reasons:
- React had an experimental feature called Concurrent Mode. If it made it into production, it would improve data loading with multiple components on a page.
- ReactDOMServer let us send HTML from the server to the browser before the React application was ready. The other frameworks may have had something similar.
Native iOS & Android Apps
Popularity
I recorded all numbers on Wednesday, April 7, 2021.
Here are the terms I used with Google Trends:
- Flutter: Software
- JavaFX: Topic
- React Native: Topic
- Xamarin Cross-platform Application Development - Second Edition: Topic
Here’s the link for Stack Overflow Trends: all cross-platform frameworks
Here were the search queries for the Udemy course data:
I restricted the Amazon US book data to English books in the category Computer & Technology Books.
Here are the links for Stack Overflow Jobs:
Please see the previous section for general information on the Indeed search.
Flutter was at a special disadvantage on Indeed. Often, you’d find the following in job ads there: “Experience with a cross-platform framework like Xamarin or React Native required”. Flutter was a cross-platform framework, but it was the new kid on the block. If you just had “Flutter” in your resume, you might still not get the job:
- Most big companies used Applicant Tracking Systems (ATS). These systems scanned resumes automatically for keywords. If “Flutter” wasn’t an approved keyword, you were out.
- The next stage was the agency or HR department. They typically had no clue about programming — how could they? They hired people for all sorts of professions. If they didn’t know about “Flutter”, you were out again. It wasn’t all sunshine and roses!
- Hopefully, the developers at the end of the process did know Flutter.
React Native Vs. Flutter
React Native always used a JavaScript VM to run our applications. Flutter used a Dart VM during development and compiled native code when deployed — that was faster. And that’s what GraalVM does in Java with Ahead-of-Time compilation (AOT) to produce native binaries.
React Native managed the native iOS/Android UI elements through a JavaScript bridge. That was slower than Dart: Dart used Google’s open-source Skia graphics library — Chrome, Firefox, Chrome OS, and Android also used Skia. But this also meant Flutter only painted pixels: it had to recreate all native iOS/Android UI elements in Flutter.
React Native didn’t officially support Windows or macOS. But Microsoft did: react-native-windows and react-native-macos. How production-ready they were remained unclear. And react-native-macos was a fork of the official React Native.
Flutter Plugins
The Flutter plugin portal was awesome! It gave you example code, popularity metrics, and code quality information:
Will Google Kill Flutter?
In 2019, Flutter was the project with the third-highest number of contributors on GitHub (section “Top and trending projects”). It had 13k. Azure Docs had 14k, VSCode had 19k. I couldn’t find these numbers for 2020.
Toyota, one of the biggest car makers in the world, picked Flutter to power future car entertainment systems. Whether this was just a test by Toyota or whether they’d already decided to go ahead with Flutter for production remained unclear.
Canonical, the maker of the popular Linux distribution Ubuntu, announced in March 2021 that Flutter would become the default choice for future Canonical mobile and desktop apps.
Responsive Design
Flutter gave only little help with responsive design: You found out the screen width and adjusted your UI yourself. Wonderful! So there was no grid like in Bootstrap or the more powerful, but also more complicated, HTML version. For now, I went with flutter_bootstrap.
Does Flutter Do Too Much?
- Animations on iOS could stutter when first used. There was now a project for that in Flutter.
- Flutter had more than 8,500 open issues. But the team claimed to close at least as many as were being opened — that seemed true for February 16, 2021 – March 16, 2021: 1,210 closed, 695 opened.
- “Sound Null Safety” was a feature of Dart that was new in Flutter 2.0. It did away with
NullPointerExceptions. But you needed to update your code — and the plugins you used also needed to be null-safe, and so did their dependencies. It was clear this would take a while and that some plugins wouldn’t get updated and would fall by the wayside. Flutter had a migration tool for null safety that was stunning: a web server that could automatically update your code! Here’s a video showing it:
- Flutter had hired a development studio to maintain the Firebase plugins, but I couldn’t find a link at the time. Firebase bundles a lot of Google services for applications.
Notable Flutter Plugins
- flutter_bootstrap: made your app responsive with the Bootstrap grid.
- flutter_platform_widgets: provided UI element abstractions that automatically created either an iOS or Android UI element, depending on the current mobile operating system.
- google_fonts: added Google Fonts to your Flutter application.
- url_launcher: launched apps to open links, send emails, or start phone calls or text messages. You could probably also launch application-specific URLs.
- flutter_email_sender: sent email in-app, using standard iOS/Android components.
- google_maps_flutter: opened Google Maps inside your app. Using Google Maps in your app was free on iOS and Android.
- connectivity: found out when the network connectivity of your app changed.
- image_picker: accessed photos & videos on iOS and Android.
- camera: accessed the camera on iOS and Android.
- image_cropper: edited pictures.
- photo_view: showed pictures with pinch-to-zoom.
- flutter_markdown: showed Markdown.
- native_pdf_view: showed PDF documents.
- flutter_html: showed HTML.
- freezed: generated immutable classes, complete with JSON serialization.
- flutter_easyloading: showed toast overlays for progress & success/info messages.
- package_info: got the application version number for your “About” screen.
- device_info: got device information for your “About” screen.
Getting Started
React & JavaScript
The React website was a good starting point. React used JavaScript to create web applications.
Learning JavaScript
- The MDN Web Docs (formerly known as “Mozilla Developer Network”) offered various tutorials based on skill level.
- academind offered a JavaScript course with 40 hours of video. The same course was on Udemy, where it may have been cheaper in a sale.
Learning TypeScript
TypeScript mixed “some Java into JavaScript”, such as types — hence the name! You had to use TypeScript with Angular. And you could use it with React.
The “TypeScript for Java/C# Programmers” article offered a starting point. If you liked it, the TypeScript handbook was your friend, also available as Epub and PDF.
Learning React
- The React site had a tutorial for beginners where you built an app.
- The React site also offered a tutorial for the React concepts.
- academind offered a React course with 40 hours of video, including React Hooks and Redux. The same course was on Udemy, where it may have been cheaper in a sale.
Flutter & Dart
The Flutter website was an excellent place to get familiar with Flutter. Flutter used the Dart programming language to build natively compiled applications for mobile, web, and desktop. Both Flutter and Dart could use plugins from a great portal.
Learning Dart
You started with the Dart language tour. Java developers then took “Intro to Dart for Java Developers”. After that, you had options:
- Google offered several free Dart tutorials.
- Code with Andrea offered a 10-hour Dart course.
Installing Flutter
The installation instructions came straight from the Flutter website:
Learning Flutter
A selection of Flutter tutorials and courses:
- Google offered several free Flutter tutorials.
- freeCodeCamp offered at least two free Flutter courses:
- a one-hour course for mobile apps, and
- a three-hour course that also claimed to cover desktop & web.
- Code with Andrea offered two paid courses:
- a 2.5-hour “Flutter REST API Crash Course” (I took it and liked it a lot!), and
- a 21-hour course on Flutter & Google Firebase.
- Finally, academind offered a Flutter course with 41 hours of video. I used the 2019 version to learn Flutter myself and could highly recommend it! The same course was on Udemy, where it may have been cheaper in a sale.