Processing is a great tool for quickly prototyping graphics-intensive computations. In my view, adding interactive visualization makes almost any idea easier to prototype, design, and understand. The Processing IDE(Integrated Development Environment) is great for beginners and experts alike, but at some point you might want to use alternatives. Moreover, popping the hood and seeing the Java inner workings of Processing can be enlightening.
This tutorial covers how to edit, compile and run Processing programs from the command-line.
Step 0: Install the Java SDK(Software Development Kit)
Use`javac` to compile the`.java` into a`.class` file
Fix CLASSPATH issues
Use`java` to run the`.class` file
Fix CLASSPATH issues
The Processing IDE program handles step 2-4 for you, when you hit that beautifully simple play button. But in this tutorial we must use the two underlying programs:`javac` and`java` directly.
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, Emacs, Vim, or Atom. Like many editors, and unlike some, these four 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.
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