Five phrases to create and execute Java application

Five phrases to create and execute Java application

prerequisite knowledge

  1. There are three general types of programming languages:

    1. machine languages: strings of 1s and 0s
    2. assembly languages: translator programs called assemblers translate assembly language to machine language
    3. high-level languages: translator programs called compilers translate high-level language to machine language
  2. Compiling a large high-level language program into machine language can take considerable computer time. Interpreter programs are developed to execute high-level language programs directly, avoid the delay of compilation, although they run slower than compiled programs. Java uses a clever performance-tuned mixture of compilation and interpretation to run programs.

  3. Virtual machine(VM) is a software application that simulates a computer but hides the underlying operating system and hardware from the programs that interact with it.

Five phrases to create and execute Java application

  1. edit: Edit source code, for example: HelloWorld.java
  2. compile: The Java compiler translates Java source code into bytecodes, i.e, javac HelloWorld.java. IDEs typically provide a menu such as Build or Make to invoke the javac command for you.
  3. load: JVM places the program in memory to execute it – this is known as loading. The JVM’s class loader takes the .class files containing the program’s bytecodes and transfers them to primary memory(RAM). The .class files can be loaded from a disk on your system or over a network.
  4. verify: Bytecode verification. As the calsses are loaded, the bytecode verifier examines their bytecodes to ensure that they’re valid and do not vilate Java’s security restrictions. Java enforces strong security to make sure that Java programs arriving over the network do not damage your files or your system(as computer viruses and worms might).
  5. execute: java HelloWorld. JVM excutes the bytecodes(IDEs typically provide a menu such as Run to invoke the java command for you). In early Java versions, the JVM was simply a Java-bytecode interpreter. Most programs would execute slowly, because the JVM would interpret and execute one bytecode at a time. Today’s JVMs typically execute bytecodes using a combination of interpretaion and just-in-time(JIT) compilation. In this process, the JVM analyzes the bytecodes as they’re interpreted, searching for hot spots – bytecodes that execute frequently. For these parts(hot spots), a just-in-time(JIT) compiler , such as Oracle’s Java HotSpot compiler, translates the bytecodes into the computer’s machine language. When the JVM encounters these compiled parts again, the faster machine-language code executes. Thus programs actually go through two compilation phases – one in which Java code is translated into bytecodes and a second in which, during execution, the bytecodes are translated into machine language.