A note on Java compilation on Windows, Ubuntu, and Raspberry Pi (Debian)

Here is some basic info for these three platforms (in particular, Java environment).

A side note – I tried Geany, Netbeans, and BlueJ on Raspberry Pi. It seems that none of these IDE’s is fast enough to do the work. The most efficient way to compile the Java source code probably is through command lines. Think of cross-compile???



64-bit Windows 7

java version “1.8.0_45”

Java(TM) SE Runtime Environment (build 1.8.0_45-b15)

Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)



Ubuntu 12.04

Linux LinuxWorkstation 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:51:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

java version “1.8.0_45”

Java(TM) SE Runtime Environment (build 1.8.0_45-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)



Raspberry Pi (a Debian variant)

Linux rasworkstation 3.18.11+ #781 PREEMPT Tue Apr 21 18:02:18 BST 2015 armv6l GNU/Linux

java version “1.6.0_34”

OpenJDK Runtime Environment (IcedTea6 1.13.6) (6b34-1.13.6-1~deb7u1+rpi1)

OpenJDK Zero VM (build 23.25-b01, mixed mode)

(If you want to install and try Oracle Java SE on Raspberry Pi, do the following.

$ sudo apt-get update && sudo apt-get install oracle-java7-jdk

You may find your Java installation under /usr/lib/jvm/. If you already installed an alternative Java implementation, such as OpenJDK you might need to do the following to switch to using the Oracle JDK as default:

$ sudo update-java-alternatives -s jdk-7-oracle-armhf


$ sudo update-alternatives –config java

$ sudo update-alternatives –config javac




A user “ras” has been set up on the Pi board. Under the /home/ras directory, I stored the Java source code and external library




First, compile the Java source code

$javac -classpath /home/ras:/home/ras/lib/sample_lib.jar /home/ras/mypackage/my_source_code.java

This will create the compiled class file in the “mypackage” directory: my_source_code.class


Now you can go ahead and run the compiled code.

$java -classpath /home/ras:/home/ras/lib/sample_lib.jar mypackage.my_source_code


Java advocates “write once, run anywhere”, meaning that the compiled Java code can run on all platforms that support Java without the need for recompilation. Unfortunately, you have to compile on the Pi board because of the different Java platform (OpenJDK).


The compiled code (on Windows) is able to run on the Ubuntu platform without any issue. Note that these two provide the same Java environment.