Computer Science 235 :: Data Structures and Algorithms

Welcome to CS 235 Orientation


We assume that you have been introduced to the Java programming language prior to this course and that you know how to edit, compile and run a Java program. The purpose of this orientation is to help you be prepared for the course and to teach you how to compile and run a packaged Java program and to be able to submit it for passoff.

Create a CS account

This course requires that you have an account with the CS department so if you don't have one already you will need to get one. Click here to create your CS account. If you are in a CS lab and need to create an account, you should be able to login to a computer by entering guest2 as the user and password at the login screen.

Packaging a Java program

Why do we want you to learn to make packages in this class?

First so that you can better understand the Java API. If you will read and understand the Java API you will be more successfull in this course and the labs will be much easier for you. We encourage you to use the Java API as much as you can in this course; however, there will be times when we will specify that you can not use certain classes in the API. The purpose for this is so you will be able to learn about and have a better feel of what Data Structures are.

Another reason that we want you to learn how to use packages is because packages help you organize your projects.

So how do you edit, compile and run a packaged program?

If you are going to put your source code into a package, you will only need to add one line of code to the top of your file. Here is an example:
/***********************************************************
 * An example of an unpackaged hello world Java application.
 **********************************************************/ 

public class HelloWorld 
{
	public static void main(String[] parameters)
	{
		System.out.println("Hello World!");
	}
}
/***********************************************************
 * An example of a packaged hello world Java application.
 **********************************************************/ 

package cs235.PackageExamples;
			
public class HelloWorld 
{
	public static void main(String[] parameters)
	{
		System.out.println("Hello World!");
	}
}
When you are putting your code into a package you need to make sure that the directory structure and the package structure match exactly (case sensitive). When you compile a packaged Java program you need to be in the directory that contains the source code. The command to compile is:
javac -classpath rootDirectoryOfYourPackage *.java

So if C:/MyPackages/cs235/PackageExamples/*.java is the path that contains your *.java files and you are in the directory C:/MyPackages/cs235/PackageExamples/ you would type the following at the command line in order to compile the code.
javac -classpath ../.. *.java

Notice that C:/MyPackages/ is the root directory for the package.

When you run a packaged Java program from the command line you need to be in the directory that contains the class files and you type:
java -cp rootDirOfPackage dirInPackageThatContainsClassFiles.ClassName

So continuing from the the previous example you would be in the C:/MyPackages/cs235/PackageExamples/ directory and type:
java -cp ../.. cs235.PackageExamples.HelloWorld

Submitting code for CS235



Here is an example of how to submit your file for passoff, using the HelloWorld code:
Open your home folder using Fedora's GUI, then open cs235 and then PackageExamples. Use ctrl click to grab all of the .java files used in your project, in this case, just the HelloWorld.java file.
Right click on the highlighted files and select the create archive option. Pick the .jar extension and then select the desired location to save it to (probably the same folder you are in), and then click create.

This method of archiving only works on linux machines. If you are writing your code on a non-linux computer, email them to yourself and download them onto a machine in the lab, and your problem is solved. If you would like to learn how to do this from the command prompt instead, you must see a TA. It isn't hard, but if it is done wrong you can end up overwriting your source code and ruining the next several days of your life.

Finishing Up
Now go the the Project Submission Page (the link is on the left-hand side of the class homepage). Enter your correct RouteYID, RouteY password, select the correct lab #(0 here), and the correct .jar file for the HelloWorld project.

After your code is submitted, meet with a TA for pass off (not needed for the HelloWorld project).

If you have any questions or can not edit, compile, run and submit a packaged program after reading this orientation please visit a TA in the TA Office located at 1044 TMCB or go to one of the orientation meetings.