Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Node.js to Java developers?

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what Node.js is for Java developers". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it to study and learn "Node.js is for Java developers" together!

runtime environment

We know that Java requires a runtime environment called JRE to run Java programs. JRE has a virtual machine called Java Virtual Machine(JVM). The JVM has many components, such as garbage collector (GC), just-in-time (JIT) compiler, interpreter, class loader, thread manager, exception handler, for performing different tasks at different times.

In addition to the JVM, the JRE has a series of libraries (e.g. rt.jar) to help Java programs run at time. We have separate JRE for different platforms such as Windows, Macintosh and Linux, as well as JVM.

Well, just try to remember how to compile and execute a Java program. We have source code (.java) compiled by the Java compiler into an intermediate code called Bytecode(.class). This Bytecode is provided to the JVM for execution on a given target platform. The JVM converts Bytecode into target platform-specific machine code before execution.

Java program execution can be explained by the following picture:

Web application architecture

A typical Java Web application architecture has four layers: Client, Presentation, Service/Business, and Data.

The client layer can use libraries like jQuery to support AJAX functionality and has some client-side validation and DOM manipulation.

The presentation layer is usually a layer that interacts with the customer layer. This layer typically already implements the MVC pattern for request and response processing. Frameworks such as Spring MVC can be used at this level. In addition, there is a templating engine, such as Velocity, that dynamically renders views according to predefined layouts.

The Service/Business layer is responsible for having the business logic and communicating with other layers. In the case of AJAX requests, this layer provides data directly to the client layer. This layer executes the business logic and responds to the presentation layer to update the model. The service layer is a layer that communicates with the data layer to obtain or update the required data. The service layer can have SOAP or REST service implementations using any framework, such as Spring.

The Data layer typically uses some ORM framework such as Hiberate, or any JDBC-based library/template (Spring JDBC template) to communicate with arbitrary RDBMS such as Oracle.

architecture deployment

Java Web application architecture deployments include Apache HTTP servers, which act as proxy servers as well as serving static content. Dynamic content is provided by Web containers, which are essentially engines for processing Java files.

The following diagram illustrates the architectural deployment of Java Web applications:

How do I understand Node.js?

runtime environment

The reason we discussed JRE above is to compare it directly to Node.js. Yes, you see! Node.js is not a language; it is not a framework; it is not a tool. It is a runtime environment for running JavaScript-based applications.

Similar to JRE, Node.js has a JavaScript Virtual Machine(JsVM?) virtual machine. It generates machine code for JavaScript-based applications to enable it on different platforms.

Node.js also has a series of libraries, which may be called Node APIs or Node Modules, to help run JavaScript applications at runtime, similar to Java libraries in the JRE. We have different Node.js requirements for different platforms such as Windows, Macintosh and Linux, as well as JsVM.

JavaScript Virtual Machine is V8, an open source JavaScript engine from Google. Like Java Virtual Machine, JsVM(V8 engine) also has major components such as JIT and GC for task execution, runtime compilation, and memory management, respectively.

Now, let's try to understand how JavaScript programs are compiled and executed. The source code is written in JavaScript(.js). No intermediate code is generated until it is provided to JsVM(V8 engine). JsVM takes this source code directly and compiles it into machine code specific to a given target platform for execution.

The following picture illustrates this explanation in a nutshell:

Web application architecture

Node. js-based Web applications primarily follow the Java Web application architecture. The main difference is client request processing. Client requests will be handled by a single thread, but asynchronously in the case of Node.js applications. With Java, each client request will be processed synchronously by a separate thread, so it is multithreaded.

There are many frameworks/libraries available for Node. js-based Web application development. What's interesting here is that all frameworks/libraries are JavaScript based.

You can quickly understand the different layers and frameworks/libraries used in those Node.js application layers from the following images.

The client layer uses Angular.js, the client-side MVC framework. The presentation layer, as well as the service layer, can be developed using Express.js, a JavaScript-based Web application framework. This also comes with a separate server for running Node.js applications. The data layer uses object data modeling modules (such as Mongoose.js) to communicate with NoSQL databases (such as MongoDB).

This particular stack is called MEAN and consists of MongoDB, Express.js, Angular.js, client MVC framework and Node.js (runtime environment).

architecture deployment

Architectural deployment of Node. js-based Web applications follows Java's Web application deployment architecture. It has an NGINX server that acts like an HTTP proxy server and provides static content. Dynamic content is served by the Node.js server, which contains an engine for processing JavaScript files.

The following diagram illustrates the architectural deployment of a Node. js-based Web application:

Thank you for reading, the above is the content of "Node.js for Java developers", after learning this article, I believe that everyone has a deeper understanding of Node.js for Java developers, and the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report