Lab 1: Getting started

Sun Microsystems has done us a huge favor by writing a really excellent set of tutorials on the Java language. Best of all, they're freely available online. You can get to the start of this set of "trails," as they are called, by going to, where you'll find an up-to-date web version of a book they publish with the same name. (You're welcome to buy the book, but it's not necessary, and we will stray from the topics covered in it over the course of the term.)

Here's what you need to do this week:

  1. Read the java style guide.

    To learn how we want you to format your java code, take a quick look at the java style guide. Just skim it; don't worry about reading every detail. Most importantly, learn how to use the java style checker program. We will assume that you run the java style checker on all of your code before submitting it. If you don't, and your code contains lots of style violations, we'll make you redo it.

  2. Create your first application.

    Go to the 'Your First Cup of Java' trail and ignore section 1. This is because on the CS cluster a fresh copy of Java 1.4.2 is already installed and ready for your use. (You're welcome to go through the process to install the Java SDK on your own machine, though, if you prefer.)

    Instead, log in to CS and verify that the Java interpreter works by typing

    > java -version

    Check that java 1.4.2 (or a later version) is installed, and then ignore the instructions in the tutorial to use the text editor pico. We recommend you use emacs instead. (Emacs is nice because it "understands" Java code -- it will help you indent it correctly and it will help you match up parentheses and the like.)

    Skip on to part 2 of the trail. Use emacs to create the source file like so:

    > emacs

    Notice how emacs indicates it is in Java mode at the bottom of the screen.

    Key in the "Hello, World!" application by hand, compile it as directed, and make sure it runs to your satisfaction. Skip the remainder of the trail. (We'll bother with applets later.)

  3. Modify HelloWorldApp.

    Note that all the modifications should be in the file named

  4. Read about objects.

    In the "Learning the Java Language" trail, there's a subsection entitled "Object-Oriented Programming Concepts." Read the first three pages of this -- "What is an Object?", "What is a Message?", and "What is a Class?"

    We'll talk about objects and classes in more detail next week.

  5. Learn how to browse the Java Application Programming Interface.

    All of the objects defined in the Java specification are nicely documented as a part of the Java API. This kind of web-based documentation is called a Javadoc. Go to it and browse around randomly just for fun. You can download a copy of the whole thing to your own computer for quicker browsing if you like. (Don't download it to your CS account -- you'll use up your disk quota!)

After you've had your fun, skip to the last part of the "Object-Oriented Programming Concepts" subsection of the "Learning the Java Language" section of the web tutorial. It's called "Questions and Exercises". Answer questions #1 and #2. (Hint: use the javadocs.) Please type the answers into a file called answers.txt which you can put in your directory with your code. DON'T look up the answers linked to the page (anyway, the answer given to question #2 is not even adequate, in my opinion).