"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.
A week later, the pilgrim returned with bloodshot eyes, wearing black wrist guards.
The pilgrim went away, more confused than ever.
The consultant was not surprised to find the pilgrim returning a full two weeks after that, 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 persued 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 Java WorkShop 2.0, an IDE developed by Sun, which is one of the few that currently support Java 1.1 on multiple platforms. Many other commerical IDEs are available, sporting numerous features and gadgets to ease the programmer's way. A partial listing can be found at the end of this handout.
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. The username is the same as the one you supplied when you filled out the sign-up sheet. The password will be your MIT ID number. NT should prompt you to change your password to something more secure. If you get no such prompt, you can change it yourself. Simply hit Ctrl-Alt-Del again. A menu will pop up. Select Change Password. Fill out the information and click OK. You can exit the Windows NT Security menu by hitting Cancel.
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:
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. It 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
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...
Actually, all of the choices in this menu are valid. For example, the one and only way to power down the machine is to select Shut Down the Computer. Never power down the machine without doing this first.
After the startup sequence, you should see two windows: a Startup window, and a code editing window with lots of brightly colored buttons. If you like guessing games, you can try to figure out what the button icons mean. Otherwise, now is a good time to select Preferences > Show Labels on Toolbar to avoid confusion.
If you do not see the Startup window, it has been disabled. It can be called up by selecting Windows > Startup from the Java WorkShop menu. Most of the functions in this window are duplicated elsewhere, except for a tutorial which you may wish to browse through later. You can dispose of this window if you like.
There is a third window, which you will be using often. This is the Project Manager window. You can call it up by selecting Project > Show Project Manager (or alternately, Window > Project Manager). This displays all of the files which you may currently work on, organized into "projects" and "portfolios". Each of you will have one portfolio which will contain many projects over the course of this class. It is automatically loaded up by Java WorkShop when you start it up.
Before you can run our version of the xeyes code you will need one piece of code:
Notice how different bits of code are colored differently. This is meant to aid the programmer in visualizing the syntax of Java statements. You'll experiment with Java expressions and statements in the Spirograph Problem Set.
The typical operations can be performed in the editing panel: cutting, pasting, searching, replacing. (See the Edit tab.) You can also Go To a certain line number by selecting Edit > Go To Line... and entering a number. (The current line and column numbers are displayed on the bar at the bottom of the window.) For those of you who are used to spawning multiple windows for editing, note that Java WorkShop is lazy and would rather replace the contents of the current window (forcing you to save your work) than spawn a new window. You can get around this by selecting File > New Editor Window or File > Clone Editor Window as needs arise.
The thin white panel at the bottom is where special error messages (or search results) will appear.
At this point, if you were to list the contents of your directory (via the Windows NT Command Prompt), it would now contain a JavaEyes.class file containing the compiled code. You can try to look at it, but it's not readable in English.
Now, you want to look at your exciting new application. Select Project > Run. This will create a new window, theoretically, with your cool new JavaEyes in them. Play around with them for a minute, then continue. (If nothing shows up in the new window, try resizing the window by pulling out the corners.)
Now we suggest that you make some modifications to the code. The purpose of this part of the project is just to get you comfortable using the tools, not to experiment with Java expressions and statements. That is what the Spirograph Problem Set is for.
Raise the Code Editing Window and look for the line that says
Try compiling the code again now. It should still compile. (Again, if it doesn't, please see an LA!) Check out your new eyes by (first) compiling using Build > Compile File and (then) the Project > Run command you used earlier. (Cool, huh?)
Side Note: if you're curious what the other flavors of building and compiling are:
In Java Workshop, the information your programs spits out is captured by a special window. When you run your program using Project > Run, the Console Window will pop up if either your program tries to print something out, or a runtime error occurs. (Runtime errors are different than compiler errors; a compiler can't catch them!) You can explicitly pop it up by selecting Windows > Java Console.
Notice that it has a Clear button. This means that a continuous log of your program's activities will be kept for the entire Java Workshop session, unless you explicitly hit the Clear button. Sometimes it is better to let the log run wild, at other times you may wish to clean up after every run.
// This is also a comment.
/* This
* is
* also
* a comment.
*/
Insert two slash characters (//) the above characters (first line) to comment out the line. (You should not delete the line; you'll need it later.) Save the file again, compile it again, and see what happens.
It should not compile this time. Read the error messages you get. Try to see if they make any sense. Note: when the java compiler can not complete its work, as in this case, the JavaEyes.class is the same one as that last time it successfully compiled. What that means is that if you try to run the JavaEyes program again, it'll run the last version (i.e. the one before you commented out that crucial line).
If you forget to save your work before compiling, Java WorkShop will save it for you. However, if you forget to (save and) compile, Java WorkShop won't lift a finger, and the old code will be run instead. (Some IDEs are smarter.)
More general help is available. There are many features to explore, and fortunately, Sun has written a decent tutorial that should help you acclimate. (Select Window > Startup and click on Start the Java WorkShop Tutorial.) The following sections are helpful to the beginner:
The other sections cover handy features, which you may wish to use as you become more proficient. They will not be necessary for the course but may be useful in your other pursuits.
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)
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.