Polyglot programming

Polyglot programming is the technique when there are different programming languages used in the same application. Such an approach is not only appropriate when a different part of the application runs on a different environment. For example, the client executes in the browser using JavaScript, CSS, and HTML while the server is programmed to run in a Tomcat environment in Java. This is a different story, and, usually, this is not the typical use when someone is speaking about polyglot programming.

When the application that runs on the server partially runs in Java and also in some other language, then we can speak about polyglot programming. For example, we create the order handling application in Java and some of the code that checks the correctness of the order based on the product-specific codes that the order contains is written in JavaScript. Does it ring a bell? We have already done that in this book to demonstrate the scripting API of the JDK. That was real polyglot programing even if we did not mention it that way.

The JVM that runs the compiled Java code is a very good target for different language compilers, and thus, there are many languages that compile for it. When the JVM runs the byte code of a class, it does not know what the source language was, and it does not really care; some compiler created the byte code and it just executes that.

We can use different languages, such as Jython, Groovy, and Scala, to name a few popular ones that compile for the JVM. We can write one class using one language and the other one using another. When they are put together into a JAR, WAR, or an EAR file, the runtime system will just run them.

When do we use polyglot programming?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.135.249