Book Image

Introduction to JVM Languages

By : Vincent van der Leun
Book Image

Introduction to JVM Languages

By: Vincent van der Leun

Overview of this book

Anyone who knows software development knows about the Java Virtual Machine. The Java Virtual Machine is responsible for interpreting Java byte code and translating it into actions. In the beginning, Java was the only programming language used for the JVM. But increasing complexity of the language and the remarkable performance of the JVM created an opening for a new generation of programming languages. If you want to build a strong foundation with the Java Virtual Machine and get started with popular modern programming languages, then this book is for you. The book will begin with a general introduction of the JVM and its features, which are common to the JVM languages, helping you get abreast with its concepts. It will then dive into explaining languages such as Java, Scala, Clojure, Kotlin, and Groovy and will show how to work with each language, their features, use cases, and pros and cons. By writing example projects in those languages and focusing on each language’s strong points, it will help you find the programming language that is most appropriate for your particular needs. By the end of the book, you will have written multiple programs that run on the Java Virtual Machine and know about the differences between the various languages.
Table of Contents (21 chapters)
Title Page
About the Author
About the Reviewer
Customer Feedback

Scala's standard library

Now that we have discussed OOP thoroughly, let's start writing classes and methods that do something useful. Part of the Scala installation is the Scala standard library, a big library of classes that is unique to Scala. We will discuss the following topics here:

  • Generics
  • Collections
  • XML processing


Java used the ClassName<T> notation for generics-aware classes. As we have seen, some classes, such as the Map<K, V> interface, requires more types. For Map, types need be specified for both the keys and the corresponding values that the map will hold.

In Scala, the ClassName[T] notation is used instead:

    val aList = List[Int](1, 2, 3, 5)

This creates an immutable list with five elements. Since List[Int] is specified, adding an instance of any type other than Int or an instance of a class that cannot be upcast to Int is not allowed.

Similarly, when a class requires two types, it is written as:

    val m = Map[String, String]("key1" -> "value1", "key2"...