Compile java program in unix
Is the current working directory one of the directories listed the "current working directory" is indicated by a single. This is done as follows. Go to your home directory and use a text editor to open the file. Just before the line that begins with if Finally, you need to tell the C shell to read your. To do this issue the command: source.
In your home directory create a new directory called graph. Into that directory, copy the files Connection. Now type the following: javac FindNeighbors. You should probably see a message that tells you that the compiler cannot locate one of the classes required to carry out the compilation. This might be notification of a missing class or a message about a missing package. What's happening is that the Java compiler is looking for a package named archipelago in this example but it can't find it.
In your home directory, if you have not already created one, create a directory named lib. Into this directory copy the file archipelago. The archipelago. These classes are in a special file type that we will look at later when we cover jar files. We're placing it in a directory that we can place such utilities that we need in many projects.
Now we need to tell the Java compiler where to find this jar file. Go to your home directory and edit the. What we're doing is changing the CLASSPATH string variable so that it contains, in addition to the other directory names, the name of the jar file in the lib directory in your home directory. If you are a careful person, you will have noticed that in a list of directories , we have placed the name of a file. The Java compiler understands that jar files are like directories containers of files and it "does the right thing" to extract the needed.
Making a change to the. You can get around this by typing in your home directory: source. This causes the C shell to re- execute the commands in the. Now go back and re-compile the Java program that we tried above: javac FindNeighbors.
This time the Java compiler should be able to find the archipelago. The javac command can take several options. This was the simplest of the example.
The sample program had just one class. The Java compiler creates a class file for each class in your program. Things get complicated for bigger programs and projects. This is why I advise installing Eclipse on Ubuntu for proper Java programming. It is easier to program in an IDE. I hope you find this tutorial helpful.
Questions or suggestions? The comment section is all yours. Also a movie buff with a soft corner for film noir. Please log in again. The login page will open in a new tab. After logging in you can close it and return to this page. You should put the files inside a subdirectory of your cs or cs directory. Type the following: o cd this will take you to your home directory o cd cs or cs - such a directory should be automatically created when you register for the course.
These files are also available on the Web: o Factorial program - A small program which calculates factorials. 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. 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. You can verify this by using the ls command. To run the program you need to run the java interpreter with the name of the class to run along with any parameters that the program expects.
The factorial program expects an input of 1 parameter, the number to calculate the factorial value for. Type java fact 1 to calculate 1! Don't bother running the program with input of much greater than 10, as the factorial numbers grow really fast, and you start to get overflow. The most important things you need to do is to find out the values of variables in your code and monitor the execution of the code, particularly the calling of procedures and functions.
The java System. Placing "debugging printouts" throughout the program at critical places to monitor the execution can be helpful. These printouts can easily be commented out when the debugging is completed, and later uncommented if further bugs show up later. But what to do when this becomes too tedious? Another option is to use a debugger, such as jdb. We'll go through an example which takes you through some basic debugging tasks. This tutorial goes through using the text version of the debugger.
At the completion of the tutorial you should be comfortable enough with the different debugging techniques. For those students that want the debugger to be a little more visual, there is a further tutorial that teaches you how to integrate jdb and Emacs together into a development tool see the bottom of this tutorial.
The debugger would be very useful in allowing you to step through the code, and show you the intermediate values being generated at each recursive call.
0コメント