In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what Node.js is for Java developers, the article is very detailed, has a certain reference value, interested friends must read it!
We all know that Node.js is getting all the attention now. Everyone is interested in learning Node.js and wants to work in Node.js. It's always right to understand the concepts behind technology before you start working. But for beginners, they may be confused by the different definitions used by different people. What on earth is Node.js? Is it a new language or a new framework, a new tool or just a simple JavaScript file? Even for experienced Java developers, it is difficult to learn about Node.js quickly. So in this article, I'll try to interpret Node.js for Java developers.
Runtime environment
We know that Java needs a runtime environment called JRE to run Java programs. JRE has a virtual machine called Java Virtual Machine (JVM). 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 JVM, JRE has a series of libraries (for example, rt.jar) to help run Java programs. 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 the source code (.java), which is compiled by the Java compiler into an intermediate code called Bytecode (.class). This Bytecode is provided to JVM for execution on a given target platform. JVM converts the Bytecode into machine code specific to the target platform before execution.
The execution of the Java program can be explained by the following picture:
Web application architecture
A typical Java Web application architecture has four layers: customer layer (Client), presentation layer (Presentation), service / business layer (Service/Business) and data layer (Data).
The client layer (Client layer) can use libraries like jQuery to support AJAX functionality and have some client-side authentication and DOM operations.
The presentation layer (Presentation layer) is usually a layer that interacts with the client layer. This layer usually already implements the MVC pattern for request and response processing. Frameworks such as Spring MVC can be used at this layer. In addition, there is a template engine, such as Velocity, that dynamically renders views based on predefined layouts.
The service or business layer (Service/Business layer) is responsible for having the business logic and communicating with other layers. In the case of an AJAX request, this layer provides data directly to the client layer. This layer performs 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 a SOAP or REST service implementation that uses any framework, such as Spring.
The data layer (Data layer) usually uses some ORM framework, such as Hiberate, or any JDBC-based library / template (Spring JDBC template) to communicate with any RDBMS, such as Oracle.
Architecture deployment
Java Web application architecture deployment includes an Apache HTTP server, which acts as a proxy server and provides static content. Dynamic content is provided by the Web container, which is actually the engine for processing Java files.
The following figure illustrates the architectural deployment of a Java Web application:
How do I understand Node.js?
Runtime environment
The reason we discussed JRE above is to compare it directly with Node.js. Yes, you see it! 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?) The virtual machine of. 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 API or Node Modules, to help run JavaScript applications at run time, similar to the Java library in 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, the open source JavaScript engine from Google. Like Java Virtual Machine, JsVM (V8 engine) 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 was generated before it was provided to JsVM (the 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 can succinctly illustrate the above explanation:
Web application architecture
Node.js-based Web applications mainly follow the Java Web application architecture. The main difference is client request processing. Client requests will be handled by a single thread, but will be handled asynchronously in the case of a Node.js application. With Java, each client request is 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 based on JavaScript.
You can quickly understand the different layers and the frameworks / libraries used in those Node.js application layers from the image below.
The client layer uses Angular.js and 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 stand-alone server for running Node.js applications. The data layer uses an object data modeling module, such as Mongoose.js, to communicate with NoSQL databases such as MongoDB.
This special stack is called MEAN and consists of MongoDB,Express.js,Angular.js, client-side MVC framework, and Node.js (runtime environment).
Architecture deployment
The architecture deployment of Node.js-based Web applications follows Java's Web application deployment architecture. It has a NGINX server that acts like a HTTP proxy server and provides static content. Dynamic content is provided by a Node.js server that contains an engine that processes JavaScript files.
The following figure illustrates the architectural deployment of a Node.js-based Web application:
These are all the contents of the article "what Node.js is to Java developers". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.