Skip to main content

Java 8 on the Raspberry Pi

This topic being approached exhaustively may become vast and is fit for at least a book. I'll have to keep it short and concise here, so I'll stick to a few key points:

  • Java Runtime vs JDK - actually there is no discussion here - if you you intend to run programming projects you need the development kit, period. (It contains the runtime anyway.)
  • Java 7  vs Java 8 (JDKs) - this could require some debate. Java 7 is the mature and default option to go with. Having around two years in production, it is the safer choice. Java 8 has been just released, and its shortcomings are still unknown. On the other hand Java 8 has numerous improvements to the language, and Oracle wouldn't approve it for release if it wasn't quite well tested. Another facet to be considered is that Java 7 is well presented in the repositories, while currently Java 8 have to be downloaded, installed and maintained (the regular updates - mostly for security reasons) all manually.
  • Source examples - new features calls for examples of them in action. Well, I'm curious too, so we'll see some code, but in a subsequent post. Seeing the new features is interesting, but seeing them in the Raspberry Pi context is even more interesting. I guess it will worth a bit more effort to gather such examples, and a bit more waiting for that next post.

Installing JDK 7 from the repositories is very trivial. Therefore not interesting. So lets see how to manually install the new JDK 8 from the command line.
First you need to get it. The following command should do:
$ wget http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-arm-vfp-hflt.tar.gz
But it doesn't. You see, when you go to the download page on the Oracle's site to get your installation, you have to accept the licence agreement in order to be allowed to download the file. So the wget command needs some additional parameters, like these:
$ wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie"  http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-arm-vfp-hflt.tar.gz
I got the tip for these parameters from this post on StackOverflow. Don't forget to check your current version of the JDK in order to have an up-to-date URL.

Now we need to install it properly, so it is available system-wide. Just deflating the archive in a dedicated folder in the home directory would suffice for some primary tasks, but to be visible from the entire system is always a better option (unless some exotic security restrictions are required).
So we create the usual directory that holds the JDK:
$ sudo mkdir /usr/lib/jvm
Move the freshly downloaded archive into that directory and unpack it with:
/usr/lib/jvm $ sudo tar zxvf jdk-8-linux-arm-vfp-hflt.tar.gz 
Now follows a critical step in the procedure - the system must be told where the java main tools (java and javac) are, and to be set as default ones. Execute the following set of commands:
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac" 1

$ sudo update-alternatives --set "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac"
$ sudo update-alternatives --set "java" "/usr/lib/jvm/jdk1.8.0/bin/java"
In the end, if everything is fine, the following commands should produce the respective outputs:
$ java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)
and 
$ javac -version
javac 1.8.0
The check will successfully run after this step, although it is supposed to be made after adding Java to the system PATH. For that purpose, the system's profile should be amended. First issue the command:
$ sudo nano /etc/profile
At the end of the file add the following:
JAVA_HOME=/usr/lib/jvm/jdk1.8.0 
export JAVA_HOME 
PATH=$PATH:$JAVA_HOME/bin 
export PATH
After saving the file you may restart the session. But that will not be necessary if you just issue the command
$ . /etc/profile
which reloads the session properties on runtime.

The procedure with all these commands I adapted from here. The version is different, but the steps are the same nevertheless. A possible next step could be setting up some Java capable IDE (updated to support Java 8) on Raspbian, or setting up a remote development environment - the IDE and the source code on a more powerful desktop machine, and the runtime environment on the Raspberry Pi. 

Comments

Popular posts from this blog

The Pi as a PostgreSQL Database Server

Raspbian with PostgreSQL it is quite easy actually. Just like on Ubuntu/Linux Mint/... (Replace the ellipsis with any derivative of Debian or Ubuntu.) The hardest part is to decide which version of the database server to employ. On this page the full set of options for retrieving the server is given with the necessary amount of detail.     "Should I get it?" Actually, since PostgreSQL (together with MySQL) is one of the most popular open source databases within the Linux realm, some distributions choose to deliver it pre-installed on their releases. If you are not sure, if you need to get the server at all, this simple command can answer that question: $ ps aux | grep postgers It will search through the processes running on your system and filter them to leave only those bound to PostgreSQL. It is possible that the server is present on the system, but it is not running at the moment. In that case it is enough to see if its configurations are in place. The plac

Book on How to Cluster some Pis with Hadoop

To be honest and straightforward I expected more from a book with title like Raspberry Pi Super Cluster . The author Andrew K. Denis has a very clear vision on the subject (like in his previous book Raspberry Pi Home Automation with Arduino , which I liked a lot) . He's done his best to deliver an exhaustive set-up while being concise at the same time, but it seems to me, this clearly is the wrong format for a book on the given topic. Stack Pis for parallel power Now having this book at hand, I finally got the chance to answer many of the questions I had about clustering, and how it can be applied to a set of Raspberry Pis. The first impression is that it is very well structured and gradual. Lets see, the first two chapters are short introductions to parallel computing (background history and the contemporary systems) and the initial set-up respectively. They're short and to the point. And that's the way it should be - it is presumed that if you're going paralle