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

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...

AWS and languages

Amazon Web Services (AWS) provides a wide range of services and tools, many of which are built using Java. Java is one of the primary programming languages used at AWS for developing various components. AWS is a platform that provides cloud services for organizations of all sizes. In particular, AWS uses Java to provide the platform’s core functionality, such as computing and storage. Java is a popular programming language that allows developers to create software applications. Furthermore, AWS also uses other languages, such as Python and Ruby, to provide specific features How is Java used in AWS applications? A huge number of open-source big data offerings are written using the Java programming language. It’s massively popular with AWS customers and cloud specialists because it’s just so easy to write, compile, debug and learn.   Using Java, developers can create both modular programs and reusable code meaning you can deploy you...

Let's question ourselves

 The responsibility of technology to stabilize and develop society and humanity is multifaceted. Here are some key aspects: 1. Ethical Design:Technology should be designed with ethical considerations, ensuring it doesn't harm individuals, communities, or the environment. This includes avoiding biases in AI algorithms and promoting user privacy. 2. Accessibility:Technology should be accessible to all, regardless of their economic, social, or physical backgrounds. This helps prevent further societal disparities. 3. Education: Promoting digital literacy and tech education is crucial. Ensuring that individuals can understand, navigate, and use technology empowers them in the modern world. 4. Innovation for Good: Technological innovation should focus on solving real-world problems, from healthcare to environmental issues, contributing to societal well-being. 5. Sustainability: Technology should be developed in ways that minimize its environmental impact. Sustainable practices, from desi...