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

Prerequisite: Open a Linux termial window (using an SSH client such as PuTTY or SSH, or use FastX to open a remote linux desktop and then open the terminal application on that desktop).

You have a choice of many text editors to work with source and data files. Some are clumsy but almost self-teaching such as pico and nano. The classic editors used by many developers, emacs and vi, can be hard to use. For help with any shell command, use the command man; for example, type man pico.

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 output file will be named classname.class.

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

javac @classlist
For projects involving multiple classes, create a file called, for example, classlist to hold the file names that make up the project and then compile them as a group. One class must define main.

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.