Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Chapter 1. Java Virtual MachineJava Virtual Machine (JVM) is a modern platform on which you can develop and deploy software. As the name implies, it was originally created to power applications written in the Java language. However, it didn't take language designers long to realize that they could not only run their languages on JVM, but also take advantage of its features and extensive class library.Sun Microsystems released Java and the first JVM implementation in 1995. With its focus on Internet applications, Java quickly became popular. It was also designed from the ground up to run anywhere. Its initial goal was to run on set-top boxes, but when Sun Microsystems found out the market was not ready at that time yet, they decided to bring the platform to desktop computers as well. To make all those use cases possible, Sun invented their own binary executable format and called it Java bytecode. To run programs compiled to Java bytecode, a JVM implementation must be installed on the sy
Chapter 1. Java Virtual Machine
Chapter 2. Developing on the Java Virtual MachineIn this chapter, we will take an in-depth look at a Java Virtual Machine (JVM). We will focus on concepts that every JVM developer should know, regardless of the chosen programming language. This is what we will cover in this chapter:Java Development Kit (JDK)Class organization with packages Java Class LibraryRunning JVM applications on the command lineInstalling the Eclipse Integrated Development Environment (Eclipse IDE)While this book covers Windows, macOS, and Linux (Ubuntu) operating systems, paths will often be shown in Windows style only. When using macOS and Linux systems, be sure to rewrite the paths using the rules of your operating system.
Chapter 2. Developing on the Java Virtual Machine
Chapter 3. JavaWhile exploring the JVM and JDK concepts in the previous chapters, we looked at quite a bit of Java code. Source code written in Java is generally easy to read and comprehend. It started out as a relatively simple language to learn. As more and more features were added to the language over the years, its complexity increased somewhat. However, good news is that beginners don't have to worry about the more advanced topics too much until they are ready to learn them. Programmers that want to choose a JVM language other than Java can still benefit from this chapter, especially once they start using libraries or frameworks that provide Javadocs as API documentation. As we will see soon, Javadoc is a tool provided with the JDK that generates HTML documentation based on some special comments in the source code. Many libraries and frameworks provide the HTML documents generated by Javadocs as part of their documentation.These are the topics we will discuss in this chapter:Obje
Chapter 3. Java
Chapter 4. Java ProgrammingWith a lot of theory behind us, let's write a real Java program. We will write a simple standalone web service that will count the frequency of each character that was used in the passed input string and return this in a JSON dictionary. We will use the Gradle build tool to automatically fetch dependencies from the internet and then build and run the project. At the coding stage of the backend class, we will use a test-driven approach and write unit tests along the way. In every step, from the coding stage to running the final web service, we will use Eclipse IDE. In the end, we'll discuss various shortcuts to ensure you are as productive as possible. We'll cover the following topics:Configuring Eclipse IDECreating a new Gradle-based project in Eclipse IDEModifying the Gradle build scriptBuilding the projectCoding the backend classCreating unit tests to test the backend classWriting a web serviceRunning a web service
Chapter 4. Java Programming
Chapter 5. ScalaScala is a unique language. It has strong support for functional programming and is also a pure object-oriented programming (OOP) language at the same time. We will cover both OOP and functional programming in this chapter. The Scala installation offers two ways of running Scala code. It offers an interactive shell where the code can be directly entered and run right away. This program can also be used to run Scala's source code directly, without manually compiling it first. Also, it offers scalac, a traditional compiler that compiles Scala's source code to Java bytecode and generates files with the .class extension. This chapter will only focus on the first method; the next chapter will cover the scalac compiler.Scala comes with its own Scala standard library. It complements the Java Class Library that is bundled with the Java Runtime Environment (JRE) and installed as part of the Java Development Kit (JDK). Scala's standard library contains classes that are optimiz
Chapter 5. Scala
Chapter 6. Scala ProgrammingIn this chapter, we are going to do a small project in Scala, using the popular Akka toolkit. Akka is a toolkit that aims to make the creation of scalable applications on a JVM easier. It is available for both Java and Scala, but since it was built by the creators of Scala, Akka is an excellent fit for Scala.We will build a simple program that will display a random quote from a hardcoded list of quotes. Akka is based on the Actor model, which we will explore in this chapter. To write the project we will use Scala IDE, which is available both as a standalone software package and as a plugin that could be installed on Eclipse IDE. We will use the latter. To build the project, we will use the Scala build tool. These are the topics that we will cover in this chapter:Scala IDE for EclipseScala Build Tool (SBT)SBT Eclipse for the SBT pluginThe scalac compilerThe Akka toolkitUnit testing with ScalaTestWriting an executable main program
Chapter 6. Scala Programming
Chapter 7. ClojureClojure is a language that is rather different from the other languages covered in this book. It is a language largely inspired by the Lisp programming language, which originally dates back to the late 1950s. Lisp stayed relevant by being up to date with both technology and times. Common Lisp and Scheme are arguably the two most popular Lisp dialects in use today. Clojure is a dialect of Lisp, but its design is influenced by both.Unlike Java and Scala, Clojure is a dynamic language. Variables do not have fixed types and when compiling, no type checking is performed by the compiler. When a variable is passed to a function that is not compatible with the code in the function, an exception will be thrown at runtime. What's also noteworthy is that Clojure is not an object-orientated language (OOP), unlike all the other languages in this book. Clojure still offers interoperability with Java and JVM, as it can create instances of objects. And, as we will soon see, it ca
Chapter 7. Clojure
Chapter 8. Clojure ProgrammingIn the previous chapter, we covered how to program Clojure by entering code directly in its REPL. While this works well, even for smaller projects, having the code placed in multiple source files is a must. Writing projects is the main focus of this chapter, and we will use Eclipse IDE again for writing code, thanks to the Counterclockwise plugin that adds Clojure compatibility to Eclipse IDE. The most popular build tool for Clojure projects is called Leiningen, and we will use it a lot during the course of this chapter. We will build two projects. One project will focus on monads, which are used a lot in functional programming languages. We will explore this subject by applying test-driven development. We will also create a very simple web application using Luminus, a popular micro web framework for Clojure. Here's a list of what we will cover in this chapter:The Counterclockwise plugin for Eclipse IDELeiningen's build toolCreating executable progra
Chapter 8. Clojure Programming
Chapter 9. KotlinKotlin is a language that is designed by JetBrains. JetBrains is the company behind popular IDEs for a wide variety of languages, including Java (IntelliJ), Python (PyCharm), PHP (PhpStorm), and many others. Their IDEs are offered in both commercial and a free community edition (which often has fewer features but is still very usable). Kotlin is, like Java, a statically typed language that is orientated towards object-oriented programming (OOP), but it also allows procedural programming. Like many modern OOP languages, it has many features inspired by functional programming. We'll cover the following topics here:Installing KotlinKotlin's Read-Eval-Print-Loop interactive shellKotlin language fundamentalsOOP in KotlinProcedural programming in KotlinStyle guideQuiz
Chapter 9. Kotlin
Chapter 10. Kotlin ProgrammingIn this chapter, we are going to write a small desktop GUI application in Kotlin using the JavaFX toolkit. While we mostly used Kotlin's REPL in the previous chapter, we will now be using the Eclipse IDE again for writing code. Just as was the case with both Scala and Clojure, we will need to install a plugin to do this. As this plugin is available in the Eclipse Marketplace, the installation process is a breeze.As a build tool, we will be using Apache Maven, a build tool that was originally created for Java but can be extended with plugins to support other languages, such as Kotlin. It builds projects by reading an XML file that defines all dependencies and plugins to use during different phases and goals of the building process. We'll use a preconfigured template provided by the Kotlin team as the template for this project. Here's the list of topics that will be covered:Kotlin for the Eclipse IDE pluginApache MavenCreating a JavaFX desktop GUI applicati
Chapter 10. Kotlin Programming
Chapter 11. GroovyGroovy is one of the earlier alternative JVM-based languages. It was originally built to provide a Python-like experience on the JVM, a marvel and an unheard of idea at the time. At its heart, it is a dynamically typed language, meaning that types do not have to be specified when declaring variables, and method calls are resolved at runtime instead of compile time, which add interesting possibilities that will be hard to implement in static languages, such as Java and Kotlin. Groovy is highly unusual, as the programmer can switch the compiler to a statically typed mode for specific classes. In this mode, the compiler checks the types and method calls at compile time, like the compiler of a statically typed language would have done.The following topics will be covered in this chapter:Installing GroovyThe GroovyConsole and GroovyShell REPL shellsGroovy language basicsObject-oriented programmingThe Groovy Development Kit (GDK)Dynamic and static programmingQuiz
Chapter 11. Groovy
Chapter 12. Groovy ProgrammingWe are going to build a simple web service in Groovy using the popular Vert.x microservice framework. Our program will make use of the H2 Database Management System (DBMS), a database system that is fully written in Java. We will use the Java Database Connectivity (JDBC) standard to interact with H2. XML will be generated using Groovy's MarkupBuilder, a class that is offered in the Groovy Development Kit (GDK), Groovy's runtime library.This time, we will not use an external build tool responsible for building the project; instead, we'll let the Eclipse IDE handle this job for us. We will be needing some external dependencies (to use the mentioned H2 and Vert.x open source projects) and will use Apache Ivy for this. The Eclipse IDE does not come with Groovy support out of the box, so we need to install a plugin for this language as well. The following topics will be covered in this chapter:Installing the Groovy Eclipse pluginApache Ivy and IvyDE plugin for
Chapter 12. Groovy Programming
Chapter 13. Other JVM languagesThere are way more languages that run on the JVM than the ones that were discussed in the previous chapters. In this appendix, we will take a quick look at some of the other languages. Most of these are custom JVM implementations of popular mainstream programming languages, such as JavaScript, Python, Ruby, and Haskell. The following are the implementations of languages that we will discuss here:Oracle Nashorn (JavaScript)Jython (Python)JRuby (Ruby)Frege (Haskell)Ceylon
Chapter 13. Other JVM languages
Chapter 14. Quiz Answers
Chapter 14. Quiz Answers
Chapter 3: Java
Chapter 5: Scala
Chapter 7: Clojure
Chapter 9: Kotlin
Chapter 11: Groovy
← Prev
Back
Next →
← Prev
Back
Next →