Skip to content
Anthony Christe edited this page Aug 28, 2013 · 2 revisions

What will we be doing in lab?

  • Hands on
  • Detailed examples
  • Detailed traces of algorithms
  • Explanations (mini-lectures) on difficult material
  • Going outside (did someone say sidewalk chalk?)
  • Personal attention
  • Debugging techniques
  • Testing techniques
  • Unix
  • git/github
  • Documentation
  • Static analysis (if time permits)
  • And more

Lab Materials

Submitting Assignments / Grading

Bonus

Lab Policies

  • Absolutely no food or drink in the lab (if you're thirsty, step out for a drink)
  • Don't be disruptive
  • Be supportive

Coding Standards

Documentation

  • Name must be documented at the top of each source file
  • Full Javadoc is not required (however, heavily encouraged)
  • Each method must have at least a single basic Javadoc comment describing what the method does
/**
 * Computes the sum in the range of 1 (inclusive) to max (exclusive).
 */
public int sumRange(int max) {
  int sum = 0;
  for(int i = 1; i < max; i++) {
    sum += i;
  }
  return sum;
}

Programming Environment

  • JDK >= 5, 7 is recomended (Oracle JDK)
  • You may use your favorite IDE
  • Knowledge of the command line tools are required (java, javac, jar, javadoc)
When I try to compile, I get the following error: 'javac' is not recognized as an internal or external command, operable program or batch file.

This means that Windows cannot find the javac program. The JDK install does not usually set your system PATH variable for you. Here's how to fix the problem.

  • Find out where the javac.exe file was installed. It will probably be somewhere like C:\Program Files\Java\jdk1.7.0_10\bin\ (On Vista or Windows 7, also check in Program Files (x86), if you have one. You might also try a file search for javac.exe if you can't find it by browsing.)
  • Once you find javac.exe, type the full path on the command line, something like this:

"C:\Program Files\Java\jdk1.7.0_10\bin\javac" -version

  • You may need the quotes around the file path if it contains any spaces.
  • Doing this is just a test. If it works (Windows can now find javac and prints a line or so telling you the version), then Java is installed correctly and you know where it is.
  • Now you can update your path so you don't have to type the whole path name every time. These are the steps to do this on Windows 7:
  • Go to Start -> Control Panel -> System. (It's easiest to find System when you change Control Panel to Classic View.)
  • Click the Advanced System Settings link. (Skip this step on WindowsXP.)
  • Go to the Advanced tab
  • Click the Environment Variables button
  • Scroll down through the System variables until you find Path.
  • Edit this variable, adding the path up to but not including javac (so probably C:\Program Files\Java\jdk1.7.0_10\bin) to the end of the list. Make sure there is a ; (semi-colon) between this path and the one before it.
  • Click OK for all of that, saving it all.
  • Close any open command prompt windows (since these still have your old path settings).
  • Open a fresh, new command prompt window. Typing either javac -version or javac Hello.java should work now, without having to type the whole path to javac.
  • If you ran into problems, try searching YouTube for "java set path on windows" for walkthu videos. If you're still stuck, let your TA know how far into this process you made it and what went wrong. If you have a laptop, feel free to bring it into lab or office hours for help.
javac works, but when I compile I get this error:

error: cannot read: Hello.java 1 error

Alternately, you might get this error:

javac: file not found: Hello.java Usage: javac use -help for a list of possible options

  • Either of these means javac can't find the .java file you are trying to compile (in this case, Hello.java).

  • Check that you are in the same directory as the file.

  • Type dir on the command line and you should see your .java file in the list of files displayed.

  • If you need to switch directories to find where you saved Hello.java, remember that cd .. moves up a level, and cd dirName will move down one level into the sub-directory named dirName. See Using the Windows Command Prompt for more.

I have a Mac, and there's no JDK download option for a Mac.
  • Modern Macs come with a JDK already installed.

  • To write your code, use the simplest text editor you can find listed under Applications.

  • If there is no plain text option when you go to save the file, you may have to go to Format -> Make Plain Text (or something similar). This will remove all formatting toolbar options and allow you to save as plain text.

  • To compile and run your code, go to Applications -> Utilities -> Terminal. Terminal works basically the same way as the Windows Command Prompt, although instead of dir, you have to type ls (or ls -l, for a longer view). (Those are Ls, not 1s, since "ls" is short for "listing".) The cd, java, and javac commands are the same.

Getting Help

  • Myself and a Lab Assistant (LA) are both available during labs
  • Officer hours and appointments
  • Open Lab Hours, every night (6-9PM), 318 A)
  • Show me how you tried to solve your problem

FizzBuzz

Write a program with the following specifications:

  • Loop through the numbers 1 to 100
  • If the number is divisible by 3, print out Fizz
  • If the number is divisible by 5, print put Buzz
  • If the number is divisible by both 3 and 5, print out FizzBuzz
  • Otherwise, print out the number
  • Why Can't Programmers Program?

Clone this wiki locally