What’s Java Digital Machine?
A Java virtual machine is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode.
Now the question arises how can Java Virtual Machine run programs written in other languages? Let us have a look into this by the help of a diagram.
Various Programming Languages for JVM
The supply code written in java will get compiled into software bytecode with the assistance of java compiler. The bytecode then runs within the java runtime that consists of the Normal libraries and Java Digital Machine.
Now from the diagram we are able to see that the precise hand aspect and the left hand aspect of the diagram are carefully linked collectively. However the reality is that the precise hand aspect of the diagram, the runtime stack, is able to working the bytecode irrespective of from the place this bytecode comes from. Largely the bytecode is compiled from the java supply code, however individuals began creating alternate options of java languages that may compile to java bytecode and therefore can run on the identical digital machine.
Probably the most generally various programming languages used to acquire the java bytecode:
Even though these are different programming languages having different compilers, but compiling the source code written in these languages results in the same bytecode that can run on the Java Virtual Machine. These languages can make use of the Java Standard Libraries and can also take advantage of the Java Virtual Machine like speed and safety.
Causes behind selecting various JVM languages
What are the reasons for choosing programming languages other than java for JVM, when java is the main language of the platform. Some of the reasons behind this:
- Productiveness: Java is a programming language that has advanced since twenty years and likewise we all know that java is optimized for readability. Some individuals consider in programming languages which can be extra to the purpose, in order that there groups could be extra productive utilizing these languages.
- Familiarity: Not each individual is aware of program in java language. Additionally there may be quite a lot of present languages like Python and Ruby that too have similar implementation as Java. On this case individuals who know these languages can get information of the JVM variations of these languages like JPython and JRuby with out studying a brand new programming language.
- Completely different Programming Paradigm: Not solely object oriented programming languages are gaining fame but additionally useful programming have gotten well-liked. There are a number of different programming languages which can be adopting new programming paradigm as nicely.
These are some the explanation why individuals select alternate languages whereas staying in Java Digital Machine. When individuals don’t wish to code in java language, they will select totally different language fairly than altering the platform. Additionally due to these various JVM languages and their concepts, java has adopted numerous adjustments as nicely.
Some Various JVM Languages
Allow us to have a quick look on the three main JVM various languages:
Groovy is a widely used JVM alternative language. It is a dynamic scripting language for JVM, which means the code written in groovy is interpreted at runtime rather than compiling it beforehand. Groovy is similar to Python and Ruby programming languages. Nevertheless, you can also compile the groovy code in bytecode using a groovy compiler. As interpreting the groovy code at runtime is quite slow, hence compiling the code usually results in better performance.
As we know Java is statically typed language, that means, we have to provide types for all the parameters which we are using in our code. However, in groovy we don’t have to provide all this, which makes the language more dynamic. Later groovy got an opt-in type system, in which the developer can optionally add a type annotations to the code and then these annotations can be used by the groovy compiler to find out the type related problems at the compile time in the code.
The groovy language is more to the point than java but the syntax could be very near that of java.
Scala is a programming language which combines object oriented programming language with procedural programming language, which Scala a very different language from java. Scala offers both functional programming features and advanced object oriented programming language features.
Scala is complied languages, the Scala compiler compiles the Scala source code into Java bytecode. Scala is statically typed language same as Java. Although Scala has a more extensive type system than Java so as to support both the functional programming features and advanced object oriented features.
The Akka (is a free and open-source toolkit and runtime simplifying the construction of concurrent and distributed applications on the JVM) library for concurrency and the Apache Spark library for big data processing are both written in Scala.
With its advanced object oriented features and functional programming features Scala can be great to work with. but, on the other hand, Scala is considered to be complex as well, as the compiler can be quite slow on some larger code bases because of the features the language is having.
Kotlin came into existence after Scala and also a recent addition to the set of JVM languages. Kotlin is developed by Jetbrains (same company that creates IntelliJ, the java IDE) and is supported by Google.
Kotlin does not relies on backward compatibility (refers to a hardware or software system that can successfully use interfaces and data from earlier versions of the system or with other systems) as java does, so the developers can choose the best ideas from the JVM only. Kotlin is interoperable with the Java, that means, whenever two java and kotlin files exist together they can share data with each other.
These three are the majorly used various JVM languages, there are dozen of languages as nicely that can be utilized as alternate options.