Newsletter:

(Tutorial) Tutorial for Java debugging


Tutorial : Tutorial for Java debugging

How to Compile and Run a Java Program in Unix

  • The first step is to write a program that you will compile. To save some time, we already have a couple of test programs set up for you to experiment with. You should put the files inside a subdirectory of your cs241 (or cs230) directory. Type the following:
    o cd (this will take you to your home directory)
    o cd cs241 (or cs230 - such a directory should be automatically created when you register for the course. If you don't have one, create it)
    o mkdir jdb
    o cd jdb
    o cp ~cs-marks/pub/resources/java/jdb/*.java . (don't forget the final period - it tells UNIX to copy the files to the current directory) 

  • At this point if you type ls you should see two files in the directory. These files are also available on the Web:
    o Factorial program - A small program which calculates factorials.
    o Fibonacci program - A small program which calculates Fibonacci numbers. 

  • Now we've got a couple of programs to compile. First let's look at the factorial program. Open the program using your favourite text editor. For the remainder of the tutorial it is assumed you are using pico, although you may want to use a different editor such as Emacs (and you should certainly use a different editor for your assignments). Type
        pico fact.java

  • Take a look at the code (it is not very long). It uses recursion to solve the problem - not very efficient, but it is perfect for what we are going to do. Manually trace through the code to get an idea of what it is doing. When you are done looking at the code, press Ctrl-X to quit the program.

[Read More...]

Courtesy:- Student.cs.uwaterloo.ca