Use javac to compile the .java into a .class file
Fix CLASSPATH issues
Use java to run the run .class file
Fix CLASSPATH issues
Editing Java
First, we have to create the Java source code file. This is a plain-text file that uses the extension .java . There are a variety of text editors. Text editors are used to create plain text files(i.e.,not word documents or rich text documents). I recommend Sublime, Microsoft Visual Studio Code, Emacs, Vim, or Atom. Like many editors, and unlike some, these text editors are suited for reading & writing code because they provide syntax highlighting, line numbers, and are configurable and extensible.
Use a text editor to create an Empty class definition in a file named Empty.java :
publicclassEmpty{
}
Note the folder(or directory) where you saved that file. It will be easiest to save it in your home directory for now. Otherwise you’ll have to cdto where you save it.
Compiling Java
Next we have to compile the java source file. We have to temporarily leave the editor for this step. The compiler will create a file of bytecode, the intermediate form of a java program. Assuming you have saved the Empty.java in your home directory, start a terminal, and enter:
javac Empty.java
Alternately, if you saved Empty.java in another folder, for instance, named Documents you first have to change to that directory before compiling:
cd Documents/
javac Empty.java
Once you have run javac , it should have created a file named Empty.class that includes the Java byte code.
If this did not happen, two things may have gone wrong:
Empty.java not found: verify you named the file exactly Empty.java and you are running javac in the correct folder.
We can verify the compilation worked by disassembling the class file. This is pretty neat: we are essentially de-compiling the class file to recreate the original source code(or something like it).
Editing Java
public class Empty{
}
Compiling Java
javac Empty.java
cd Documents/
javac Empty.java
javap Empty
Compiled from "Empty.java"
public class Empty {
public Empty();