Here is an example if you are going to use OpenJDK. This helps when it’s too slow to load a Java IDE to compile the source files (For example, on Raspberry Pi platform; I’ve tried Geany and Netbeans. It takes forever to load…).
- From Terminal install the open jdk
sudo apt-get install openjdk-7-jdk
- Write program and save the file as filename.java
- Now to compile use this command from the terminal
If everything work well you will notice a filename.class file is also created.
- To run your program you compiled use the below code in terminal:
You can use any text editor (like gedit) ,
replace the filename with watever name you want
you need to be on same directory as the “present working directory” (got by running
pwd) while running the command from terminal.