CS630 Java Development Setup: on Linux at cs.umb.edu and on your home machine, Fall 2019

Linux at cs.umb.edu: Java setup.
For Linux systems such as users.cs.umb.edu and our system, topcat.cs.umb.edu, you should not need to do any setup to use java. To make sure the java is a recent-enough version, simply use the commands under Linux java and setup tests below.  To check that java and javac are in /usr/bin as expected, use the "which"; command as follows:

    $ which javac
    /usr/bin/javac

Linux at cs.umb.edu:  editors Hopefully you know emacs or vi or another Linux editor.  We will do most of our software development on PCs, and then test the systems on Linux at cs.umb.edu for final delivery. This works well because of the robust portability of Java. Project deliveries are to the Linux filesystem at cs.umb.edu. See AccessToCSHosts.html for more info on file transfers.

Linux at cs.umb.edu: java setup test:

java-version   should output
java version "1.8.0_xxx", plus two more lines of text, where xx stands for 3 digits

env|grep CLASSPATH    should output nothing.  If it does give output, try to hunt down the source, usually in .profile or .bashrc, or files they invoke.

Home System Software Setup

For logging in to cs.umb.edu systems from home PCs and transferring files, see AccessToCSHosts

Text Editor

Windows: download Notepad++, unless you already have (and know how to use) emacs or vi or another pure text editor. Note: be careful to avoid downloading other tools at this site: find the "Notepad++ Installer" link.
Mac: download BBEdit  (previously known as TextWrangler) unless you already have and (and know how to use) emacs or vi or another pure text editor. Note that Mac's TextEdit does not produce pure text files. As on any UNIX system, vi is available at the shell prompt (in Terminal).
Linux: As on any UNIX system, vi is available at the shell prompt. Other possibilities are gedit (simpler) and emacs (harder).

Java setup on home systems

Java for Linux or Mac OSX:

first see what java is already there by using "java -version"; and "javac -version";. If these versions agree and show 1.6 or 1.7 or 1.8, or later, you do not need to download the JDK.  For Linux, you may be able to install a newer Java JDK by using the package system of your Linux distribution. For the Ubuntu Linux, see http://tecadmin.net/install-oracle-java-8-jdk-8-ubuntu-via-ppa/#

Java for Windows

Assume you need to download Java, unless you have previously set up Java for development.

Downloading Java from Oracle - We will be using Java 8 or higher (or Java 7) from Oracle.  Everything we need from Oracle is in the Java SE (Java Standard Edition) download, that is, the  JDK (Java Development Kit) for Java 8.  Note that the JRE (Java runtime environment) is not enough. Download and install the latest open-source JDK (version 12) from https://jdk.java.net/12/  Note that the Java SE installation will install a system JRE, i.e., possibly disrupt other Java development on the system if you need an older Java for some reason, but fine if this system is used only for current Java development. Java 12 can be used as a maintenance release of Java 8, Java 7, or Java 6 for normal Java programming.

      If you already have the Java 7 or 8 JDK downloaded from Oracle, that's good enough. Also, it's OK if you have the larger (360 MB) distribution of JavaEE (Java Enterprise Edition), which contains the full Java SE JDK in its jdk subdirectory.

JAVA_HOME and PATH Environment Variables  

The environment variable JAVA_HOME tells where the JDK is located on the system (Windows, Linux, or MacOSX). Specifically, it is the directory with a bin subdirectory containing java and javac.  JAVA_HOME is used by programs (other than java and javac) that need access to resources in the JDK.

The environment variable PATH holds the search path used by the system (Windows, Linux, or MacOSX) to locate executables. When we add a new executable located in a directory not listed in PATH, we need to add its directory to PATH, so we can run the program from anywhere on the system. How to do this depends on the system as follows.

PATH for a Windows machine: Use System Control Panel>Advanced>Environment to define the JAVA_HOME user environment variable as C:\Program Files\Java\jdk1.8.0_xxx or c:\Java\jdk1.7.0_xx or wherever you put the JDK download. There is a shortcut method to get to this control panel, as follows. Click the Start button, fill in "env" in the text box, and click on "Edit Environmant Variables for your account". enable command-line java development, edit your user Path environment variable to include your JDK's bin directory, using %JAVA_HOME%\bin as its value. Use a semicolon between entries in the value of Path. For example, my Path value has c:\Program Files\emacs\bin; %JAVA_HOME%\bin;    Test the environment variables by creating a new command window and using the "set" command.

PATH for a Linux machine: It should work to add the environment variables to .profile (or .bashrc or .bash_profile possibly, non-Ubuntu Linux) in your home directory. For example, if javac is in /usr/bin, it's already on the PATH, so you don't need to do anything here. If elsewhere, add this line to .profile:

  export PATH=$PATH:/usr/local/jdk1.8.0_60/bin  (for example)

if you have downloaded Java to /usr/local/jdk1.8.0_60. Note the colons between directories on the PATH, vs. semicolons for the Windows PATH. Log out and in again and see if javac is now available. If you did the download through a package system like apt-get for Ubuntu, you may not need to do anything extra to get the new java and javac on your Path, so check the resulting versions by "java -version" and "javac -version". If these fail or show an old version, you need further work. Ubuntu/Debian Linux has "update-alternatives"; for handling multiple versions of Java on the system, but it is somewhat difficult to use.

PATH for a MacOSX machine: Don't even try to Google this topic (environment variables on Mac OSX), because you will only find a confusing contradictory morass.

From the Terminal application, i.e., the UNIX shell, MacOSX works very much like Linux, except that .profile is called .bash_profile. Put the following line in .bash_profile in your home directory, creating a new file if necessary. After download from Oracle, look in /Library/Java/JavaVirtualMachines for the exact directory name in the following JAVA_HOME value. The following shows the specification valid in August, 2016.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/     (replace 101 as needed to match)
export PATH=$PATH:$JAVA_HOME/bin

Then logout and in again and check by "echo $JAVA_HOME"; in Terminal. Try the Java setup test below. This will establish the needed environment variables for command line work, i.e., commands in Terminal.

Java setup test

Note: use a brand new command window or shell if you just changed your environment variables.

1. java -version should output (first line of output):

    java version "12.0.x" or "11.0.x" where x is one digit (maybe two)
or
   java version "1.8.0_xx"   or "1.7.0_xx"      where xx is one or more digits

Windows Failure case:   java -version shows java 1.6.x (or some other wrong version). Look for a java.exe in Window's system32 directory.  Rename it to java_hold.exe (run CMD as administrator for this by right-clicking its icon and selection "run as administrator", or log in as Administrator and use Windows Explorer.)
Mac/Linux Failure case:  All set up as above, but java -version shows java 1.6.x (or some other wrong version). Look for java in /usr/bin. Just rename it to java_hold (cd /usr/bin; sudo mv java java_hold) . If it's not in /usr/bin, find it using "which java". This will print out where it's found on the system search path.

2. javac -version                   should output the same version as "java -version". If it doesn't, you have java and javac in different places but both on the system search path. Check in those directories (on the system search path) and delete or rename the java executable out of the way.

3. On Windows, set|find "CLASSPATH"    should output nothing. Similarly, env|grep CLASSPATH should output nothing on Mac/Linux  If it does give output, look for an old environment variable setting and delete it.