Self-Study 1, CPSC 331, Fall 2010

home page -  news -  syllabus -  schedule -  assignments -  tutorials -  tests -  java -  references -  Mike Jacobson

Self-Study 1 -  Self-Study 2 -  Self-Study 3 -  Self-Study 4 -  Self-Study 5 -  Self-Study 6 -  Self-Study 7

 Setting Up Your Java Environment

About This Exercise

This exercise can be completed by students at the beginning of the term. It does not rely on any material presented in lectures or tutorials. Students who successfully complete this assignment will have ensured that they have the basic Unix and programming skills needed at the beginning of the course — or, at the very worst, they know more about the remedial work they will need to do as soon as possible.

Students who have completed any version of the Computer Science prerequisites, CPSC 219, 233, or 235 using Java will likely not find anything to be new here. Students who have completed the Engineering prerequisite, ENCM 369, or who completed a computer science prerequisite using a different object-oriented programming language, probably will find new material here. By working through the exercise they will ensure that their computer environment is set up for Java program development and compilation and that they can write simple Java programs.

This exercise will not be worked through or discussed extensively in tutorials. Instead it will be assumed that you worked through it on your own ahead of time! You will be given a chance to ask for help (if you ran into problems) at the very beginning of the first tutorial — but the teaching assistant will be discussing more advanced material unless students indicate that they worked through this material and had problems with it.

Expected Background and Preparation

It is assumed that students are reasonably familiar with the UNIX (or Linux) operating system. If you have not used UNIX or Linux before, or if you do not know enough about this to customize your computing environment, then you should work through an online UNIX/Linux tutorial for beginners before you do much more. This tutorial assumes the use of the tcsh shell. You might be using another popular command shell — most likely, bash. Additional information for users of bash is also available.

It is also assumed that students are familiar with either Java or C++. Completion of the programming prerequisite for this course with a grade of C− or better is reasonable evidence of this. If (for whatever reason) you have been admitted into this course but you have not received instruction in the use of either Java or C++ then you should inform the instructor of this as soon as you can.

Finally, it is assumed that you have a requested, received, and successfully logged onto the Department of Computer Science account that you will use for this course. Please read the following information about Department of Computer Science accounts and follow the instructions to apply for this if you have not already done so. Note that, while Windows PC accounts are available, it will be assumed that you are using a UNIX/Linux account for this course, and detailed information about how to use a Windows account will not be provided.

Problems To Be Solved

  1. Work through the online “Hello World!” Tutorial for SunOS and Linux. It should not be necessary for you to download a version of the “Java Development Kit” when you are working at school — this has already been done for you.

    Please contact the course instructor as soon as possible if you are not able to compile and run the program that is described in this online tutorial.

  2. Read Chapter 1 of the course text book.

  3. The tutorial that you worked through when solving the first problem (above) is part of a considerably more extensive set of online Java tutorials. These go into more detail than the chapter you were asked to read when solving problem #2. Work through a few of these additional tutorials, to see what they are like. You might find these to be helpful to learn more about Java as this course progresses.

    You might also find some of the resources listed on the Java basics page to be useful as you learn Java basics.

  4. Up until now it is probably true that you are executing the javac command in the directory that contains the source file you wish to compile, and that the executable file generated by the compiler is written to the same directory. Another organization of files is more useful if you are developing other software for other people to use.

    Choose a sub-directory of your home directory for storage of Java source files as well as a completely separate sub-directory for storage of the class files that you compile from your source files. Once you have chosen and created these sub-directories, make any changes to your computing environment that are needed to ensure the following.

    • The javac utility automatically stores Java class files in (an appropriate sub-directory of) your chosen sub-directory for compiled class files.

    • The java utility also automatically searches for Java class files in (an appropriate sub-directory of) the directory you have chosen for storage of these files.

      You will generally still run java from within the directory containing your source files (unless you give it a path to the file as an argument). However, this allows you to keep source files in one place and class files in another.

    You might find that online documentation for the javac and java utilities are helpful as you set up your environment. You will probably need to edit a file in your home directory whose name is something like .cshrc or .profile as part of this.

  5. Students often wish to work on assignments using their computers at home. Some work can be done by logging onto your computer science account from home. However, you might also wish to install Java on your home system.

    • Windows users should follow the instructions in the “Hello World!” Tutorial for Microsoft Windows. You will probably need to figure out where Java has been installed, and you will probably wish to change your search path to include both the javac and java utilities. It is possible to do this but, unfortunately, the process seems to be a little different for each version of the Windows operating system that is currently available: You may need to search for some system-specific information online in order to complete this step.

      On the other hand, you might be able to use Java at home without worrying about your search path by installing the Netbeans IDE, as discussed in the next step.

    • Macintosh users should (for the most part) be able to proceed by opening the terminal utility and then proceeding as if you were using a UNIX or Linux system — Java is already installed. You should be able to complete the “Hello World!” tutorial for Solaris OS and Linux (skipping the steps for installation of the Java Development Kit). Additional information about the use of Java on a Macintosh is also available.

    • Students who use UNIX or Linux at home will probably need to begin by installing the Java Development Kit (JDK). Unfortunately the process for doing this is quite different for the various versions of Linux that are currently available: You should probably search online (including both the name of the version of Linux you are using as well as “install jdk” as search keys).

      Once this step has been completed you should be able to complete the “Hello World!” tutorial for Solaris OS and Linux

  6. You may also wish to use an “integrated development environment (IDE).” Both Netbeans and Eclipse are popular choices.

    • Netbeans is reasonably easy to install on a Windows system or a Macintosh. Some examples in the textbook (including one involving the use of a debugger in Chapter 2) are given for thie IDE.

    • It is possible, but a bit more challenging, to install Eclipse on a Windows machine (you should check for additional online information about this) or a Macintosh.

      To start off, you will need software that can be used to extract files from a “zip” file in order to install this on either a Windows machine or a Macintosh. Winzip is a popular choice for Windows users; Macintosh users who are familiar with the Unix gunzip and tar utilities should find that these are available on their Macs too. Alternatively, a utility like Stuffit Expander can be used to decompress the file that you download from the Eclipse web site.

      Note that Eclipse is installed on the machines in the lab that CPSC 331 students generally use at school.

    The process required to install either of the above IDEs on a Linux machine depends on the version of Linux that is being used; you will need to search for information online in order to figure out how to do this correctly.

    Students wishing to use Netbeans at home should work through the “Hello World! tutorial for the Netbeans IDE. Students wishing to use Eclipse should find that a similar tutorial is available within Eclipse the first time they run the IDE.

    Note, however, that it must be possible to compile the code you submit for assignments on these machines from the command line using the javac command: Teaching assistants will not be testing your code using IDEs.

  7. This next task should be carried out both at school and at home: Find out what version of Java you are using. You can do this at school (or at home, if you are using the MacOS or a Linux operating system) by reading the man page for java and then executing this command with the appropriate additional command line argument.

    If the version of Java that is identified begins with 1.6 then all is well — this agrees with the version of Java that is (supposed to be) available in the undergraduate computer science labs for the Fall 2010 term. If the version of Java begins with something else then you should let the instructor know about this as soon as you can. That said, if the version number does not begin with 1.6 then the version of Java you are using is probably out of date, and it should likely be upgraded before you continue with this course.

  8. Finally, you are encouraged to help us to improve this information! Please do send polite and constructive feedback about this page. Suggestions of better way to explain things or alternative online references would be appreciated! So would things that you don’t think worked as well as they should have.

Last updated: