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

Crafting Software: A Symphony of Understanding and Simplicity

(From experience) In the realm of software development, the journey from concept to creation is an intricate dance between definition, design, and development. Picture it as an art form where the brushstrokes must not only reflect technological prowess but also resonate with human values. Finding the delicate balance between flexibility and rigidity is akin to composing a melody. Too much of either can lead to discord, hindering not only current comprehension but also future understanding and maintenance. It's a harmony that stands the test of time. In this artistic endeavor, the canvas of design becomes our medium to accommodate both the intricacies of technology and the subtleties of human experience. There's no one-size-fits-all logic or paradigm; rather, it's a palette of possibilities. In the world of creating software, let's avoid getting too excited about fancy tech terms, being a fan of just one thing, or acting like the star player. A good team is like a friend

Ui vs api

 In a data-rich engineering web app where GraphQL is used for data retrieval, the time ratio between API development and UI development can vary based on several factors: 1. Data Complexity:If the data structures are complex or have varying relationships, more time might be spent on API development to ensure efficient querying and data retrieval. 2. UI Customization Needs: When the UI requires extensive customization for each section or table, additional time might be allocated to UI development to ensure each component meets specific requirements. 3. Integration Challenges:Bridging the gap between the GraphQL responses and UI components, especially in scenarios where components cannot be easily reused, can significantly impact the time spent on integration efforts. 4. Functionality and User Interactions: If the application involves complex user interactions, form handling, validations, or real-time updates, a considerable amount of time may be dedicated to implementing these features

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 your existin