0% found this document useful (0 votes)
11 views2 pages

Compiling and Running Java and C++ Programs

Uploaded by

abdulrhman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Compiling and Running Java and C++ Programs

Uploaded by

abdulrhman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Compiling and running Java and C++ programs 18/10/2017, 12)35 pm

CSCI 202: Object-Oriented Programming

Compiling and running programs on Unix/Linux

To compile and run programs on Linux you have first to login into your account in [Link] with your login and
password provided by the instructor.

Java Programs

1. Go to cs202 folder by entering the command cd cs202. Linux machine will respond with a different prompt as it is
shown below:

student@linux:~> cd cs202
student@linux:~/cs202>

If you are designing an applet, you will need to put the Java source, Java bytecode, and calling HTML script in
public_html directory on your Linux account. The general procedure is similar to the one described above.

To open the applet, enter the following URL into the browser window:

[Link]

where your_login is your Linux login and [Link] is the HTML script containing the <applet> tag.

2. To compile your program use instruction

student@linux:~/cs201> javac [Link] (make sure to use .java extension)

If the compilation is successful you will see no warnings on the screen. Just a new prompt appears in the line following
the javac instruction. If the compiler finds an error, the number of the line in your source file containing the error will be
displayed.

3. After successful compilation of your program by using the javac command you will get file [Link] in the same
directory. In order to run it enter the command

student@linux:~/cs201> java Myfile (no .class extension)

If your program hangs up, enter Ctrl-C to terminate it.

C++ programs

1. To compile your program use instruction

g++ [Link]

If the compilation is successful you will see no warnings on the screen. Just a new prompt appears in the line following
the g++ instruction. If the compiler finds an error, the number of the line in your source file containing the error will be
displayed.

2. After successful compilation of your program by using the g++ command you will get file [Link] in the same directory.
In order to run it enter

./[Link]

Alternatively, to create an executable file with a specific name, use the g++ instruction with the "-o" key:

g++ [Link] -o filename2

In this case executable file filename2 will be created and can be executed by entering

[Link] Page 1 of 2
Compiling and running Java and C++ programs 18/10/2017, 12)35 pm

./filename2

If your program hangs up type Ctrl-C to terminate it.

Some useful Unix/Linux commands

Unix as well as Windows is an operating system, and a number of very convenient text editors and window managers are
designed for it. However, since we use just a remote access to Linux machine via ssh that is not designed to exchange graphical
information from the Linux screen, we have to type in all the necessary commands.

Shell commands Comments

ls list files in current directory


cd Mydir go to subfolder Mydir
mkdir dir_name make new folder dir
rmdir dir_name delete (empty only) folder dir
rm file_name delete file file_name
cp old_file new_file copy old_file to new_file
mv ol_file new_file rename old_file to new_file
vi file_name edit file with vi editor
joe file_name edit file with joe editor
nedit filename edit file with nedit editor (in graphics mode only)
less filename open file only for reading

For more information refer to Linux tutorial for beginners

<== Back to Course

[Link] Page 2 of 2

You might also like