Java Snippets

Hamburger icon

If you don't have Java

First check that you don't have java by typing:

$ java -version

and

$ javac -version

If nothing comes out, then install by typing:

$ sudo apt-get install default-jre

This will install the Java Runtime Environment that will allow you to use java to run the compiled snippets.

You might prefer to do:

$ sudo apt-get install default-jdk

to install the Java Development Kit that includes javac, which will allow you to compile the snippets and generate your own class files. It includes the jre, so if you install this you will be able to both compile and run.

Compiling and running

Once you have Java in your system:

Go to the Java snippets folder and compile as:

$ javac folder/mainprogram.java

Run as:

$ javac folder.mainprogram

For example, for the snippet "Age Calculation":

$ javac ageCalc/AgeCalc.java
$ java ageCalc.AgeCalc