1. Introduction to the Java Ecosystem

Many newcomers get caught in "tutorial hell": they read a lot, watch countless videos. This chapter is here to help you break out of your shell and get comfortable with practical programming. You’ll not only learn your way around the development environment, but you’ll also be able to flex your skills by running programs from the command line. In the process, we will get to know our development environment better, be able to run programs from the command line, and see more clearly the division of tasks between the Java compiler and the runtime environment.

Prerequisites

  • Understand the task of Java compiler, bytecode, and JVM

  • Be able to compile Java programs on the command line

  • Know the difference between java and javac programs

  • Set up and be able to operate Java development environment

1.1. Bytecode and JVM

In the early days of Java, the usual way for compilers was to generate a directly executable machine file. Sun Microsystems wanted something different: a platform-independent programming language—this led to Java. To achieve this, the compiler is no longer allowed to generate machine code, but the Java compiler generates bytecode. This bytecode is not bound to a machine. So that the bytecode can be executed, a runtime environment and a function library must exist, called Java Runtime Environment (short JRE). Part of the JRE is the Java Virtual Machine, short JVM, which executes the bytecode.

1.1.1. Porting Java programs ⭐

Anyone starting in programming is bound to have come across a classic: the Hello World output. In the mid-1970s, this small example appeared in a C tutorial and has since been ported to various programming languages. Although the program is small, it serves an important purpose: to test whether all the development tools are installed and working correctly.

Task:

Save the following program named Application.java. Pay attention to the upper/lower case.

Application.java
public class Application {
  public static void main( String[] args ) {
    System.out.println( "Aye Captain!" );
  }
}

We can now compile the program with

$ javac Application.java

and start it with

$ java Application

Question:

  • Would it be possible to copy the file Application.class from a Windows operating system to a Linux operating system and java can run the program?

  • What software must be installed on the computer?

1.2. Tools for Java developers

The choice of development environment often depends on personal taste, they all handle the core tasks well:

This workbook is completely independent of the IDE. All developers should work intensively with the shortcuts, the debugger, and the other tools. The web pages of the developers and YouTube offer plentifully material for it, a small selection:

1.2.1. Get to know error messages of the IDE ⭐

This task is about getting to know the development environment a little better.

Let’s take the following program again:

Application.java
public class Application {
  public static void main( String[] args ) {
    System.out.println( "Aye Captain!" );
  }
}

Task:

  • Transfer Application.java to the IDE.

  • Deliberately build errors into the program code, and observe the error messages. Some suggestions:

    • Change the file name.

    • Change the case, for example, write Class instead of class.

    • The main program is not started until the class has a special method public static void main(String[] args). What happens if the method is not called main, for example, but something else, e.g., Main or run?

    • Try to output Greek letters or hearts, can you do that?

    • White space is often used, so spaces (usually not a tab) and line breaks appear after each statement. Is the following valid like this?

      public class Application{public static void main(String[]args){System.out.println("Aye Captain!");}}.