Java is strong in computing.
Node is strong in IO, and it is also a js stack, which is more friendly to the front end. But when the application becomes complex, the front end needs to handle the controller, and Java can do its job of interface service.
On the other hand, node, as the middle layer, can also reduce the differentiated cost of heterogeneous systems to a certain extent with its asynchronous characteristics.
Answer the original poster’s question.
1. Why is nodejs only suitable for the middle layer?
You might as well change your thinking, what will happen if nodejs is used as the business layer and data layer? I used pure nodejs to make applications, and found that the business logic layer was too difficult to write. Due to the inherent language flaws of nodejs, when complex logic encounters a bunch of callbacks, the code is simply unreadable, even if libraries such as promises are used. There is no way to completely make up for this shortcoming. Large-scale website architecture attaches great importance to maintainability. If the code readability is low, the maintainability will naturally be low.
2. Why can’t Java shake its status?
The positioning of the two is inherently different, why should they be replaced? The existence of two languages does not necessarily have to be a life-and-death struggle. Large-scale IT projects are often a combination of multiple languages and learn from each other's strengths. Complex business logic is done in Java, and nodejs is used to handle some routing mapping and parameter verification. Front-end engineers can also partially participate in back-end engineers. work, so the project scalability is actually better.
The characteristics of node or js (single-threaded, asynchronous, weak type) determine that it is more suitable for doing simple things quickly. You don’t need to consider many underlying things, do not need to consider data type conversion, and do not need an application server at all. Make an application soon. But when the application becomes large, some problems will be exposed. Not talking about efficiency here, just in terms of code maintainability, it is much worse than Java. Relatively speaking, Java has more restrictions and stricter syntax, but these restrictions determine that Java programs will have a more consistent style and are easier to read and maintain.
So generally speaking, node will not be used to implement more complex business logic. Object-oriented languages, such as Java, have strong capabilities in controlling business.
Moreover, Java became popular much earlier than node. Many domestic commercial companies, including banks, have their business systems implemented in Java. In this regard, these companies have accumulated a lot of experience and invested a lot of resources. Even if their business is more suitable for using node, it will gradually replace Java instead of completely. For example, first use node to implement routing and rendering. The project I'm working on now is similar to this.
But none of the above is constant. There is no doubt that good node programmers can write better applications than bad java programmers. As one of my colleagues said, Java can guarantee the bottom line of the program because it itself has many mandatory principles, and there is also a lot of object-oriented knowledge such as design patterns for reference. But node has no upper limit, and at the same time, there is no lower limit.
Looking at the communities of the two, in another 3 years, the answer to this question will be completely different. Language is not the key, the key is people. People who are active in the community and talents are the foundation of creation. In fact, js, a language that everyone thinks is a toy, did not expect to reach this point.
The biggest advantage of Node.JS is asynchronous, but callbacks increase the complexity of programming, and JS does not have good object-oriented support.
Nodejs is suitable for simple business, such as based on HTTP API interface. On the contrary, if you use it to build a BOSS (Business. Operation Support System, business content support system), it seems a little thin. Another example is that some memory-resident tasks, such as message queue tasks, can also be done with nodejs, but it feels too awkward. At this time, I still feel that Java is better.
Of course, the advantage of nodejs is its high development efficiency, which is more suitable for some companies with relatively single business scenarios.
In short, the selection of programming language is linked to the company's business, and the specific situation must be analyzed in detail.
Because your question is too simple and crude: nodejs is a platform, and java is a language. There is no direct comparison between the two, not to mention that the meaning of the middle layer is not clearly stated, so there is definitely no chance of shaking;P
Let me give you a simple and crude answer: nodejs is equivalent to ASP.NET without IDE, it is just light and fast. Compared with PHP and the like, it is not bad. Forget about Java, it is not the same type at all. tool. Moreover, the Java ecosystem is more open (although there is Oracle), which is better than Joyent playing alone.
Nodejs feels like it is designed for the development of the front-end towards the full stack. Java has more history, development is stable and rapid, and there are many open source frameworks.
nodejs --> V8 --> C++ explanation --> Compile machine code java --> JVM C++ explanation --> Compile machine code
Theoretically, you can do anything that Java does. In fact, there are no specific settings for numbers and characters in JS, which takes up more memory. When performing calculations, it is not as efficient as Java. Although Java does specific Differentiation between numbers and characters, but requires virtual machine and garbage memory detection, the performance is much lower than C++ and C.
nodeJs has high concurrency, is more flexible, and java is more stable! ~~
Java is strong in computing.
Node is strong in IO, and it is also a js stack, which is more friendly to the front end. But when the application becomes complex, the front end needs to handle the controller, and Java can do its job of interface service.
On the other hand, node, as the middle layer, can also reduce the differentiated cost of heterogeneous systems to a certain extent with its asynchronous characteristics.
Answer the original poster’s question.
1. Why is nodejs only suitable for the middle layer?
You might as well change your thinking, what will happen if nodejs is used as the business layer and data layer? I used pure nodejs to make applications, and found that the business logic layer was too difficult to write. Due to the inherent language flaws of nodejs, when complex logic encounters a bunch of callbacks, the code is simply unreadable, even if libraries such as promises are used. There is no way to completely make up for this shortcoming. Large-scale website architecture attaches great importance to maintainability. If the code readability is low, the maintainability will naturally be low.
2. Why can’t Java shake its status?
The positioning of the two is inherently different, why should they be replaced? The existence of two languages does not necessarily have to be a life-and-death struggle. Large-scale IT projects are often a combination of multiple languages and learn from each other's strengths. Complex business logic is done in Java, and nodejs is used to handle some routing mapping and parameter verification. Front-end engineers can also partially participate in back-end engineers. work, so the project scalability is actually better.
The characteristics of node or js (single-threaded, asynchronous, weak type) determine that it is more suitable for doing simple things quickly. You don’t need to consider many underlying things, do not need to consider data type conversion, and do not need an application server at all. Make an application soon. But when the application becomes large, some problems will be exposed. Not talking about efficiency here, just in terms of code maintainability, it is much worse than Java. Relatively speaking, Java has more restrictions and stricter syntax, but these restrictions determine that Java programs will have a more consistent style and are easier to read and maintain.
So generally speaking, node will not be used to implement more complex business logic. Object-oriented languages, such as Java, have strong capabilities in controlling business.
Moreover, Java became popular much earlier than node. Many domestic commercial companies, including banks, have their business systems implemented in Java. In this regard, these companies have accumulated a lot of experience and invested a lot of resources. Even if their business is more suitable for using node, it will gradually replace Java instead of completely. For example, first use node to implement routing and rendering. The project I'm working on now is similar to this.
But none of the above is constant. There is no doubt that good node programmers can write better applications than bad java programmers. As one of my colleagues said, Java can guarantee the bottom line of the program because it itself has many mandatory principles, and there is also a lot of object-oriented knowledge such as design patterns for reference. But node has no upper limit, and at the same time, there is no lower limit.
Looking at the communities of the two, in another 3 years, the answer to this question will be completely different. Language is not the key, the key is people. People who are active in the community and talents are the foundation of creation. In fact, js, a language that everyone thinks is a toy, did not expect to reach this point.
The biggest advantage of Node.JS is asynchronous, but callbacks increase the complexity of programming, and JS does not have good object-oriented support.
Nodejs is suitable for simple business, such as based on HTTP API interface. On the contrary, if you use it to build a BOSS (Business. Operation Support System, business content support system), it seems a little thin. Another example is that some memory-resident tasks, such as message queue tasks, can also be done with nodejs, but it feels too awkward. At this time, I still feel that Java is better.
Of course, the advantage of nodejs is its high development efficiency, which is more suitable for some companies with relatively single business scenarios.
In short, the selection of programming language is linked to the company's business, and the specific situation must be analyzed in detail.
Because your question is too simple and crude: nodejs is a platform, and java is a language. There is no direct comparison between the two, not to mention that the meaning of the middle layer is not clearly stated, so there is definitely no chance of shaking;P
Let me give you a simple and crude answer: nodejs is equivalent to ASP.NET without IDE, it is just light and fast. Compared with PHP and the like, it is not bad. Forget about Java, it is not the same type at all. tool. Moreover, the Java ecosystem is more open (although there is Oracle), which is better than Joyent playing alone.
Nodejs feels like it is designed for the development of the front-end towards the full stack. Java has more history, development is stable and rapid, and there are many open source frameworks.
nodejs --> V8 --> C++ explanation --> Compile machine code
java --> JVM C++ explanation --> Compile machine code
Theoretically, you can do anything that Java does. In fact, there are no specific settings for numbers and characters in JS, which takes up more memory. When performing calculations, it is not as efficient as Java. Although Java does specific Differentiation between numbers and characters, but requires virtual machine and garbage memory detection, the performance is much lower than C++ and C.