CSU Long Beach
CECS 274
Programming and Problem Solving II


Syllabus
Schedule
Grading
Project 1
Project 2
Solution to Project 2
Project 3
Solution to Project 3
Project 4
Solution to Project 4
Project 5
Set Solution to Project 5
Map Solution to Project 5
Lecture Notes
Basic Unix Commands
Basic vi Commands
More vi Commands
Using Eclipse
Compiling and Running Java on Unix


Mimi Opkins Home

Compiling/Running Java on Unix

     

    1.                  Connecting into Linux: 

    a)                  From home: 

    i)                    Prepare for the connection via any of the following methods:

    a)                  If you have broadband, you are already prepared.

    b)                  If you have a dial-in account with AOL or a similar service, dial your provider and login in your usual manner.

    ii)                  Connect to heart via telnet.  If you are using a Microsoft operating system on your home computer, select Start | Run and type telnet heart.cecs.csulb.edu in the text box.

    iii)                Login to heart at the prompts with your account and password. 

    iv)                At the prompt, type ssh linux (or rsh linux) and follow the login and password prompts.

    v)                  You can repeat the telnet heart and ssh linux commands to open as many windows as you need.  Typically, you might want one window per file you are editing and another window to compile and execute your program.

    vi)                Type logout to exit the linux server.

    vii)              Type logout to exit heart.

    b)                  From school:

    i)                    Login and password.

    ii)                  Type the following command to start X Windows:  startx

    iii)                Click on Applications | System Tools | Terminal to open a console window.  Repeat process for as many windows as needed.  Typically, you will have one or more windows in which to display and edit your source code and another window to compile and execute your program.

    iv)                To move a window, click on the title bar of the window using the left mouse button and drag the window to its new location.

    v)                  To resize a window, move the cursor to the bottom right corner of the window until it changes into a diagonal arrow (or on the sides of the window to lengthen or widen it).  Click on the left button, then drag the arrow to adjust the window size.  The minimize, restore, maximize and close buttons on the title bar of the window perform in a manner similar to Microsoft windows. 

    vi)                To close a window, click on the close button in the title bar of the window.

    vii)              To exit X Windows, select menu option Desktop | Log Out.

    a)                  At the prompt to end the session, click on the OK button.

    viii)            Type logout to exit Linux.  You must logout from Linux; otherwise, other people will have access to your account.

     

    2.                  Editing source files:

    a)                  Use either the vi or vim editor (can be difficult to use) or pico (easy to use).

    b)                  Save the source file with a .java extension.

     


    3.                  Compiling and linking programs (done in one step):

    a)                  For one source file, enter javac filename. 

    b)                  For multiple source files, enter javac filename1 filename2 filename_etc.

    c)                  Correct any compiler errors and use javac to recompile the file(s).

    d)                 The java compiler will create .class files for each of the respective .java files.  The class file contains the bytecode.

     

    4.                  Interpreting and running the program

    a)                  Type java filename to run the program where filename is the name of the file containing the main method.  Whereas when compiling the program, you typed the .java extension as part of the file name (e.g. javac HelloWorld.java), when you run the program you omit the .java extension (e.g. java HelloWorld).

     

    5.                  Creating a run-time output listing,

    a)                  Enter the command script at the prompt. 

    b)                  From this point until you type exit (or control-d), everything that appears on the screen will go into a file called typescript. 

    c)                  After you type exit, you can print the typescript file as you would print any other file.

     

    6.                  Printing source code, run-time listings or any other file when in the lab:

    a)                  Prior to doing any printing, you need to provide a ream of paper (500 sheets) to CECS support to set up a paper account.  Do this as early as possible.  It takes a few days to set up the account.  The instructions for setting up a paper account are on the bin outside the elevator on the 4th floor of CECS.

    b)                  At the prompt, type lpr filename.

     

    7.                  Transferring files between your home PC and your Linux account:

    a)                  Start your web browser or if you have broadband, click on Start | Accessories | Windows Explorer.

    b)                  In the URL, type ftp://account:password@heart.cecs.csulb.edu, replacing account and password with your own account name and password.

    c)                  You will see a display of all directories and files in your Linux account.  Move and copy files in the same manner that you do these activities when using Microsoft.