By Barry Burd

If you’re a seasoned veteran of computers and computing, you can try installing the required software for creating Java programs. You’ll need the three things listed below in order to start

“A compiler takes the Java code that you write and turns that code into something that can run on your computer.”

Barry Burd, Java For Dummies, 6th Edition

So how many tools do you need for creating Java programs? As a novice, you need three tools:

  • A compiler takes the Java code that you write and turns that code into something that can run on your computer.

  • A Java Virtual Machine runs your code (and other peoples’ Java code) on your computer.

  • An integrated development environment helps you manage your Java code and provides convenient ways for you to write, compile, and run your code.

// This is part of a Java program
// (not a complete Java program).
roomNum = 1;
while (roomNum < 100) {
    if (guests[roomNum] == 0) {
        out.println("Room " + roomNum
                + " is available.");
        exit(0);
    } else {
        roomNum++;
    }
}
out.println("No vacancy");

The Java code here checks for vacancies in a small hotel (a hotel with room numbers 1 to 99). You can’t run the code without adding several additional lines. But those additional lines aren’t important. What’s important is that, by staring at the code, squinting a bit, and looking past all the code’s strange punctuation, you can see what the code is trying to do:

Set the room number to 1.
As long as the room number is less than 100,
    Check the number of guests in the room.
    If the number of guests in the room is 0, then 
        report that the room is available,
        and stop.
    Otherwise,
        prepare to check the next room by 
        adding 1 to the room number.
If you get to the non-existent room number 100, then
    report that there are no vacancies.

If you don’t see the similarities between the code and its English equivalent, don’t worry, like most human beings, you can learn to read and write the code. It’s called Java source code.

So here’s the catch: Computers aren’t human beings. Computers don’t normally follow instructions like the instructions in the listing. That is, computers don’t follow Java source code instructions. Instead, computers follow cryptic instructions like the ones in the listing.

aload_0
iconst_1
putfield Hotel/roomNum I
goto 32
aload_0
getfield Hotel/guests [I
aload_0
getfield Hotel/roomNum I
iaload
ifne 26
getstatic java/lang/System/out Ljava/io/PrintStream;
new java/lang/StringBuilder
dup
ldc "Room "
invokespecial java/lang/StringBuilder/<init>(Ljava/lang/String;)V
aload_0
getfield Hotel/roomNum I
invokevirtual java/lang/StringBuilder/append(I)Ljava/lang/StringBuilder;
ldc " is available."
invokevirtual
java/lang/StringBuilder/append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invokevirtual java/lang/StringBuilder/toString()Ljava/lang/String;
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
iconst_0
invokestatic java/lang/System/exit(I)V
goto 32
aload_0
dup
getfield Hotel/roomNum I
iconst_1
iadd
putfield Hotel/roomNum I
aload_0
getfield Hotel/roomNum I
bipush 100
if_icmplt 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc "No vacancy"
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
return

The instructions in this listing aren’t Java source code instructions. They’re Java bytecode instructions. When you write a Java program, you write source code instructions (like the instructions listed first). After writing the source code, you run a program (that is, you apply a tool) to your source code.

The program is a compiler. The compiler translates your source code instructions into Java bytecode instructions. In other words, the compiler takes code that you can write and understand and translates it into code that a computer can execute (like the code here).

You might put your source code in a file named Hotel.java. If so, the compiler probably puts the Java bytecode in another file named Hotel.class. Normally, you don’t bother looking at the bytecode in the Hotel.class file. In fact, the compiler doesn’t encode the Hotel.class file as ordinary text, so you can’t examine the bytecode with an ordinary editor.

If you try to open Hotel.class with Notepad, TextEdit, KWrite, or even Microsoft Word, you’ll see nothing but dots, squiggles, and other gobbledygook. To create a listing, you have to apply yet another tool to your Hotel.class file. That tool displays a text-like version of a Java bytecode file. You can use Ando Saabas’s Java Bytecode Editor.

No one (except for a few crazy developers in some isolated labs in faraway places) writes Java bytecode. You run software (a compiler) to create Java bytecode. The only reason to look at this listing is to understand what a hard worker your computer is.