Configure Your Computer

Depending on your operating system, there are a bunch of things we need to do to setup your computer up for this course.

The precise steps to take depend on your operating system.

Move on to the next section only once you’ve completed the instructions above for your operating system.

Learn to Use the Terminal

If you already know how to open and use a terminal, skip this section.

The terminal is an application that allows you to run all sorts of programs, as well as manipulate files in your own computer. It is a powerful but also dangerous tool, so please be careful with using some of these commands. On UNIX operating systems (such as macOS and Linux), the Terminal application will provide you with everything that you need.

Here are some important commands that you may find useful in this course:

cd
Change your working directory
  cd hw

This command will change your directory to hw.

pwd
Present working directory
  pwd

This command will tell you the full absolute path for the current directory you are in if you are not sure where you are.

.
Means your current directory
  cd .

This command will change your directory to the current directory (aka. do nothing).

..
Means one parent directory above your current directory
  cd ..

This command will change your directory to its parent. If you are in /workspace/day1/, the command will place you in /workspace/.

ls
List files/folders in directory
  ls

This command will list all the files and folders in your current directory.

  ls -l

This command will list all the files and folders in your current directory with timestamps and file permissions. This can help you double-check if your file updated correctly or change the read-write- execute permissions for your files.

mkdir
Make a directory
  mkdir dirname

This command will make a directory within the current directory called dirname.

rm
Remove a file
  rm file

This command will remove file from the current directory. It will not work if file does not exist.

  rm -r dir

This command will remove the dir directory recursively. In other words, it will delete all the files and directories in dir in addition to dir itself. Be careful with this command!

cp
Copy a file
  cp lab01/original lab02/duplicate

This command will copy the original file in the lab01 directory and and create a duplicate copy in the lab02 directory.

mv
Move or rename a file
  mv lab01/original lab02/original

This command moves original from lab01 to lab02. Unlike cp, mv does not leave original in the lab01 directory.

  mv lab01/original lab01/newname

This command does not move the file but rather renames it from original to newname.

Here are some other useful tricks when navigating on command line:

  • Most terminals can autocomplete file and directory names for you with tab completion. When you have an incomplete name (for something that already exists), try pressing the Tab key for autocomplete or a list of possible names.

  • If you want to retype the same instruction used recently, press the Up key on your keyboard until you see the correct instruction. This saves typing time if you are doing repetitive instructions (like running Java programs on command line while testing).

Test Run

Let’s ensure that everything is working.

Git

First open up your terminal. Check that git is a recognized command by typing the following command:

git --version

The version number for git should be printed. If you see “git: command not found”, or similar, try opening a new terminal window, restarting your computer, or installing Git again.

Java

Finally, let’s check that javac and java are working. Start by running the following commands on your terminal.

mkdir ~/temp
cd ~/temp
  1. Then, open your operating system’s file explorer in this directory. You can do this from the command line:

    • Mac: open .
    • Windows: explorer .
    • Ubuntu: gnome-open .
    • Linux Mint: xdg-open . or mate .
  2. In this newly-opened directory, create a file HelloWorld.java with these contents:

     public class HelloWorld {
         public static void main(String[] args) {
             System.out.println("Hello world!");
         }
     }
    
  3. In your terminal, enter ls (list the files/folders in this directory). You should see HelloWorld.java listed.

  4. Run javac HelloWorld.java. If this produces any output, then something may be wrong with your setup. Try opening a new terminal window or restarting your computer. If that still doesn’t work, ask a lab assistant for help.

  5. Type ls, and you should see both HelloWorld.java and a freshly created HelloWorld.class (the javac command created this file).

  6. Run java HelloWorld. It should print out “Hello world!” for you. If it didn’t, something is wrong with your setup!

  7. You’re done! You can also now delete the “temp” folder and its contents. See the terminal commands above if you need a refresher on how to do so.

The screenshot below shows what we’re hoping for when we do steps 4-7. If you see something similar to this, your Java setup is complete.

hello-world