Using Java

from the Linux shell (command line)

Part of CS:2820, Object-Oriented Software Development, Fall 2015
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

First: Use to open a remote desktop on one of the Linux servers where we will be working. These servers can be accessed from anywhere on the Internet using your HawkID and password.

Fastx offers several ways of connecting to the server:

If you open a MATE session, you can open an xterm window on your remote desktop by clicking on the xterm icon. Hover the mouse over the icon and a popup should appear saying "MATE terminal / Use the command line."

We will emphasize using the command-line tools in this course because they continue to be the primary tools used in many parts of the computer industry. In the Unix/Linux world, the command-line interface is known as the shell. For help with any shell command, use the command man; for example, type man pico to learn more about the pico text editor.

A number of text editors are available from the shell for working with source and data files. Some are clumsy but almost self-teaching such as pico and nano. The classic and far more powerful editors used by many software developers are emacs and vi; it is worth taking the time to learn one of these.

The following shell commands matter to Java programmers:

Compile a java source file that defines the class classname. Source files must be named to match the class they define, with the extension .java. The compiler will generate an output file named classname.class.

java classname
Run compiled code from the file classname.class which must contain the public method main.

javac @classlist
If the file classlist holds a list of file names that make up the project and then compile them as a group. One class must define a public main method for the result to be executable.

Advice: When you create large programs consisting of many classes, dedicate a sub-directory to the project. If your project is named, for example, project the following shell commands will be useful:

mkdir project
Create the directory

rm -r project
Delete the the directory and everything it contains. By default, the system will ask permission to delete each file (respond y for yes).

cd project
Change the current directory to the project

cd ..
Go back to the parent directory

Configuring the vi editor: The vi editor has many options:

:syntax on — turns on color syntax highlighting
:syntax off — turns it off
Color syntax highlighting can be useful but it can be awful. Blue is particularly unreadable.

:set paste — makes vi friendly to dragging and dropping text.
:set nopaste — may mess up indenting and comments when you drag and drop.
:set autoindent — auto-indent lines that follow indents.
:set noautoindent — disable that.

You can put configuration options in your .vimrc file; one option per line without leading colons.

In the Unix/Linux world, file names with leading dots are invisible. By default, you won't see the file listed in directories, but you can open it for editing. Also, the file name ending rc means "run commands," and by default, many Unix/Linux applications look for and use a hidden "rc" file when they are launched.