6.75s - Introduction to Interactive Programming

The Manual of Dextrous Compilation



The purpose of this document is to familiarize the user with our lab setup. We will be using a cluster of Windows NT workstations, and writing Java applications with the assistance of Microsoft Visual J++, a professional software product. This and many other supplementary products are not completely necessary to write Java programs*, but their use greatly enhances speed, productivity and the learning process.

This handout is designed for users who may have had only minimal exposure to Windows operating systems and integrated development environments; but will also be of use to users familiar with Windows NT and Visual J++, who need to know the particulars of our setup.

*Indeed, all one really needs is the JDK 1.1 from Javasoft and an ascii text editor such as emacs (Unix) or edit (MSDOS). However, as your projects increase in complexity, so will your need for the appropriate tools.


Table of Contents


1. Prologue

A learned software consultant was once approached by a bedraggled pilgrim who had not showered in many days.

"O wise one, I am troubled. I must continually master new languages, operating systems, and applications in order to remain competitive, and I must remember so many commands and keystrokes and directories where everything is supposed to be kept, that I cannot write a line of code without devoting months of effort and frustration. Yet you have mastered all these with ease, and even find spare time to go to the beach and see movies. How may I discover this programmer-nature, that I as well may become sought after in business and academia and still have a social life?"

The consultant responded by lifting his index finger.

The pilgrim went away, perplexed.

Several weeks later, the pilgrim returned with bloodshot eyes, wearing black wrist guards.

The consultant responded by depressing his index finger.

The pilgrim went away, more confused than ever.

Several months later the pilgrim returned, this time pale and near death.

"O wise one, I believe that you do not know the answer. For your depressed finger suggests a bowed head, so I have pursued the ascetic life by fasting, meditating, and practising yoga. I am much more spiritually complete, but I still find it overwhelming to sit down and write a line of code. Clarity of thought and purity of the soul is not the answer; you have misled me. I believe I know what this programmer-nature is: it is merely the ability to speed-read computer manuals together with a photographic memory. It is the only explanation for your success."

The consultant was silent for a moment, and then responded by lifting, and then depressing, his index finger.

At this the pilgrim was enlightened.

A note from the course assistants: Help was only a mouse-click away. The Integrated Development Environment (IDE), though still not a cure-all, can alleviate many of the pilgrim's complaints and make programming a more enjoyable experience.

An IDE does this by integrating all the necessary functions into a single, easy-to-use graphical user interface. We will be using Visual J++ 6.0, an IDE developed by Microsoft, which supports Java 1.1. Many other commerical IDEs are available, sporting numerous features and gadgets to ease the programmer's way. At the end of this handout we will describe some alternative IDEs and some issues you should consider in selecting an IDE for your own use.


2. The Lab Environment

2.1 Logging In

When you first come in to lab, be sure that the machine you sit down at is a Windows NT workstation, and not one of the Hewlett-PackardApollo's, which are for a different class. (The NT's look cooler.) If you see a screensaver, you can jiggle the mouse or hit a key to get the machine's attention. Be sure to avoid any machines labeled NOT WORKING.

You will probably see the message "Press Ctrl-Alt-Delete to log on." This means to simultaneously hold down the CTRL, ALT, and DEL keys. If you are used to other Windows operating systems, you might expect this to reset the machine, but in Windows NT, this will start the login sequence.

You will be prompted for a username and password; ask a course assistant where to find them.

To get a Command Prompt (a command line interface that resembles MS-DOS), you will have to use the Start menu. Find the button in the lower left corner of the screen labeled "Start". Single-click on it. A menu will appear with several choices. Move the mouse pointer over "Programs". A moment later, another menu will appear. Move the mouse pointer over "Command Prompt". A single-click will start up the program. Later in this document and in other handouts, we will use the following convention to describe the process of wading through menus:

For the command prompt, the shorthand would be:

Sound reasonable? Now we'll try some window exercises.

2.2 Working with NT

If you have not called up the Command Prompt, do so now. Look at the gray bar at the bottom of the screen (called the Taskbar). Notice how a button has been added to the Taskbar that corresponds to the Command Prompt. The button will be depressed for every window that is open and raised for every window that is minimized.

To get a feel for this, minimize the Command Prompt by clicking on the small gray button labeled with an underbar ("_") in the upper right corner of the Command Prompt window. Notice how it shrivels up, and the button on the Taskbar pops out. Click on this button that just popped out. The window should re-inflate.

Windows can also be maximized. Just click on the gray button in the upper right corner that contains a black square. The window should expand to its maximum size, and the button should look different now (it will contain multiple black squares). Click on this same button and the window will return to normal.

Finally, the window can be closed. Click on the gray button containing a black X. The Command Prompt, and its corresponding button on the Taskbar, will disappear forever. Now start up another Command Prompt.

You can browse directories in two basic ways: either use the Command Prompt, or use Windows NT Explorer. In the Command Prompt, you can list a directory by typing

