18 ms·
Using Java 9 Modularization to Ship Zero-Dependency Native Apps
- capelio 9y agoEven so, Java is now at a place where you can ship self-contained, zero-dependency applications that are comparable in size to other compiled languages (and superior to web-hybrid options like Electron). For cross-platform desktop GUI apps, I would argue that JavaFX combined with Java 9 modularization is hands-down the best choice available today. Electron is succeeding in the desktop GUI space because it tears down the barriers to desktop app development. While the author's article is excellent, when it comes to Electron, he (like most engineers) is still missing the point: the choice between Electron and its alternatives doesn't pivot on file size.
- aaomidi 9y agoYes, but it's electron. I've honestly seen only one properly written Electron app and it's VSCode. Everything else electron sucks. VSCode is not great either but it's much better than say, Atom or Slack.
- bpicolo 9y agoDiscord is great
- supergreg 9y agoSo is gitkraken. But I assume these apps have spent a considerable amount of time in optimizing electron, which not everyone can do.
- erikbye 9y agoWhile some may find GitKraken visually pleasing, it can't be used for big repos; didn't even manage to open a few of the ones I tried.
- crispinb 9y agoI was curious as I've never found a standalone visual git client I liked as much as IntelliJ's integrated one. So I downloaded it, found it was 1/4 of a GB and wouldn't look at a local repo without logging in to a web service. Deleted.
- philliphaydon 9y agoIt never used to require logging in but the moment they added that I deleted it.
- friendzis 9y agoSome years ago I was evaluating GUI git clients (the landscape has changed since) for rather simple flows and found SmartGitHg simple enough to setup and explain in under an hour and powerful enough not to drop to a shell. No affiliation here.
- SOLAR_FIELDS 9y agoI still haven't found anything better than IntelliJ's triple column view for resolving merge conflicts. Is there anything similar in a more lightweight editor?
- icebraining 9y agoIf you don't mind having it separate from your main editor, Meld is great.
- SOLAR_FIELDS 9y agoInteresting that this is touted as one of the "best" uses of Meld[0]. Will try this out tomorrow. 0: http://meldmerge.org/help/resolving-conflicts.html http://meldmerge.org/help/resolving-conflicts.html
- Spivak 9y agoSure, but Discord's web app and their native app are basically equivalent. The native app gives a little more system integration (like global hotkeys and direct access to sound hardware) but fundamentally the Discord app is just a webview. I don't think anyone doubts that a high-quality website wrapped in a webview won't be at least the same quality. The question is whether "web-native" platforms can do more than just be a branded browser.
- deleted 9y ago[deleted]
- richardwhiuk 9y agoSlack?
- blueline 9y agostutters horrendously very often for my work setup (~800 people). also eats tons and tons of memory and kills my battery
- cyberpunk0 9y agoAnecdotal problems
- KGIII 9y agoAnother anecdote; your comment is the only one I've ever noticed that appears to be defending Slack. From an outsider looking in, I'm not sure why it is so popular.
- always_good 9y agoIt's popular because technical superiority isn't why people use software. For example, Spotify eats 100% CPU if I leave it open for 24 hours yet I don't think I've met someone in the last year that doesn't have Spotify running on their computer.
- KGIII 9y agoIf it helps, I don't have Spotify.
- NikolaeVarius 9y agoSlack takes up 1.3 gb of RAM if I don't restart it at least once a week
- ssijak 9y agoWell, will see how Electron will pan out in the end. While I dislike default Java Swing GUI (it can be made easily to look native but many devs previously did not do it), JavaFX can be made to look like anything with almost weblike feel to development and animations. Now, more than the looks I dislike the slowness and utterly unacceptable memory Electron apps consume. I ditched Electron and VSCode (it is a little better than Atom) because I don`t want to have my text editor eat 500mb ram to open 1 medium file and crash on large ones. Same for Slack and other Electron apps. And it is not even funny to see dev console when some Atom plugin or whatever crash. I`m interested how many devs also ditched this two editors ONLY because of Electron bloat.
- pjmlp 9y agoElectron pop culture made me buy Sublime Text.
- ssijak 9y agoFor me it finally pushed me enough to switch to Vim for web dev work. But I do have Sublime for just in case.
- jjoonathan 9y agoWhat a breath of fresh air Sublime is.
- cyberpunk0 9y agoProbably not many. They are too busy developing instead of over obsessing over small performance gains
- Avshalom 9y ago>tears down the barriers to desktop app development Yes, then it replaces them with the barriers to web app development.
- Spivak 9y agoSure, but more companies have the story of needing a web app anyway which requires a specific tech stack. So you can either maintain two tech stacks or you can port your webapp to native. Having a beautiful, easy to develop, and easy to maintain native stack means nothing when you don't have an answer to, "How do we then reuse our code in a browser?".
- pjmlp 9y agoYou don't. Use the browser for what it was meant for, hyperactive documents. Everything that matters is on the backend accessed via Web APIs.
- _sh 9y agoElectron sits in the same hybrid space as Cordova/Phonegap, and will suffer the same fate once React Native, or something similar, starts eating its lunch.
- Can_Not 9y agoThere are some ReactNative alternatives calling themselves "native" that are only "native looking css in a webview". The future will probably only get more ambiguous.
- gdfhhgddhjj 9y agoIt’s really not clear what the electron app even provides over the same app in chrome. Its own icon, sure, but the behavior is just as bad as on the web—just take slack for example.
- cyberpunk0 9y agoIt offers access to file system and system resources as well as multi platform build support. Developers like all people will whine over anything. For students and indie devs who have little time, support, and resources things like electron are great
- gdfhhgddhjj 9y agoRight, but does eg slack actually use any of that? It’s not a great native client by any stretch—it doesn’t use a native UI, it’s not particularly snappy, and it doesn’t do any special integration. So, it seems that electron is mostly a way to distinguish certain sites from others, not that they provide a better experience. Granted I do like the distinct app icon. But electron should mean more than that to qualify as meaningfully native.
- alexasmyths 9y agoWhat electron gives Slack is A) local install and B) proper notifications. So Slack gets an icon on the homescreen and possibly offline notification + notification integration with the OS. That might be pretty limited from a technical perspective, but it's a massive product thing from a product perspective. Also, it's possible they may use file access for caching/storage etc..
- 0xFFC 9y agoNot closing and losing your data when your chrome crashes?
- profalseidol 9y agoI can be, for very small very cheap devices.
- phreack 9y agoWhile Electron's popularity was a boon to the desktop app scene, I keep on dreaming that JavaFX applications made with Kotlin, jlink, Gluon's scene builder (or maybe even something better) will gain enough popularity to attract a healthy open source community for cross platform desktop apps. It feels like the tools are almost where they need to be and finally coming together!
- adamhepner 9y agoOK, so question time: I haven't done any Java (let alone Kotlin) coding now for what seems like ages, but will need to implement a relatively simple, yet cross-platform client for my upcoming application. It will probably sound extremely silly, but were I to write a GUI that speaks to a REST API, where should I start doing my research?
- phreack 9y agoIf you have more recent experience on C++, Python or Javascript then you should be looking into Qt, PyQt, Electron (respectively) or other alternatives first, but if you're willing to try the Java environment you could look into the following components to get you started: -Kotlin to speed up development -Gradle as a dependency manager -Retrofit + OkHTTP to create a type safe backend API definition -JavaFX for the GUI components -Gluon's scene builder if you like creating your FX views in xml, with a visual editor -RX as a powerful library for async tasks -Gson or Jackson as a JSON parsing library -IntelliJ if you like coding with IDEs, for its massive refactoring capabilities It's a lot to take in if you're unfamiliar, but together they all come to form really solid desktop applications.
- generichuman 9y agoI want to use JavaFX to develop cross-platform apps but I feel JVM uses too much memory even for little things. It's been a while since I've used Java to program, has the memory situation changed? or are there any other solutions for lowering the JVM memory usage?
- slackingoff2017 9y agoJava will use as much memory as you give it. Higher heap size is better for performance up to around 32GB. For most Java apps you can limit heap to 256M or less with little consequence. AFAIK Java uses less ram than Python and JavaScript, only common languages that beat it are Golang and C/C++
- nextos 9y agoAnd memory used will be hopefully quite lower with value types, coming sometime in the future: http://www.jesperdj.com/2015/10/04/project-valhalla-value-types/ http://www.jesperdj.com/2015/10/04/project-valhalla-value-ty...
- vbezhenar 9y agoI used Swing Java applications on a computer with 512 MB RAM. Sure, Java eats more than C++, but it should be pretty in line with JavaScript which is a very popular choice nowadays.
- jm547ster 9y agoDefault heap size is over-generous in most JVM implementations, experimenting with smaller settings is the solution.
- pjmlp 9y agoApparently lack of memory isn't something that affects Electron popularity. Java applications use much less memory, unless their coders weren't paying attention during algorithms and datastructures lectures.
- camus2 9y ago> A “Hello World” CLI written in Go compiles to around 2 MB. Nitpick but hello-world in Go : package main func main(){ print("Hello World") } is < 1MB on most computers (900KB on windows). No need to import the "fmt" package.
- slackingoff2017 9y agoYou can get under 200KB in Java easily by using proguard or similar to strip unused code from your dependencies.
- camus2 9y agoSure, but I didn't apply any specific code optimization or third party tool here.
- slackingoff2017 9y agoProgaurd is default on Android and some other environments, it's not anything exotic.
- pebers 9y agoBut that 200KB isn't a standalone executable. The Go example would be a lot smaller if it just distributed some unlinked object code with no runtime.
- slackingoff2017 9y agoTrue. The JVM is big. I've been meaning to try Golang one of these days, I see it as Java's spiritual successor
- eropple 9y agoI tend to view it more as a regressor. Golang is a conservative retrenchment towards Java pre-1.5 in a lot of ways. (And that may be fine for some use cases; I get the appeal even if I think it's misguided.)
- tootie 9y agoWhile everyone is excited about how this helps desktop app development, this is also going to simplify server deploys. If you've got a full java stack, you won't need to do anything to provision a server.
- tuananh 9y agoi think this is a better selling point.
- tpolzer 9y agoDoes it have cross platform Hi-DPI support? No.
- ZenoArrow 9y agoAre you joking? I can't tell. Just in case you aren't, what do you think is required for a platform to support Hi-DPI displays?
- Pyxl101 9y agoI'm not the OP, but I assume hi-DPI support means that applications scale up their GUI sizes appropriately based on the DPI. When I use a hi-DPI display (like 4K displays), a lot of old software renders text and widgets too small to see, because they were programmed to display things as so-many pixels high, without concern for DPI. It's frequently a problem with old video games, though it affects regular applications too.
- Sophistifunk 9y agoIt's more than that, simply pixel-doubling the UI is also terrible. Real hi-DPI support (to me) is actually rendering at hi-dpi.
- ZenoArrow 9y agoWhat difference does it make if the standard resolution is Hi-DPI or not? Can you visually tell the difference between pixel doubling and other methods of designing for Hi-DPI?
- harrygeez 9y agoFor what's it's worth, I've written Java 8 on macOS and it 'just works'. I didn't have to do anything to make it look good in hidpi.
- tpolzer 9y ago
- zengid 9y agoI'm unfamiliar with the state of the art, but could this make it possible to target iOS with a bundled JVM?
- filereaper 9y agoiOS tends to favour direct native code, hence the use of Objective C and Swift for iOS development. Given the already large ecosystem built on these lanuages, its unlikely they'll pivot to a JVM based system.
- pjmlp 9y agoThere are AOT native Java compilers for iOS, the majority just tends to ignore them.
- ssijak 9y agoNo.
- MBCook 9y agossijak is right, Apple still doesn’t allow general purpose interpreters, so you can’t put an app in the store built on the JVM. As others have pointed out you could compile the Java code to native code before submitting the app, the way C# apps are put in the store.
- pjmlp 9y agoIt is possible using an AOT compiler for Java, like Codename One or Robot VM. So far Oracle has shown little interest into integrating such features into OpenJDK, but the ongoing efforts to add AOT compilation to it, might become a possible solution.
- i386 9y agoOracle have broken and delayed releases of Java so some people can get slimmer binaries? Hardly seems like a good trade off when storage is the cheapest it’s ever been.
- blinkingled 9y agoIt's not about storage. Most desktops don't have a JRE installed and downloading the full non-modular JRE and installing it before being able to run the program is a hassle compared to providing a stripped down, self sufficient, linked version of the app that's one third in size.
- erik_seaberg 9y agoEnd result: install nine apps, end up with three variously outdated copies of the JRE, none of which benefit the tenth app I install. It's frustrating how we're wallowing in problems that had already been solved for most of my career.
- blinkingled 9y agoWith JNLP you could presumably keep all those JREs updated automatically - no issues other than storage which isn't.
- i386 9y agoWho cares about desktop apps? Most Java development is done on the server where the size of your runtime isn't a constraint. Breaking reflection, delaying language features, releases, etc is a very poor tradeoff for the module system that has been delivered.
- blinkingled 9y agoWell, now you can care about Java desktop apps - that's kind of the point of all this :) And server apps don't really switch that fast to newest Java release. Only now we're seeing JDK7 based things for example.
- 0xFFC 9y agoGreat article. Pair this with AOT. Then you have unbeatable combination. Productivity of java with availability of Native features. Count me in!
- firdak 9y agoSo, after "optimizations [...] to further reduce the resulting bundle size", a Java command-line "Hello World" is still 21.7 MB. I've found a Node.js version (using node-packer [1]) to be about the same size. However, as mentioned in the article, "Hello World" in Go is an order of magnitude smaller. The article may be right that Java is "the best choice available" for cross-platform GUI apps, but for cross-platform command-line tools, I think Go is currently the best option. IMO Go provides the best tradeoff between ease of development, ease of distribution and runtime performance. [1] https://github.com/pmq20/node-packer https://github.com/pmq20/node-packer
- nerdponx 9y ago2.17 MB is still enormous for a "hello world" binary.
- c_shu 9y agoNo. 2.17 MB is NOT enormous. Usually there is no runtime library. In contrast, C or C++ runtime libraries can easily exceed that size. For example, vc_redist.x64.exe is 13.9 MB.
- joosters 9y ago(Note: The size in the article is 21.7 MB, and not 2.17 MB!) I just tried building a statically linked 'hello world' c++ program, and co-incidentally, the binary also happened to be 2.1 MB! #include <iostream> int main( int, const char *[] ) { std::cout << "Hello World!" << std::endl; return 0; } 'g++ -static -o hello hello.cpp' produces a binary of 2191112 bytes (Linux x64). Stripping it of debug symbols leaves a 1.7 MB file.
- taspeotis 9y agohttp://www.muppetlabs.com/~breadbox/software/tiny/teensy.html http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
- 9y ago
- 0xbear 9y ago“Zero dependency” after you install a 80MB JRE. You keep using this word. I don’t think it means what you think it does. Statically linked C is zero dependency. Go is zero dependency. Copy a binary to the target system and it runs. There’s nothing else to install.
- wstrange 9y agoThe bundle includes the JRE.
- kbenson 9y agoIt gets a little fuzzy. Go and C are only zero dependency once you have their platforms installed (the OS). The JRE is only a little on top of that, ships with some systems out of the box, and is generally ubiquitous enough that you can probably rely on it being present it over a particular OS being present. Ita not really zero cost, but neither is an app that only has binaries for an OS you don't run.
- jrs95 9y agoThis looks pretty awesome. I haven't used JavaFX before, but if it's easy enough to deliver high quality UX with it, I'll be using this for any side project desktop apps I end up working on.
- ksec 9y ago15 years since I last looked at Java for Desktop Apps and shipping as binary. I remember there were also GCJ as the commercial JET alternative. Graal and Truffle are progressing along. I wonder what happen to SubstrateVM, which allows AOT of Java. I assume with SVM the binary size can be further reduced and much faster startup time.
- bmn__ 9y agoTFA reads like GCJ does not exist, a classic lie by omission. Don't become a victim of misinformation! Compiling to small, native binaries (i.e. JRE not needed) is possible since at least 10 years ago. Let's examine this application as an example: http://sancho-gui.sf.net http://sancho-gui.sf.net /tmp/sancho-0.9.4-59-linux-gtk$ ls -hs ./sancho 13M ./sancho /tmp/sancho-0.9.4-59-linux-gtk$ du -hs ./lib 740K ./lib /tmp/sancho-0.9.4-59-linux-gtk$ ldd ./sancho linux-gate.so.1 (0xf7f71000) libm.so.6 => /lib/libm.so.6 (0xf7e30000) libpthread.so.0 => /lib/libpthread.so.0 (0xf7e11000) librt.so.1 => /lib/librt.so.1 (0xf7e07000) libdl.so.2 => /lib/libdl.so.2 (0xf7e02000) libc.so.6 => /lib/libc.so.6 (0xf7c29000) /lib/ld-linux.so.2 (0xf7f73000)
- kryptiskt 9y agoGCJ is dead, there is no development and it has been removed from GCC.
- mmargerum 9y agoBoy if I could pair this with Clojure I’d seriously consider building desktop apps again.