CS计算机代考程序代写 compiler Java algorithm interpreter COSC1285/2123: Algorithms &

COSC1285/2123: Algorithms &
Analysis Workshop 0

1 Topic
UNIX induction and Java.

2 Objective
• Become familiar with UNIX environment.

• Become familiar with UNIX terminal.

• Be able to compile and modify a Java code.

3 Unix induction
• Read the RMIT Unix Survival Guide. The following link has RMIT Unix induction:

RMIT Unix Survival Guide.

This induction is designed to get you orientated and comfortable using a unix/linux
based operating system. The link also has videos to get yourself acclimatised to the
Unix operating system.

4 Teaching Servers
Three CSIT teaching servers are available for your use: (titan|saturn|jupiter).csit.rmit.edu.au.

Details for how to access these servers are available in RMIT Unix Survival Guide.

You are encouraged to develop and run your labs and assignments on these servers.

We advise you to use either WinSCP for Windows or Cyberduck for Mac. You may also
use Putty.

5 Guide
In this section we will learn how to use a Java compiler in a command-line Unix envi-

ronment. The java compiler is invoked with the javac command.
The Java compiler, javac, takes your source file and translates its text into instructions

that the Java Virtual Machine (Java VM) can understand. The compiler puts these instruc-
tions into a byte code file.

Now, bring up another shell window. To compile your source file, change your current
directory to the directory where your file is located. For example, if your source directory is
/home/s30xxxx/java, you would type the following command at the prompt and press Return:
cd /home/s30xxxx/java

If you enter pwd at the prompt, you should see the current directory, which in this
example has been changed to /home/s30xxxx/java.

Assume that we already created the following first Java code called HelloWorld

© 2021 RMIT University 1

https://sites.google.com/rmit.edu.au/unixinduction
https://sites.google.com/rmit.edu.au/unixinduction

/* HelloWorld.java

*/

public class HelloWorld

{

public static void main(String[] args) {

System.out.println(“Hello World!”);

}

}

If you enter ls at the prompt, you should see your file: HelloWorld.java
Now you can compile. At the prompt, type the following command and press Return:

javac HelloWorld.java

The compiler now has generated a Java byte code file: HelloWorld.class.
At the prompt, type ls to verify the new file is there.

Now, let’s implement our Java code. The Java VM is implemented by a Java interpreter
called java. This interpreter takes your byte code file and carries out the instructions by
translating them into instructions that your computer can understand.

In the same directory, enter at the prompt:
java HelloWorld
Now you should see:
Hello world!

6 Exercises
Use the terminal to implement the following Java programs.

• Write a Java program that takes two numbers as input and display the product of two
numbers

• Write a Java program that takes three numbers as input to calculate and print the
average of the numbers.

© 2021 RMIT University 2

Topic
Objective
Unix induction
Teaching Servers
Guide
Exercises