Wednesday, February 26, 2014

C programming exercise: copy file

The following code copy file using C language, run in Raspberry Pi.

copy file using C

#include <fcntl.h>
#include <stdio.h>

int main(int argc, char *argv[]){
    
    int srcFileDesc;    //file descriptor of source file
    int destFileDesc;   //file descriptor of output file
    ssize_t numberOfRead;
    int BUFFER_SIZE = 1024;
    char buffer[BUFFER_SIZE];
    
    char *SRC_FILE ="test";
    char *DEST_FILE ="new_test";
    
    printf("copyfile:\n");
    printf("Copy file %s to %s\n", SRC_FILE, DEST_FILE);
    
    printf("Open file: %s\n", SRC_FILE);
    srcFileDesc = open("test", O_RDONLY);
    if(srcFileDesc != -1){
        
        printf("Create output file: %s\n", DEST_FILE);
        destFileDesc = open(DEST_FILE,
            O_CREAT|O_WRONLY|O_TRUNC,
            S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
        if(destFileDesc != -1){
            
            while((numberOfRead=read(srcFileDesc, buffer, BUFSIZ)) > 0){
                if(write(destFileDesc, buffer, numberOfRead) != numberOfRead){
                    printf("Error in copying...!\n");
                }
            }
            
            if(numberOfRead == -1){
                printf("Something wrong...!\n");
            }
            
            if (close(destFileDesc) != -1){
                printf("Close destination file: %s\n", DEST_FILE);
            }else{
                printf("Error in Close destination file: %s\n", DEST_FILE);
            }
            
        }else{
            printf("Error in Create output file: %s\n", DEST_FILE);
        }
        
        if (close(srcFileDesc) != -1){
            printf("Close file: %s\n", SRC_FILE);
        }else{
            printf("Error in Close file: %s\n", SRC_FILE);
        }
    }else{
        printf("Cannot open file: %s\n", SRC_FILE);
    }
}

Tuesday, February 25, 2014

Stream music to the Raspberry Pi

This video show how to stream music to the Raspberry Pi by using it as a media renderer. Prepare the Pi, install all packages required, and play sample audio which has been streamed wirelessly to the device from a smartphone app.



Saturday, February 22, 2014

ARM Cortex-A Series Programmer's Guide version 4 is available now

The new ARM Cortex-A Series Programmer’s Guide, Version 4.0, is available in a PDF version HERE (requires registration for an ARM account).

ARM Cortex-A Series Programmer’s Guide, Version 4.0

Tuesday, February 18, 2014

Oracle Learning: Using a Raspberry Pi to Deploy JavaFX Applications

Oracle Learning Library released a tutorial of "Using a Raspberry Pi to Deploy JavaFX Applications". It covers how to configure a Raspberry Pi as a development platform for the JavaFX platform.

Begin Tutorial at HERE

Using a Raspberry Pi to Deploy JavaFX Applications
Oracle Learning Library: Using a Raspberry Pi to Deploy JavaFX Applications

Saturday, February 15, 2014

Raspberry Pi Server Essentials

Raspberry Pi Server Essentials
Raspberry Pi Server Essentials
Transform your Raspberry Pi into a server for hosting websites, games, or even your Bitcoin network
Overview
  • Unlock the various possibilities of using Raspberry Pi as a server
  • Configure a media center for your home or sharing with friends
  • Connect to the Bitcoin network and manage your wallet
In Detail
Raspberry Pi makes a good server that facilitates you with eminently achievable to the massively ambitious ideas. It is a capable computer that can perform tasks that involve spreadsheets, word processing, and games. It also plays high-definition video. If you are looking for a way to set up a low cost web server, primarily to be used as a testing environment or to store files, then Raspberry Pi is perfect for you.
This book demonstrates Raspberry Pi's ability to perform tasks that a mini computer would, in an efficient manner using a minimum number of power resources. You can connect your Raspberry Pi to the Internet at home to share files, host multi-player games, or even host a website.
Starting with the pre-requisites and installation of Pi, you will learn how to setup Pi as a web server with MySQL. This book progresses with building Pi as a file server and knowing about using the various file transfer protocols. It also guides you to install Bitcoin/ Litecoin and set up Bitcoin wallet. You will learn how to stream a webcam to watch movies in HD or camera module.
Complete your journey by learning how to use Pi as a game server by using basic console commands to get graphical content.
What you will learn from this book
  • Use Raspberry Pi as a low cost network storage device
  • Configure a webserver using PHP and work with databases
  • Host multi-player games by using Pi as a game server to get graphical content
  • Share files and use hardware RAID on the Pi
  • Mine Bitcoins and make your own digital currency
  • Turn your Raspberry Pi into a media server to stream media to your network
  • Enable extra features such as installing a wireless adapter, enabling the hardware watchdog, and updating and upgrading the distro
Approach
This is an engaging, easy to follow guide for developing a wide range of server projects with Raspberry Pi
Who this book is written for
This book is targeted towards all Raspberry Pi enthusiasts who are interested in exploring the potential of Pi as a server. Even if you have no prior experience with the Raspberry Pi, you can pick up this book and develop a wide range of projects.

Thursday, February 13, 2014

MagPi February 2014 out

MagPi February 2014
The FREE Raspberry Pi magazine, MagPi Issue 20, February 2014 is here.

Rethinking the Internet of Things: A Scalable Approach to Connecting Everything

Rethinking the Internet of Things
Rethinking the Internet of Things
Over the next decade, most devices connected to the Internet will not be used by people in the familiar way that personal computers, tablets and smart phones are. Billions of interconnected devices will be monitoring the environment, transportation systems, factories, farms, forests, utilities, soil and weather conditions, oceans and resources.

Many of these sensors and actuators will be networked into autonomous sets, with much of the information being exchanged machine-to-machine directly and without human involvement.   Machine-to-machine communications are typically terse. Most sensors and actuators will report or act upon small pieces of information - “chirps”.  Burdening these devices with current network protocol stacks is inefficient, unnecessary and unduly increases their cost of ownership.  

This must change.  The architecture of the Internet of Things must evolve now by incorporating simpler protocols toward at the edges of the network
, or remain forever inefficient.   Rethinking the Internet of Things describes reasons why we must rethink current approaches to the Internet of Things. Appropriate architectures that will coexist with existing networking protocols are described in detail. An architecture comprised of integrator functions, propagator nodes, and end devices, along with their interactions, is explored.


What you’ll learn

  • Discusses the difference between the "normal" Internet and the Internet of Things.
  • Describes a new architecture and its components in the "chirp" context.
  • Explains the shortcomings of IP for IoT.
  • Describes the anatomy of the IoT.
  • Describes how to build a suitable network to maximize the amazing potential of the IoT.

Who this book is for


Thought leaders, executives, architectural, standards and development leaders  in the evolving IoT industry.  Corporations and organizations whose commercial products could be adapted simply to be functioning devices on the IOT while saving billions of dollars in unnecessary costs or proprietary designs.  Those who wish to capitalize on technology change and those interested in the Internet, its capabilities and the need to improve it.

Table of Contents

Foreword
Preface

Chapter Goal: The reader will understand the new demands and opportunities of the Internet of Things (IoT). The preface introduces the idea of a new, simplified architectural approach that draws on nature. 

Chapter 1: It's Different Out Here 

Chapter Goal: Reader should understand the difference between traditional Internet networking and the Internet of Things. What are the unique characteristics of the IoT that demand a new architecture? Why traditional architectures such as IP are a poor fit. Characteristics of an IoT-optimized architecture. 

Chapter 2: Anatomy of the Internet of Things 

Chapter Goal: Reader will understand the underlying principles of the emerging IoT architecture. Fundamental concepts are: the division of networking complexity among different devices; the make-up of the "Chirp" and how they are propagated; distinctions between transport and functional topologies; the concept of neighborhoods or zones of interest.

Chapter 3: On the Edge 


Chapter Goal: Reader will learn the principles and characteristics of the End Devices in the IoT and how these will often differ from our present understanding of the Smartphone, tablet, and laptop. How the minimal networking needs of many IoT devices dictate elements of the architecture. 

Chapter 4: Building a Web of Things 

Chapter Goal: Reader will learn the characteristics and functionality of the Propagator node in the IoT Architecture. Some communications principles are introduced which will be more fully explored in Chapter 6. 

Chapter 5: Small Data, Big Data, and Human Interaction 

Chapter Goal: Reader will understand the role of Integrator functions in the IoT, the point in the IoT where humans interact to gain information from IoT data and to set parameters and control end devices. An explanation of zones of interest and neighborhoods, with a discussion of incorporating "small data" from chirps into big data analysis. 

Chapter 6: An Architecture for the Frontier 


Chapter Goal: Reader will gain an understanding of the challenges inherent in a communications architecture for the massive scale of the IoT. Exploiting the opportunities inherent in a machine-to-machine environment, a much simpler architecture is described in detail that readily scales to the required scope. This chapter adds technical depth to ideas introduced in Chapters 3-5. 

Chapter 7: IoT Examples and Applications 

Chapter Goal: Reader will learn about current and emerging applications in the Internet of Things. Reference wile b made to new applications enabled by the simpler architecture described in this book that are difficult or not possible with traditional networking protocols. 

Chapter 8: Blueprint to the Internet of Things
 
Chapter Goal: Exploring the steps to IoT deployment. Standards based versus ad hoc approaches, call for industry cooperation and consortia. Intermediate incremental steps to broader adoption. 

Wednesday, February 12, 2014

Practical OpenCV

Hands on projects for Computer Vision on the Windows, Linux, and Raspberry Pi platforms
Practical OpenCV
Practical OpenCV
Practical OpenCV is a hands-on project book that shows you how to get the best results from OpenCV, the open-source computer vision library.

Computer vision is key to technologies like object recognition, shape detection, and depth estimation. OpenCV is an open-source library with over 2500 algorithms that you can use to do all of these, as well as track moving objects, extract 3D models, and overlay augmented reality. It's used by major companies like Google (in its autonomous car), Intel, and Sony; and it is the backbone of the Robot Operating System’s computer vision capability. In short, if you're working with computer vision at all, you need to know OpenCV.

With Practical OpenCV, you'll be able to:
  • Get OpenCV up and running on Windows or Linux.
  • Use OpenCV to control the camera board and run vision algorithms on Raspberry Pi.
  • Understand what goes on behind the scenes in computer vision applications like object detection, image stitching, filtering, stereo vision, and more.
  • Code complex computer vision projects for your class/hobby/robot/job, many of which can execute in real time on off-the-shelf processors.
  • Combine different modules that you develop to create your own interactive computer vision app.

What you’ll learn

  • The ins and outs of OpenCV programming on Windows and Linux
  • Transforming and filtering images
  • Detecting corners, edges, lines, and circles in images and video
  • Detecting pre-trained objects in images and video
  • Making panoramas by stitching images together
  • Getting depth information by using stereo cameras
  • Basic machine learning techniques
  • BONUS: Learn how to run OpenCV on Raspberry Pi

Who this book is for

This book is for programmers and makers with little or no previous exposure to computer vision. Some proficiency with C++ is required.

Table of Contents

Part 1: Getting comfortable
Chapter 1: Introduction to Computer Vision and OpenCV
Chapter 2: Setting up OpenCV on your computer
Chapter 3: CV Bling – OpenCV inbuilt demos
Chapter 4: Basic operations on images and GUI windows

Part 2: Advanced computer vision problems and coding them in OpenCV
Chapter 5: Image filtering
Chapter 6: Shapes in images
Chapter 7: Image segmentation and histograms
Chapter 8: Basic machine learning and keypoint-based object detection
Chapter 9: Affine and Perspective transformations and their applications to image panoramas
Chapter 10: 3D geometry and stereo vision
Chapter 11: Embedded computer vision: Running OpenCV programs on the Raspberry Pi

Beginning Sensor Networks with Arduino and Raspberry Pi

Beginning Sensor Networks with Arduino and Raspberry Pi
Beginning Sensor Networks with Arduino and Raspberry Pi teaches you how to build sensor networks with Arduino, Raspberry Pi, and XBee radio modules, and even shows you how to turn your Raspberry Pi into a MySQL database server to store your sensor data!

First you'll learn about the different types of sensors and sensor networks, including how to build a simple XBee network. Then you'll walk through building an Arduino-based temperature sensor and data collector, followed by building a Raspberry Pi-based sensor node.

Next you'll learn different ways to store sensor data, including writing to an SD card, sending data to the cloud, and setting up a Raspberry Pi MySQL server to host your data. You even learn how to connect to and interact with a MySQL database server directly from an Arduino! Finally you'll learn how to put it all together by connecting your Arduino sensor node to your new Raspberry Pi database server.

If you want to see how well Arduino and Raspberry Pi can get along, especially to create a sensor network, then Beginning Sensor Networks with Arduino and Raspberry Pi is just the book you need.

What you’ll learn

  • How to build sensor nodes with both Arduino and Raspberry Pi!
  • What is XBee?
  • What methods you have for storing sensor data
  • How you can host your data on the Raspberry Pi
  • How to get started with the MySQL database connector for Arduino
  • How to build database enabled sensor networks

Who this book is for

Electronics enthusiasts, Arduino and Raspberry Pi fans, and anyone who wants hands-on experience seeing how these two amazing platforms, Arduino and Raspberry Pi, can work together with MySQL.

Table of Contents

1.  Introduction to Sensor Networks
2.  Tiny Talking Modules: An Intro to Xbee Wireless Modules
3.  Arduino-Based Sensor Node
4.  Rapberry Pi-based Sensor Notes    
5.  Where to Put It All: Storing Sensor Data
6.  Turning Your Raspberry Pi into a Database Server  
7.  MySQL and Arduino: United at Last!   
8.  Building Your Network: Arduino Wireless Aggregator + Wireless Sensor Node + Raspberry Pi Server
9.  Planning Wireless Sensor Networks
10. Shopping List

Develop Java Embedded Applications Using a Raspberry Pi

In this free 5-week course, Oracle Massive Open Online Course: Develop Java Embedded Applications Using a Raspberry Pi, learn to develop Java ME Embedded 8 Applications using a Raspberry Pi as your development platform! This course will leverage your Java skills and introduce you to the world of embedded devices and the Internet of Things (IoT). Purchase a Raspberry Pi and take the training for free.

You will learn how to:
* Read input data from switches and drive LED's using the GPIO interface
* Read temperature and barometric pressure from an I2C device
* Read the device's current location using a GPS UART device
* Store and manage data collected
* Report data to a client through a variety of communication options

Sunday, February 9, 2014

Adventures In Raspberry Pi

Adventures In Raspberry Pi
Adventures In Raspberry Pi
Coding for kids is cool with Raspberry Pi and this elementary guide

Even if your kids don't have an ounce of computer geek in them, they can learn to code with Raspberry Pi and this wonderful book. Written for 11- to 15-year-olds and assuming no prior computing knowledge, this book uses the wildly successful, low-cost, credit-card-sized Raspberry Pi computer to explain fundamental computing concepts. Young people will enjoy going through the book's nine fun projects while they learn basic programming and system administration skills, starting with the very basics of how to plug in the board and turn it on.

Each project includes a lively and informative video to reinforce the lessons. It's perfect for young, eager self-learners—your kids can jump in, set up their Raspberry Pi, and go through the lessons on their own.
  • Written by Carrie Anne Philbin, a high school teacher of computing who advises the U.K. government on the revised ICT Curriculum
  • Teaches 11- to 15-year-olds programming and system administration skills using Raspberry Pi
  • Features 9 fun projects accompanied by lively and helpful videos
  • Raspberry Pi is a $35/£25 credit-card-sized computer created by the non-profit Raspberry Pi Foundation; over a million have been sold
Help your children have fun and learn computing skills at the same time with Adventures in Raspberry Pi.

January 7, 2014  1118751256  978-1118751251 1


Linux command: list and display installed fonts

The Linux command xlsfonts list the fonts for X-server, and the commaand xfd display all the characters in an X font.

example:
$ xlsfonts
$ xfd -fn micro


Get my IP Address using Java

The below Java code, myIP.java, list my IP address.

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

class myIP {
    public static void main(String[] args) {
        System.out.println(getIpAddress());
    }
    
    private static String getIpAddress(){
        String ip = "";
        try {
            Enumeration<NetworkInterface> enumNetworkInterfaces = 
                NetworkInterface.getNetworkInterfaces();
            while(enumNetworkInterfaces.hasMoreElements()){
                NetworkInterface networkInterface = 
                    enumNetworkInterfaces.nextElement();
                Enumeration<InetAddress> enumInetAddress = 
                    networkInterface.getInetAddresses();
                while(enumInetAddress.hasMoreElements()){
                    InetAddress inetAddress = enumInetAddress.nextElement();
                    
                    String ipAddress = "";
                    if(inetAddress.isLoopbackAddress()){
                        ipAddress = "LoopbackAddress: ";
                    }else if(inetAddress.isSiteLocalAddress()){
                        ipAddress = "SiteLocalAddress: ";
                    }else if(inetAddress.isLinkLocalAddress()){
                        ipAddress = "LinkLocalAddress: ";
                    }else if(inetAddress.isMulticastAddress()){
                        ipAddress = "MulticastAddress: ";
                    }
                    
                    ip += ipAddress + inetAddress.getHostAddress() + "\n"; 
                }
            }    
        } catch (SocketException e) {
            ip += "Something Wrong! " + e.toString() + "\n";
        }
        
        return ip;
    }
}

Get my IP Address using Java
Get my IP Address using Java

Check System Properties of Raspberry Pi, using Java

Once installed Java 8 release candidate on Raspberry Pi, we can create a java program, listProperties.java, to list System Properties, to verify the installation.

listProperties.java
import java.util.Properties;
import java.util.Set;

class listProperties {
    
    public static void main(String[] args) {
        
        Properties properties = System.getProperties();
        System.out.println(properties.toString());
        System.out.println("\n");
        
        Set<String> setPropertyNames = 
            properties.stringPropertyNames();
        for (String propName : setPropertyNames) {
            System.out.println(
                propName + " : " +
                System.getProperty(propName));
        }
    }
}

To compile listProperties.java
$ javac listProperties.java

Run generated listProperties.class
$ java listProperties

The result will be something like:



pi@raspberrypi ~/worksJava $ java listProperties
{java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=/opt/jdk1.8.0/jre/lib/arm, java.vm.version=25.0-b69, java.vm.vendor=Oracle Corporation, java.vendor.url=http://java.oracle.com/, path.separator=:, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=GB, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/home/pi/worksJava, java.runtime.version=1.8.0-b128, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/opt/jdk1.8.0/jre/lib/endorsed, os.arch=arm, java.io.tmpdir=/tmp, line.separator=
, java.vm.specification.vendor=Oracle Corporation, os.name=Linux, sun.jnu.encoding=UTF-8, java.library.path=/usr/java/packages/lib/arm:/lib:/usr/lib, java.specification.name=Java Platform API Specification, java.class.version=52.0, sun.management.compiler=HotSpot Client Compiler, os.version=3.10.28+, user.home=/home/pi, sun.arch.abi=gnueabihf, user.timezone=Asia/Hong_Kong, java.awt.printerjob=sun.print.PSPrinterJob, file.encoding=UTF-8, java.specification.version=1.8, java.class.path=., user.name=pi, java.vm.specification.version=1.8, sun.java.command=listProperties, java.home=/opt/jdk1.8.0/jre, sun.arch.data.model=32, user.language=en, java.specification.vendor=Oracle Corporation, awt.toolkit=sun.awt.X11.XToolkit, java.vm.info=mixed mode, java.version=1.8.0, java.ext.dirs=/opt/jdk1.8.0/jre/lib/ext:/usr/java/packages/lib/ext, sun.boot.class.path=/opt/jdk1.8.0/jre/lib/resources.jar:/opt/jdk1.8.0/jre/lib/rt.jar:/opt/jdk1.8.0/jre/lib/sunrsasign.jar:/opt/jdk1.8.0/jre/lib/jsse.jar:/opt/jdk1.8.0/jre/lib/jce.jar:/opt/jdk1.8.0/jre/lib/charsets.jar:/opt/jdk1.8.0/jre/lib/jfr.jar:/opt/jdk1.8.0/jre/classes, java.vendor=Oracle Corporation, file.separator=/, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.cpu.isalist=}



java.runtime.name : Java(TM) SE Runtime Environment

sun.boot.library.path : /opt/jdk1.8.0/jre/lib/arm
java.vm.version : 25.0-b69
java.vm.vendor : Oracle Corporation
java.vendor.url : http://java.oracle.com/
path.separator : :
java.vm.name : Java HotSpot(TM) Client VM
file.encoding.pkg : sun.io
user.country : GB
sun.java.launcher : SUN_STANDARD
sun.os.patch.level : unknown
java.vm.specification.name : Java Virtual Machine Specification
user.dir : /home/pi/worksJava
java.runtime.version : 1.8.0-b128
java.awt.graphicsenv : sun.awt.X11GraphicsEnvironment
java.endorsed.dirs : /opt/jdk1.8.0/jre/lib/endorsed
os.arch : arm
java.io.tmpdir : /tmp
line.separator : 


java.vm.specification.vendor : Oracle Corporation

os.name : Linux
sun.jnu.encoding : UTF-8
java.library.path : /usr/java/packages/lib/arm:/lib:/usr/lib
java.specification.name : Java Platform API Specification
java.class.version : 52.0
sun.management.compiler : HotSpot Client Compiler
os.version : 3.10.28+
user.home : /home/pi
sun.arch.abi : gnueabihf
user.timezone : Asia/Hong_Kong
java.awt.printerjob : sun.print.PSPrinterJob
file.encoding : UTF-8
java.specification.version : 1.8
user.name : pi
java.class.path : .
java.vm.specification.version : 1.8
sun.arch.data.model : 32
java.home : /opt/jdk1.8.0/jre
sun.java.command : listProperties
java.specification.vendor : Oracle Corporation
user.language : en
awt.toolkit : sun.awt.X11.XToolkit
java.vm.info : mixed mode
java.version : 1.8.0
java.ext.dirs : /opt/jdk1.8.0/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path : /opt/jdk1.8.0/jre/lib/resources.jar:/opt/jdk1.8.0/jre/lib/rt.jar:/opt/jdk1.8.0/jre/lib/sunrsasign.jar:/opt/jdk1.8.0/jre/lib/jsse.jar:/opt/jdk1.8.0/jre/lib/jce.jar:/opt/jdk1.8.0/jre/lib/charsets.jar:/opt/jdk1.8.0/jre/lib/jfr.jar:/opt/jdk1.8.0/jre/classes
java.vendor : Oracle Corporation
file.separator : /
java.vendor.url.bug : http://bugreport.sun.com/bugreport/
sun.cpu.endian : little
sun.io.unicode.encoding : UnicodeLittle
sun.cpu.isalist : 




Java 8 release candidate is available (with steps to install on Raspberry Pi)

As announced in the post "Update on JDK 8 builds and release candidate status", the first release candidate build of JDK 8, b128 is available on https://jdk8.java.net/download.html. Including supported platform of Linux ARMv6/7 VFP, HardFP ABI, it can be run on Raspberry Pi. Here show the steps to install on Raspberry Pi.

In the steps shown here, visit https://jdk8.java.net/download.html on host PC, click to Accept License Agreement to get the actually download link of Linux ARMv6/7 VFP, HardFP ABI, it's http://www.java.net/download/jdk8/archive/b128/binaries/jdk-8-fcs-b128-linux-arm-vfp-hflt-31_jan_2014.tar.gz currently for Build b128.

JDK8 Download page
https://jdk8.java.net/download.html
Run on LXTerminal in Raspberry Pi:

  • Enter the command to downlaod the tar.gz with wget:
    wget --no-check-certificate http://www.java.net/download/jdk8/archive/b128/binaries/jdk-8-fcs-b128-linux-arm-vfp-hflt-31_jan_2014.tar.gz
  • Un-compress the downloaded tar.gz:
    sudo tar zxvf jdk-8-fcs-b128-linux-arm-vfp-hflt-31_jan_2014.tar.gz -C /opt
    The un-compressed jdk8 will be install in /opt/jdk1.8.0
  • To set the new JDK8 as default java and javac, enter the command:
    sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0/bin/javac 1
    sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0/bin/java 1

    Run the following commands to select jdk8 as default java:
    sudo update-alternatives --config javac
    sudo update-alternatives --config java
  • Now you can run the commands to verify default jdk version:
    $ java -version
    $ javac -version



After installed, you can create a test program to list System Properties to verify the installation.