Java features

Node.js vs. Java: An epic battle for developer mindshare

Let’s examine how the enterprise stalwart and JavaScript upstart stack up in the battle for the server room

Java features

Show More
1 2 Page 2
Page 2 of 2

But Java is making inroads in another way. The newest Chromebooks will support Android apps, giving Java developers a path to the desktop of Chromebook users. Is there still a chance for Java to conquer the desktop?

Where Node.js wins: Libraries

There is a huge collection of libraries available in Java, and they offer some of the most serious work around. Text indexing tools like Lucene and computer vision toolkits like OpenCV are two examples of great open source projects that are ready to be the foundation of a serious project. 

But JavaScript programmers have been staying up late and churning out many amazing projects of their own. In some areas, Java is a distant memory. There may be a zillion different progressive web frameworks, and Java can’t begin to compete in this new world. When you move beyond this very important and dynamic sector, the pickings get a bit harder to find. But the energy in the web space is unrivaled. Node is rapidly accumulating a deeper bench of code to call into the game.

Where Java wins: Solid engineering

It’s a bit hard to quantify, but many of the complex packages for serious scientific work are written in Java because Java has strong mathematical foundations. Sun spent a long time sweating the details of the utility classes and it shows. There are BigIntegers, elaborate IO routines, and complex Date code with implementations of both Gregorian and Julian calendars.

JavaScript is fine for simple tasks, but there’s plenty of confusion in the guts. One easy way to see this is in JavaScript’s three different results for functions that don’t have answers: undefined, NaN, and null. Which is right? Well, each has its role—one of which is to drive programmers nuts trying to keep them straight. Issues about the weirder corners of the language rarely cause problems for simple form work, but they don’t feel like a good foundation for complex mathematical and type work.

Where Node.js wins: Speed

People love to praise the speed of Node.js. The data comes in and the answers come out like lightning. Node.js doesn’t mess around with setting up separate threads with all of the locking headaches. There’s no overhead to slow down anything. You write simple code and Node.js takes the right step as quickly as possible.

The callback model has changed programming by excluding the programmer from the job of juggling multiple concurrent tasks. The JavaScript engine does the work of figuring out what needs to run when. The programmer writes shorter, event-driven code and focuses on the important logic.

This praise comes with a caveat. Your Node.js code better be simple and it better work correctly. If it deadlocks, the entire server could lock up. Operating system developers have pulled their hair out creating safety nets that can withstand programming mistakes, but Node.js casts these nets aside.

And then there is the problem of code complexity as the programmers nest endless layers of callback functions like Russian dolls. One callback is easy to follow, but a chain of N callbacks can be mind-numbing. The good news is that the promise model is often easier to read. But you need to remember that many things could happen between the executions of the lines.

Where Java wins: Threads

Fast code is great, but it’s usually more important that the code be correct. Here is where Java’s extra features make sense.

Java’s web servers are multi-threaded. Creating multiple threads may take time and memory, but it pays off. If one thread deadlocks, the others continue. If one thread requires longer computation, the other threads aren’t starved for attention (usually). Most important of all, you—or really your code—is in charge and open to adjustment. Any problems aren’t lost waiting for some call back that never comes like an unrequited Tinder swipe.

If one Node.js request runs too slowly, everything slows down. There’s only one thread in Node.js, and it will get to your event when it’s good and ready. It may look superfast, but underneath it uses the same architecture as a one-window post office in the week before Christmas.

There have been decades of work devoted to building smart operating systems that can juggle many different processes at the same time. Why go back in time to the ’60s when computers could handle only one thread? Yes, dealing with the threads means more work, but you’re tough, right? Sometimes you need to write character-building code to get something that’s great.

Where Node.js wins: Momentum

Yes, all of our grandparents’ lessons about thrift are true. Waste not; want not. It can be painful to watch Silicon Valley’s foolish devotion to the “new” and “disruptive,” but sometimes cleaning out the cruft makes the most sense. Yes, Java can keep up, but there is old code everywhere. Sure, Java has new IO routines, but it also has old IO routines. Plenty of applet and util classes can get in the way.

Node.js is now old enough to have its own cruft larding up the Git repositories, but much of it is decades newer than the Java. The Node.js developers are churning out endless enhancements to web stack software. The energy is still there.

Where both win: Cross-compiling between Java and Node.js

The debate whether to use Java or Node.js on your servers can and will go on for years. As opposed to most debates, however, we can have it both ways. Java can be cross-compiled into JavaScript. Google does this frequently with Google Web Toolkit, and some of its most popular websites have Java code running in them—Java that was translated into JavaScript.

There’s a path in the other direction, too. JavaScript engines like Rhino and Nashorn run JavaScript inside your Java application where you can link to it. If you’re really ambitious, you can link in Google’s V8 engine.

Voilà. All of the code can link to each other harmoniously and you don’t need to choose.

Copyright © 2019 IDG Communications, Inc.

1 2 Page 2
Page 2 of 2
How to choose a low-code development platform