EC

  • Edwin Chan
  • CV
  • CPSC 233
  • CPSC 331
  • CPSC 355
  • CPSC 581
  • Origami
  • Random

Tutorial 1 (Jan 19): Orientation

Topics: UNIX Accounts, Printing, Assignment Submission, Remote Access to CPSC Servers, UNIX Basics, Eclipse IDE, Setting up JDK (Java Development Kit), Java Documentation

Download PPTX slides from tutorial.
Download Code handout from tutorial.

UNIX Accounts

If you do not already have a UNIX account for the computer science lab, go to the Help Desk in MS 151. Bring your Student ID. You will need this account to use the computers in the lab, and to remote access the CPSC servers.

Printing

All the CPSC printers for undergrads are located on the first floor of Math Sciences, in the computer lab. Undergrads get a 50 page quota per CPSC course for printing, otherwise you need to pay to print. Refer to the department for more details.

Assignment Submission

For the time being, we have decided to use only digital submissions on D2L. Find "Assessments" at the top, and "Dropbox" in the drop-down menu. If you are submitting multiple files, please archive them (put all files into a ZIP/RAR/TAR file) before you submit.

For other CPSC classes, you may be required to print and hand in physical copies. You can find the physical dropboxes on the second floor of the Math Sciences building.

NOTE! To ensure fairness, your assignment code is tested on school servers (eg. the computers in the lab). You can use any editor or IDE to write your program, but it MUST work on school computers. You can also remote into school servers to test code, detailed below.

Remote Access to CPSC Servers

For the duration of your degree, you will occasionally need to access the CPSC servers at school. If you would rather not go to the lab, you can access these servers remotely from your own computer. Refer to the department page for a complete list of servers.

  • You can use any client (program) to access the servers. I personally use a combination of PuTTY and WinSCP for Windows.
  • To setup PuTTY:
    • Run PuTTY.
    • Host Name (or IP Address): linux.cpsc.ucalgary.ca
    • Port: 22 (default)
    • Connection type: SSH (default)
    • Saved Sessions: Any name you want (I'd just call it linux.cpsc.ucalgary.ca)
    • Click Save to save this profile.
    • Click Open, you should connect and be asked your User+Password.
    • You might get asked about an SSH Fingerprint, you can probably just click Yes to connect. (If you want, you can check to make sure the SSH Fingerprint matches the one listed on the department site.)
  • A note about using remote access! Because you are only connected through SSH, programs that pop up a GUI will not work by default. For example, if you use appletviewer, you will get some error about "X11". You can run Java on your own computer to test your assignments, and then go to school to test on the servers before you submit.

UNIX Basics

To complete this course, you actually only need to use the lab computers (or remote access). You can write code in emacs/vi/vim which are text editors you can access from the command line. Then you compile the java files (javac), and run the compiled results (java). Below are some of the common commands we will use in tutorial. For a more complete list, check our the CPSC department's page.

Command Explanation
ls list files by name only
ls -n list file with some additional details (there are other "flags" you can use instead of -n)
mkdir "name" make a new folder called "name"
rm "name" remove a file or folder
rm -rf "folderName" remove a folder, "r" for recursive (include all files/subfolders) and "f" to ignore prompts
touch "fileName" make a blank file
cd "path to director" change directory (eg. cd C:/Program Files/Example)
cd ./folderName a dot (.) is shorthand for the current folder's path, so you can use ./ instead of typing the path every time
cd folderName = cd ./folderName
cd ./subFolder1/subFolder2
mkdir ./
cd .. two dots (..) is shorthand for the parent folder
Example
*currently in C:/ParentFolder/SubFolder/*
cd ..
*changed directory to C:/ParentFolder/*

A typical assignment may go like this:

Command Explanation
ls check the contents of the folder I'm in
mkdir A1 make a new directory called "A1"
cd A1 change to the "A1" directory
vim A1Code.java use vim editor to create a new JAVA file
<INSERT> for Windows <i> for Macs enter INSERT/RECORDING mode so I can start typing my code
...type your code...  
esc get out of INSERT/RECORDING mode
:x save the file and exit (:q! to quit without saving)
javac A1Code.java compile the new code
java A1Code run the new code

Useful UNIX Tips

Auto-complete: Typing entire file/folder names is a pain. If you type the beginning of the file name, then press TAB, it will try to auto-complete the file/folder name. If multiple files/folders match what you entered, it will fill in what it can, and you can type a few more characters to pick between multiple matching files/folders. Try it out, it'll be easier to understand and you will never forget this.

Repeat previous commands: Just press up/down to scroll through previous commands you typed.

Spaces in file names: If your file or folder has a space in it such as "Assignment Code.java", typing javac Assignment Code.java will not work, because it is looking for the first string (block of text) only. You need to use double quotation marks to mark the entire file name as a single string, just like when you are writing code: javac "Assignment Code.java"

Stop current program/command: CTRL+C will work most of the time, if you are stuck in a program or typing a command and want to return to the command line.

Eclipse IDE

In this course, we let students choose whether they want to use an IDE or not. An IDE (Integrated Development Environment) is software that packages many tools together to help software developers.  As a beginner, you want experience with the UNIX command line, but also with IDEs. While an IDE is not necessary in this course, you will most likely spend a significant amount of time using IDEs later in your careers.

For Java development, Eclipse is probably the most popular IDE. It should be installed on the lab computers. If you decide to use Eclipse on your own computer, the "Eclipse IDE for Java Developers" downloads is best for this course.

NetBeans and IntelliJ IDEA are other IDE options.

Setting up JDK (Java Development Kit)

To develop in Java (and use java or javac commands), you will need the JDK (Java Development Kit). Install the latest JDK version, making sure to select the correct architecture: x86 (32-bit) or x64 (64-bit). If you are unsure what your computer architecture is, open Explorer and find "My Computer" or "This PC". Right-click it, and select "Properties". You can find the correct architecture under "System type".

On Windows, if you use java or javac and get an error saying "...is not recognized as an internal or external command...":

  1. Check out this answer on Stack Overflow, follow steps 1-4.
  2. Then follow this answer on Stack Overflow on how to setup your Environment Variables.
    • for JAVA_HOME, make sure jdk1.8.0_xx matches the version you downloaded (eg.1.8.0_65 or 1.8.0_71)
    • for PATH, don't include the "your-unique-entries;" part, that's just to show you how to add this if you already have something in your PATH variable.

If everything is working, you can run Command Prompt, type javac -version and see your JDK version.
If that was too confusing, email me or go to Continuous Tutorials!

Java Documentation

The official link to the Java documentation is here: http://docs.oracle.com/javase/8/docs

I'd recommend going here instead for a better overview of the documentation/resources: http://docs.oracle.com/javase/8/
P
ersonally, I find these the most useful:

  • Learn the Language > Java Tutorials Learning Paths
  • Reference > Java SE API Documentation

The API documentation may be confusing at first. However, when you start programming more and using more methods/functions/classes, you will find it extremely helpful. The documentation will tell you how to use a method, that parameters to pass into the method, what the method returns, etc. Don't worry if you don't understand this yet, you will soon!

  • Edwin Chan
  • CV
  • CPSC 233
  • CPSC 331
  • CPSC 355
  • CPSC 581
  • Origami
  • Random