AMAPstudio

### Sidebar

The Java training online

# 1. Installation

Capsis can be run on several systems. This training can be followed under Linux, Windows or MacOSX. Installations are required before starting the exercises: an expected version of the Java Development Kit and the Java exercises archive must be installed, see blow.

## 1.1 How to use the terminal

Where is the terminal ?

During the training, you will need to enter commands in the terminal.

• Under Linux, the terminal is called a shell, search an application called 'shell' or 'terminal'
• under Windows it is a command-prompt: try 'Ctrl+r', or execute 'cmd', or look in 'Programs > Accessories'
• under MacOSX, it is called a terminal: find the 'terminal' icon or look in 'Applications > Utilities'.

Current directory

In the terminal, you are always located in a directory: the current directory (or folder), you can see it in the prompt (where you are supposed to type a command)

Main commands

Under Linux and Mac, the commands are the same (Unix commands) and '~' means 'your home (personal) directory'

Linux / MacOSX Windows
see the current directorypwd (print working directory)echo %cd%
get the list of files in this directoryls (list files and directories) dir
move down into a directorycd directoryName (change directory) cd directoryName
move up one directorycd .. cd ..
create a new directory in the current directorymkdir directoryName (make directory)mkdir directoryName

## 1.2 Check if the java you need is already installed...

You need a Java Development Kit (JDK) installed, version 1.8 (higher may be ok).

Note: if you find a Java Runtime Environment (JRE), this can run Java programs but you will not have the java compiler we need to write Java programs, so a JDK must be installed.

Check this by entering the following two commands in your terminal, from whatever directory, they should both return the same version of Java.

All operating systems
version of java (i.e. the Java Virtual Machine, JVM) runs the java programs)java -version
version of the java compiler (to build java programs)javac -version

E.g. under Linux: both commands return version 1.8.0, correct (the number after the _ does not matter here)

coligny@marvin-13:~$java -version java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) coligny@marvin-13:~$ javac -version
javac 1.8.0_101
coligny@marvin-13:~\$


## 1.3 ... Or install Java on your computer

The reference Java for Capsis is the version JDK 1.8 by Oracle, you may find it there:

• The Oracle JDK 1.8 (official, Oracle registration needed), choose the installer for your system then run it.
• An alternative is available for Windows and Linux only, see the OpenJDK 1.8 on this page, this version is a zip archive (.zip or .tar.gz), you will have to unzip it in a local Applications folder (where you like).

How to tell the system this is the default Java ? (PATH)

Once installed, to tell your system this is the default Java, you may still have to update the PATH system variable.

When you type a command (or program) in the terminal, the system looks in the current directory. If not found there, it looks in order in the directory names listed in an environment variable named PATH (same under Linux, MacOSX and Windows), until it finds the command.

You need to change this PATH variable to add a directory at the top of the list: the directory containing the java and javac you've just installed.

Open a file manager, go to the directory you've installed or unzipped your Java, find the bin/ directory containing the java and javac programs and copy its name in the clipboard with Ctrl-C.

For Windows, find the environment variables configuration (Try Configuration Panel > System > Advanced > Environment Variables), find the 'System' section, locate the PATH variable in the list, edit it, add the new directory name (Ctrl-V) then ensure it is at the top of the list.

For Linux Ubuntu users, the PATH may be tuned in the file /etc/environment, e.g. below to be adapted for your machine (use a ':' between the paths), then type 'source /etc/environment'

PATH="/home/coligny/Applications/jdk1.8.0_102/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

Note: setting other variables like the CLASSPATH or JAVA_HOME is not needed here, neither for these exercices, nor after for the Capsis end-users or modellers (see the pages about compilation in the Capsis Documentation page).

Check your configuration (see previous section) until you get the expected answer, close and reopen the opened terminals, only the applications starting from now on will now the correct path for Java.

## 1.4 Install a simple text editor

To write your programs, you need a simple text editor with few features including syntax coloring (colors for the Java keywords…). If you already have one, you can use it, else look at one of these:

For Windows:

For Linux:

• Gedit
• SublimeText

For MacOSX:

• TextWrangler
• Atom

## 1.5 Create a directory for your exercises

Create a new directory named java/ to write your exercises.

The new directory must be somewhere you can access easily on your machine, somewhere under your personal directory for instance.

You can create it with the terminal and mkdir, or with your file manager.

For the following exercises, you will need to reach this java/ directory in the terminal with cd.