In this blog post I will explain some features of Java that in my opinion make it better than JavaScript. Later I will also write a blog post “10 Reasons why JavaScript is better than Java”
1. The Java VM is more advanced than the JavaScript VM
The first thing is, that there are mulitple Java VMs and JavaScript VMs. The major Java VM is Oracle Hotspot and the currently most hyped one for JavaScript is Google V8. The fun thing is that you can run Java on V8 e.g. by using Doppio or you can run JavaScript in the Java VM e.g. by using Nashorn.
So here is a small table what is supported in the Java VM which is not supported by the most advanced JavaScript Engines.
Feature | Java Oracle HotSpot | Google V8 |
---|---|---|
Just-In-Time Compiling | X | X |
Advanced Identification of Hot-Spots | X | O |
Parallel Garbage Collector with Real Time Configuration | X | O |
Advanced Monitoring Tools | X (e.g. JVisual VM and Java Mission Control) | O |
Debugger and Profiler | X | X |
2. Java has far more packages
Maven central has currently 1,330,090 indexed artifacts compared to 27,066 on bower.io. I will do the math for you. Java has around 50 times the amount of open source packages compared to JavaScript. The even more important thing is that maven central is write once and only signed artifacts are allowed. Once an artifact is uploaded it can’t be changed and revoked.
This happend to npm. A developer revoked around 30 packages and a lot of builds broke.
3. Java can be refactored better because it is statically typed
Java IDEs like IntelliJ, Eclipse or NetBeans are always analyzing your code and are building an AST. This can be used to give you direct feedback if you made something wrong. Further it supports advanced refactoring like:
- Rename variable
- Extract interface
- Generate getters and setters
- Introduce paramter object
- etc.
Especially in large projects these techniques are required for maintaining the code base.
4. Java has more effective auto completion
When browsing a new library the IDEs can directly analyse them. Typically they can download the source from maven central and auto complete the different function calls. Normally the libraries are well documented to the documentation is shown as well.
When debugging you can step into a function and automatically see the code of your dependency.
5. Java has multiple application servers you can choose from
In JavaScript there is currently a big hype around node. Actually one of the first web servers Netscape Enterprise Server contained Livewire. This was a JavaScript on the server side implementation.
When using Java EE there are multiple servlet containers or full blown application servers you can choose from e.g.:
- Tomcat or TomEE
- Wildfly
- Payara
- SAP NetWeaver
- around 20 others etc.
This make the investment saver because it is not necessary to rely on one party. You can even execute JavaScript on all these Java server because Scripting is build into Java by default: JSR 223: Scripting for the JavaTM Platform.
6. Java can be better tested
The JUnit framework and mockito framework including IDE support for them makes it very convenient to write test code. Further libraries like Arquillian make integration tests more automated.
7. Java has better build tools
With maven and gradle Java has the 2 best build tools in the world. They:
- Download dependencies
- Compile the code
- Execute unit test case
- Generate test reports optionally including coverage
- Can download and set up whole application servers
- Run integration test cases
- Generate documentation
- Check against code quality metrics
- Deploy artifacts
The most advanced continuous integration system Jenkins is written in Java and maven projects are a first class citizen in the Jenkins world.
8. Java can use system resources more efficiently
With JNI it is possible to directly access system resources and there are multiple abstraction layers to directly access hardware like JOGL for OpenGL or USB4Java.
9. Java can use all CPUs
Java was always able to use threads. In Java 8 the concurrency behavior was a lot enhanced and the usability of the APIs is easy. It is possible to:
- Manage thread pools
- Use streams to e.g.
- Run paralleled sorting
- Run parallized mapping
- Run parallized reducing
10. Java has more literature
A lot of advanced books use Java in their examples e.g.:
- Working effectively with legacy code
- Clean Code: A Handbook of Agile Software Craftsmanship
- Design Patterns: Elements of Reusable Object-Oriented Software
Conclusion
Java has currently still some advantaged over JavaScript. Especially on the server. Nevertheless we have to observe closely how the market and the technology is developing.
Leave a Reply