on the command line, and hitting return. (You always have to hit return after a command.) You can move into a directory by typing

where <name-of-directory> is the directory you wish to change into. This should appear to be very similar to MS-DOS. Other pertinent commands include del (delete), ren (rename), and copy, as well as type which will blast the text across the screen. If the file is long, you can display a screen at a time by entering

where <filename> is the file you're interested in, and the funny symbol (" | ") is the vertical bar (also called "pipe"). more is a simple program: hit any key to advance to the next screen of information. You can also have the output of other commands "pipe" their information to more, such as

Piping information between programs is a simple and powerful way to get things done. If you've been using UNIX for a while, you probably found several uses of this concept. Later in the course, you will be writing programs that pipe information to each other, under a slightly different name: streams.

If you'd prefer to exercise your mouse hand instead, you can use a graphical user interface by selecting Start > Programs > Windows NT Explorer. You will see two panels. On the left is the directory structure. On the right is a listing of all the directories and files contained in the current directory. In either panel, you can select a directory or file by single-clicking on it, and switch into a directory (or view a text file, or run an application) by double-clicking on it.

Moving a file or directory is just a matter of drag-and-drop. You can also cut, paste, copy, rename or delete files or directories using the File and Edit tabs. For more advanced features and information about Windows NT, select Start > Help > How To...

2.3 Finding Your Homedir

Please help us out by setting up your own homedir. This should be easy; simply open up Windows NT Explorer and create a directory with your typical username in the U:\675s directory. Now go to S:\projects and copy the entire directory structure into your new homedir. You will find these two drives handy: the U: drive contains all the user homedirs for the class, and the S: drive is where the problem set code will reside.

2.4 Logging Out

When it comes time to log out, be very careful. Windows NT is very fussy about this. The proper way is to select Start > Shut Down. When given the choice to Close All Programs and Log On As Another User, click on Yes. This is the only valid choice for our laboratory cluster.

The screen should clear, and the login screen should pop up for the next user.


3. The Development Environment

3.1 Exploring Visual J++

To start up the application, you can click on the Windows NT Start button (lower left corner of the screen) to select Start > Programs > Visual J++ 6.0 > Visual J++ 6.0.

After the startup sequence, you should see the central code editing window, with lots of subpanels and brightly colored buttons. If you like guessing games, you can try to figure out what the button icons mean. Otherwise, you may rest the mouse pointer over a button for several seconds. A "tooltip" will pop up describing what the button does. All of these functions can also be found somewhere in the Visual J++ menu system.

There is another window, which you will be using often. This is the Project Explorer window. You can call it up by selecting View > Project Explorer. This displays all of the files which you may currently work on, organized into ``solutions'' and ``projects.'' Each of you will have one solution which will contain several projects over the course of this class. It should be automatically loaded up by Visual J++ when you start it up.

Also of use is the Class Outline. You can call it up by selecting View > Other Windows > Document Outline. This breaks down Java classes into their component parts and, if appropriate, displays the Java documentation for that part of the code. Browse around in the provided code in this window and you will see how this works.

Finally, the Task List will be of great use when you begin writing code. If it is not onscreen already, call it up using View > Other Windows > Task List. As you write Java code, Visual J++ will compile your code on the fly and indicate any errors in the task list. This should keep you aware of glaring bugs and encourages incremental design techniques.

All these windows are dockable. This means that you can drag the window around the screen, and it will attempt to ``dock'' with the nearest window, giving you the freedom to set up the layout as you like. Once it is docked, a window can be undocked by double clicking on the dark blue titlebar. (Similarly, to re-dock.) Some windows, like the Document Outline and Project Explorer, like to combine into one window with several tabs. These can be undocked by double clicking on their tab instead.

Several preset window layouts are available. There is a menu on the far right end of the toolbar. Feel free to use these as is, or use them to create a layout of your own.

3.4 The Code Editing Window

Go ahead and add a class to the Calculator project. You can do this by selecting Calculator in the Project Explorer, right clicking on it, and selecting Set As Startup Project. Now try Project > Add Class, and select Class > Class from the New tab. You may give this class any name you like.

Notice how different bits of code are colored differently. This is meant to aid the programmer in visualizing the syntax of Java statements.

The typical operations can be performed in the editing panel: cutting, pasting, searching, replacing. (See the Edit tab.)


4. Time to Roll up Your Sleeves

4.1 Building and Compiling

Now, you're ready to do your first compilation. Select Build > Build. This will take a few moments to compile your java file. It should compile properly. (If it doesn't, please ask a course assistant for help!)

Now, you want to look at your exciting new application. Select Debug > Run. This will create a new window, theoretically, with your cool new program in them.

4.2 The Console

Whenever your Java program prints information using System.out.println(), that information is captured by the console. If you have used the JDK (Java Development Kit), which contains command-line tools for compiling (javac) and running (java), then the console is simply the window you type your commands into. (This applies to both our NT cluster and Athena, and anywhere else you use the JDK.)

