Skip to main content

Java or Node.js

It depends.

But seriously though.
To decide which one to choose you need to answer to the following question:

What kind of application are you planning to create?


Performance

Node.js and Java memory models differ and this has the most impact for the performance.
Let me explain both models in simplification.
Java model

Java application runs in its own JVM and thus its own process. A process consists of multiple threads.
Threads are like processes with significant differences:

        threads are more lightweight and relatively easy to create
        processes have private set of resources but threads share the memory from its process
        thread can communicate with other threads with ease but processes can communicate with each other by using inter-process communication, which is slower than communication between threads

It means that in Java program job can be divided into multiple threads, which can be executed simultaneously by multiple processors.
This way we can use the full power of the CPUs.

It is very powerful approach, but working with concurrency isn’t easy.
Node.js model

The huge advantage of Node.js is its natural non blocking I/O model. Node.js contain one main thread of execution
and multiple background threads. This background threads perform their tasks in a non-blocking way and are scheduled using a queue
by a main thread.
In this approach all changes are performed in main thread, which means that it is easier to work with, but for the performance cost.
Performance summary

Is that it? Is the only difference that Java can be executed in parallel and Node has non blocking I/O operations?
Not exactly.
Java also have support for non-blocking I/O operations, but it’s not a first class citizen as it is in Node.
Node on the other hand also can be used with parallelism. To do so you need to use `Cluster` library.
This library creates child processes and communicate via IPC (which is slower than communication in Java threads).

As you can see both platforms can handle similar tasks but in favor of Java in case of performance.
Let’s review other aspects which could have an influence on which platform to choose.
Security

Over two decades of improvements Java has has become rock-solid language for secure enterprise apps.
I would consider its strong static typing as a great advantage, especially for a large application.
Thanks to static type we receive error about wrong types during the compilation.
All refactoring could be done with greater confidence. Types serve as a self explaining documentation.

As for Node.js, you can use it with JavaScript or if you want to benefit from static typing you can use TypeScript.
Team performance

By team performance I mean how fast and easy application can be created and maintained.
Verbosity

There is no doubt Java is far more verbose than JavaScript or TypeScript. In Java you have to create classes,
use proper type for any variable user creates, specify getters and setters…
Tooling

Writing code for Node usually means to write code in developers favourite editor without any fancy support.

In Java world you have at least 3 great IDE to choose: IntelliJ, Eclipse, Netbeans. Each one of these
contains a great amount of functionality, which makes a life of a developer a lot easier, eg:

    language support
    smart completion
    inspections and quick-fixes
    code navigation
    class hierarchy view
    refactoring shortcuts
    debugger integration with view
    test runners
    decompilers
    build-in tools (version control, build tools)

Mastery an IDE highly improves productivity and joy of work.
Isomorphism

This point is dedicated to JavaScript.
One of the advantage of using Node both on client and server side can share common code and libraries.
Situation where part of the business logic has to be moved from client to server (or in the opposite direction)
is much easier to handle when code is written in the same language.

Also in Node you don’t have problems with JSON which is widely used in services communication and in a way data are stored in some
NoSQL databases like mongoDB.
Summary

There is no Holy Grail of a programming stack. Each stack should be chosen according to requirements.
In base case scenario a rule of thumb might be to pick Java for larger projects and with heavy processing.
There is a chance for a compromise. In an era of micro services, some jobs could be delegated to services written in Java
and some delegated to services written in Node.js.

For each problem proper approach should be applied.
Don’t follow the buzzwords. Rely on facts and experts opinion.
If you have an idea for an app and still hesitate on a backend stack – write to us. We will help you to choose
optimal tools to complete resilient apps.
If you can’t decide on a frontend side stack you can read this great article,  by Mateusz C.,
where he is comparing 2 major frontend frameworks Angular and React.
Well… actually, one of them is not a framework. But to find out which one and why, you need to read it.

[courtesy: Mateusz Piotrowski  https://www.futurum.tech/blog/index.php/2018/02/22/java-or-node-js/]

Comments

Popular posts from this blog

Caged engineer, but the creative

 The journey of a software engineer is a complex and often underappreciated saga. They start as programmers, mastering the intricacies of code, but their role quickly expands far beyond just writing lines of logic. In reality, a dedicated developer ends up wearing many hats—business analyst, architect, troubleshooter, deployment expert, and sometimes even a therapist for systems and people alike. Despite their best efforts, developers often find themselves at the receiving end of blame when things go wrong. End users might complain about a feature not working as expected, the business team might point out gaps between requirements and reality, security might flag issues that slipped through the cracks, and operations might raise alarms over performance bottlenecks. Yet, when it comes time to find a solution, all eyes turn to the developer. In the software lifecycle, any bug, oversight, or delay typically falls on the developer's shoulders. Even when the root cause lies in infrastru...

Micro Front and ui frameworks

 To mix technologies in a micro front-end architecture, where different parts of the application use different frameworks or libraries, there are several ways to approach this, and the technologies you mentioned—Astro, Nuxt, Next, and Vite—can play a role. Here's how you can mix them, along with new approaches to micro front-end architecture:  Micro Front-End Architecture Overview Micro front-ends involve breaking a frontend application into smaller, independent pieces (micro-apps), where each micro-app can be developed, deployed, and maintained separately. These micro-apps can use different technologies (React, Angular, Vue, etc.) and are usually stitched together by a wrapper or container that manages the composition and communication between them.  Approaches to Micro Front-Ends with Modern Tech  1. Module Federation (Webpack 5)    - How it works: Module Federation allows multiple independent builds to dynamically share code. You can create different mic...

Team is the culture

 In the fast-paced world of modern technology, where innovation and collaboration were the lifeblood of success, a tale of transformation emerged, driven by the power of unity and positive change. In the heart of a bustling tech company, a team of skilled professionals worked tirelessly to bring their projects to life. However, an undercurrent of bossy culture and minor office politics threatened to cast a shadow over their enthusiasm and camaraderie. Amidst the whirlwind of deadlines and complex problem-solving, tensions simmered under the surface. A bossy culture, where authoritarian leadership overshadowed open communication, cast a pall over the team's potential. Minor office politics, like stealthy specters, attempted to sow discord and division among colleagues who once shared dreams and aspirations. However, in the face of these challenges, a whisper of change began to stir. It started with a few individuals who refused to succumb to the negativity. A senior engineer named M...