Walk through options on other languages on JVM besides Java.
- [Instructor] Let's start with the last video of the section, Other Languages on JVM. Previously, we've learned about JVM concepts and Java editions. In this video, we'll understand why we should choose a language, other than Java, for JVM development. We'll discuss the possibility of mixing languages in a single project, and the issues that would be expected. We'll also see writing unit tests in a different language than the one used in the main project. To promote the Java language and platform, Sun published JVM specifications early on.
This document was meant for developers who wanted to write a JVM implementation themselves. Perhaps for platforms that did not have an official JVM implementation available yet. It described which low-level commands JVM can execute, the required data structures, rules when accessing memory, the Java bytecodes.class file format, and much more. While not originally a goal of the developers, the release of these specifications also made it possible for other language writers to experiment with the Java bytecode, and it didn't take long before other languages could compile to their format.
Sun, and later Oracle, liked this development a lot. They liked it so much, Oracle even added new features to JVM, solely to make it easier to support dynamic languages on JVM. Why choose a language other than Java? Since Java is a language originally designed to run on JVM, why would anyone choose another language for JVM development? There are several reasons why a developer would do this. Java is a very verbose language. Not everyone likes statically typed languages, and they're not always the best solution.
Java class library misses some classes for common use cases. Let's learn to mix JVM languages in a project. Many languages offer good interoperability with Java, and therefore, with other JVM languages as well. Languages do this if they use standard Java class library classes, where possible, for their data structures and compile methods, in a similar way as Java would have done. It's not uncommon to have certain classes compiled in different languages in a Java project. One should be aware of the various issues though.
It can complicate the building process a lot. Many languages require their own run time classes, that can cause issues. Let's move on to the next topic, writing unit tests in a different language. It's quite common approach to test Java code with unit tests written in a different language. As we've seen earlier in this section, the code in other languages can be much more compact than the same code in Java, which is ideal for writing small, concrete, and readable unit tests.
Since the language's run time library will only be used while running the unit tests, the language's run time library itself, will only be used while executing the tests, and it will not have to be bundled with the compiled main project. Groovy is especially suited for this use case. It has some convenient features for writing unit tests, including a built-in assert statement that prints very verbose and readable output when the past value is different than the expected output. In this section, we described JVM from a fairly higher level.
We started by looking at what JVM offers to developers, and also focused on popular use cases and the most important JVM concepts. We also have examined the available Java editions. Finally, we covered alternative JVM languages, by looking at several possible reasons why a developer would choose another language than Java for JVM development. In the next section, we'll install a JDK and take a detailed look at it. We'll also cover a Java class library in detail, and install additional development tools to really get going.
- JVM concepts
- Java editions
- Installing JDK
- Running JVM applications on the command line
- Writing Java code
- Creating a web service
- Installing Scala
- Programming in Scala