In Visual J++, the information your programs spits out is captured by a special application, JVIEW. When you run your program using Debug > Start, the JVIEW window will pop up and deal with any console input or output. Note that you must enable this application explicitly by going to Project > Options > Launch. Click on Custom and change the Program field to read JVIEW.EXE instead of WJVIEW.EXE. Also, note the Arguments field. The last argument should be the name of your main class. In the case of Calculator, this will be Calculator.Main. After the main class is where you will append your command-line arguments that will be read by the main() method of the main class.

4.3 Fixing Errors

You should to comment out a portion of the code, in order to see what kinds of compiling errors you can get. Commenting means to mark off an area in your code file that will be deliberately ignored by the compiler. In java, you use the following scheme to comment your code: (here, the words "This is a comment." will be ignored by the compiler: (note that in the second case, only the remaining text on the same line is ignored)

As you type (or comment out) code in the editing window, you will notice that at times you have valid java code and at other times you do not. These errors should be appearing in the Task List. Read the error messages you get; try to see if they make any sense. Note: when the java compiler can not complete its work, the class is the same one as that last time it successfully compiled. What that means is that if you try to run your program again, it'll run the last version.

4.4 Printing Out Code

Printing is a piece of cake. To print your code, be sure the window containing your code has a blinking cursor (click in the window if it does not), and then select File > Print.

You may get a message about an uninstalled printer. If so, please ask a course assitant for help.

To print help documentation (see below), be sure the page you want appears in the right hand panel, and select File > Print in the Visual J++ Documentation window. It will prompt you as to how much you want to print; please select Print the Current Page.

4.5 Getting Help

If you have a burning reference-type question that can be answered by the Java 1.1 API (Application Programming Interface) or the Java Language Specification, these can be found online. Select Help > Contents. A window should appear named ``Visual J++ Documentation.'' Notice that there are four tabs: Contents (which should be selected), Index, Search, and Favorites. In the panel on the left, you will see a directory tree with a single entry. You can navigate this tree by double-clicking on the book icon(s). Reference material can be found by selecting Visual J++ Technology Preview 1 > Reference. In the panel to the right, you should see a hypertext document with navigable links. You will probably want to go to Java API most of the time. It often has details that the book Java in a Nutshell did not have room to print. Another handy link is the Java Language Specification. This is the definitive text on the Java language and a rather hefty read.

More general help is available. Feel free to navigate the documentation (the tree structure in the left hand panel should help). Since there is a lot of material here, you can either expand a directory by clicking on the plus symbol, or contract a directory by clicking on the minus symbol.

There are many features to explore, and fortunately, Microsoft has online documentation that should help you acclimate. The following sections are helpful to the beginner:

Beware any documentation referring to the Windows Foundation Classes (WFC), J/Direct, COM, ActiveX, the SDK, or any other non-portable Microsoft technology. We will not be using these technologies in this course. The same goes for HTML forms, applets, or database components. This class will focus exclusively on standalone console applications, written in 100% pure Java.

There is also a help index and search engine of the usual (only vaguely helpful) variety.

Of course, whenever you're in lab, there should be course assistants there to help you. If you need to report bugs, or simply want advice on how to proceed, feel free to talk to them.

The course assistants are there to help; ask questions early and often! :o)


5. Epilogue

Criteria you may want to use in selecting an IDE:

  1. Product version
  2. JDK Version
  3. Platform
  4. Price... sometimes free downloads of beta technology
  5. 100% Pure Java
  6. Enterprise Needs

Product Version

Beware of any piece of software with alpha, beta, pre-release, preview, or any version number less than one. Also keep in mind that just because the version number of the product is 1.1, you cannot assume that it supports the Java 1.1.

JDK Version

1.0 - Popular support in commercial browsers.

1.1 - Some changes to the language spec. Stable. Popular in enterprise computing.

1.2 - In beta at the time of this writing. Many new advanced features. Little or no change to the language spec.

Platform

Identify all the platforms you need this product to run on. You may have to dig deep into the technical specifications for their product to be absolutely sure that your configuration is supported.

Price

IDEs that support enterprise computing are at one extreme end of the spectrum, and homebrew solutions are at the other end. Sometimes trial downloads of the product are helpful.

100% Pure Java

Some things you need to know about:

  1. Not all Java products produce 100% Pure Java bytecode that is portable to any Java Virtual Machine.
  2. Microsoft's Visual J++ is one of these products.
  3. A Java product can produce 100% Pure Java bytecode but just hasn't been certified by Sun.

Enterprise Needs

If you need an IDE that can handle multiple computer languages, edit JavaBeans, includes database connectivity...


This course is a part of Lynn Andrea Stein's Rethinking CS101 project at the MIT AI Lab and the Department of Electrical Engineering and Computer Science at the Massachusetts Institute of Technology.

Questions or comments:
<cs101-webmaster@ai.mit.edu>

Last modified: Thu Jul 10 13:01:20 1997