Those, who cannot teach, lecture trainee teachers teaching methodology.
The javac command will read HelloWorld.java. If no errors are found a HelloWorld.class bytecode file is being generated.
The ls command lists all files and directories being found in your current working directory. The -l option will create a longer listing providing privilege, user and group ownership, file size and modification time meta data.
The bytecode file HelloWorld.class results from compilation in ❶.
The source file containing our class definition code. Note Sep 25 09:14 being more recent than Sep 23 17:44. This reflects the fact that compilation happened after editing HelloWorld.java.
Starting the Java™ runtime. HelloWorld is a command line parameter to java.
The source line System.out.println("Hello, world") causes the Java™ runtime writing the string "Hello, world" to the operating system's standard output channel appending a newline character.
"lecture trainee teachers teaching methodology."); // No \n here, println does it.
Rename your existing HelloWorld.java file to Advance.java and try to compile it. What happens and why does it happen?
How do you solve the problem by editing the file's content?
We rename HelloWorld.java to Advance.java on file system level without touching its content.
Failure: The file Advance.java still contains a public class HelloWorld definition. But Java™ requires the class name being equal to the containing file's base name appending a .java extension.
This error belongs to the wide class of compile time errors. More specific it is being called a syntax error violating Java™ language constraints.
Whats wrong here? Why does the "I have changed!" string does not show up?
The programmer likely edited HelloWorld.java and forgot to invoke the compiler by executing javac HelloWorld.java. As a consequence the now outdated HelloWorld.class bytecode file was not replaced by a current version thus not reflecting the change of HelloWorld.java and thus became outdated.
This is a common beginner's error: Integrated development environments like Intellij IDEA and build tools like Maven relieve you from the »manually keeping track of dependencies« burden: Editing a source code file will trigger compilation automatically. We'll turn to those higher level tools after finishing our basic tour on “pure” Java™ javac / java commands and plain text source code editing.
Use your favourite text editor for overwriting the string "Hello, world" by "Software joy" in HelloWorld.class (Not in HelloWorld.java!).
Try to execute this bytecode file (without recompiling). What do you observe?
Recompile and repeat the process starting from a sound HelloWorld.class file. This time use a binary editor like hexedit or ghex instead.
The “tab” key switching to the ASCII section in the right pane.
“Ctrl-X” for leaving the editor and hitting the “Y” key to persist your changes.
Start again from a freshly compiled HelloWorld.class. Use a binary editor again to append an exclamation mark as in "Hello, world!". The string's length will thus be increased by 1. What happens on execution?
The 0A (10 in hexadecimal notation) is being appended to the bytecode file both by vim and nano. This is the ASCII value corresponding to a linefeed character. Both editors thus add an empty new line on saving thereby corrupting the bytecode file.
The emacs editor for example refrains from auto-adding newlines and doesn't cause this problem.
Thus appending an exclamation mark will override the hexadecimal 07 value immediately following the "Hello, world" string with a new value of 21 (ASCII for “!”). Apparently this value serves some purpose with respect to the virtual machine and must therefore not be altered. This is the byte code verifier's responsibility as being outlined in Figure 27, “Execute Java™ bytecode file ”.
Overall conclusion: Tinkering with bytecode files is a bad idea unless you have a good reason and know what you are doing.