Things That Are Useful to Keep in Mind.
from Martin Smith

Part I

This is my little fact/help sheet for those of you who are somewhat confused with what your applets are doing. If you're a little confused, read through this. Don't take anything as the pure and holy truth because I am subject to error as much as (if not more than) anyone else; but this will give you a better understanding of what's going on and what to keep in mind. So, read through this, and it'll help you out.



Office Hours
Compiling
Viewing
Methods
Errors
Stages
Indenting



Office Hours are nice.

For those of you having trouble understanding what the computer is doing, while there's no guarantee that we can explain it to you, you will usually find information in Office Hours. To find when office hours are, go to the course web page and check the course calander. They may be moved to a separate page in the future but right now they are on the top right of the course calendar. They are usually going to be held near the elevators on Wean on the fourth floor by the restrooms. If not there, try the seventh or eighth floor. There should be a sign or something letting you know if we've moved. For some of you, two classes a week is not enough to understand what's going on. So......Office Hours.

Back to Top

Compiling with "javac"

Know it. Remember it. Use it.
"javac.exe" is the program we use to compile our .java programs into .class files. To use this program, on a Windows machine, you type in the Dos Command Prompt "javac Lab##.java" (Note that you don't have to type the .exe). This will take the first part of the filename (note the capital first letter) and make a file called "Lab##.class" (again, capital first letter). The .java file is a text file (ASCII) you typed it on the keyboard. The .class file is generated by javac.exe and it is a Binary file. It is bytecode thatwill be interpreted by appletviewer, Internet Explorer and Netscape to name a few.

Back to Top

Viewing with "appletviewer"

Know it. Remember it. Use it.

"appletviewer.exe" is one of the programs thatwe use to view our applets. I highly recommend it as opposed to Netscape or Internet Explorer because it will give you more detailed errors if there is something wrong with your applet. Sometimes they will compile but not run. This is because the syntax or how things are phrased may be right but there may be something more conceptually wrong with the program. You use it by typing in the Dos Command Prompt "appletviewer Lab3.html" where the Lab3.html file uses the Lab3.class file using the applet tag (see below). The HTML file does not need to be named Lab3.html; it can be myapplet.html or whatever. Just make sure you link to it using the same cases so Andrew can find it.

Back to Top

Some things are case sensitive

What is case sensitive? Case sensitive is simply that ‘A’is not the same as ‘a’. We see the alphabet (a-z) as being 26 letters but acomputer or program that’s case sensitive, sees the alphabet as being 52 letters (a-z and A-Z).

What things are case sensitive? Well, the declaration in your applet, which looks like"public class Lab3 extends Applet" should match thefilename of the .java file. So, the .javafile should be saved as Lab3.java. The program javac.exe will interpret that and make a Lab3.classfile. Which will be opened by an HTML file using <appletcode="Lab3.class" width=300 height=19></applet>. Notice that they all have capitalized first letters. This is important.

Some other things that are case sensitive are Andrew and Java. When you upload your .html file and .java file to your webpage, check to make sure that they have the same case sensitive name as they are referredto. With Java, when you type a method, make sure you are typing the same cases becauseJava can find "setColor" in the graphics class butit can’t find "SetColor" or " setcolor" in there.

Back to Top

Methods

What is a method? My definition: A method is something you can call (tell the program to do or run) that can do something. Simple, huh? A method can take in information. It can modify it or use it to do something, and it can return information. When defining amethod, we write the method's header which describes what the method uses and returns. Such as "void fillRect(int x, int y, int w, int h)" this method takes in four integers to make a rectangle and returns no values. The first two integers are to define the top left corner of the rectangle by going right x number of pixels, then going down y number of pixels. The second two represent the width and height of the rectangle from the point (x ,y). So, the computer will draw a rectangle from (x,y)going w pixels over and h pixels down. To use a method, you type the object that it is of. For functions that are known to the Applet class, that would not be necessary, but others are known to the other classes,like the Graphics class, so you will have to type the name of that class and a period to access the the classes methods. Then you type the method name and a parenthesis with it's arguments (the values it takes in) with a closing parenthesis.

Example:               g.fillRect(23, 43, 290, 355);

Or                          myGraphicsObject.fillRect(value, 34, width, height);

where value, width and height are variables with integers stored in them and the nameof the graphics object is declared. See Lab 2 that you copied from page 25.

paint is a method.

public void paint(Graphics nameOfObject)
{
}

It’s declared public (things outside the class can call it) and it returns void (nothing) and in this case it takes in a variable or object of type Graphics. We usually call the object g, but in this case the name of the object as it exists inside the braces will be nameOfObject. What’s within the braces {} is the method’s body. This is what the paint function does.

Back to Top

Errors are good

No, I’m not insane; errors are good. You learn from making mistakes and going back and fixing them. Also, you get a nice rewarding feeling when you get them to go away. Before asking for help, take a look at the error message, go to that line and look for something out of place. Check other sample codes in the book and try to determine what is wrong. You will learn much more and much better from this than we if simply tell you what's wrong.

Back to Top

Write programs in stages

You can either write the program all at once. Then try and compile it and possibly get fifty errors, all interrelated and try to deal with it then. Or do it in steps and deal with the problems as they come. (The second one is nicer) Start by taking something that works or a hollow applet. Like the one on page 32 of the book. Make sure that it compiles. Then add a couple things here and there. Compile. Take a look at it. Continue with this process until you have a finished product.

Back to Top

Indenting and being neat

Indentation is a mildly important thing to do. It helps you read your code better andthis is extremely use full when trying to track down and error. Think of it as a termpaper. Say you wrote this twenty page paper on Anthropomorphic behaviors of Holothurians in the South Pacific without ever hitting the enter key, tab key or the space key. Then remembered you misspelled Mollusk as Mollusc and had to go back by handand find Mullusc? Yeah. Or what about asking someone else to find where you misspelled Mollusk? So indent. It’s nice sometimes.

How to indent.

I indent by moving in a set amount each time I type a { or something that may be contained in a {and go back that amount when I get to the other }. Otherwise, I just try to be neat and such. Add comments about what your doing so you and others canread your code and understand what it’s doing. Sometimes separate blocks ofstatements that are related by a line. And so forth. While I don’t think that Jim is grading neatness, the little bit of extra time will help you out.

Back to Top

To Be Continued

(Maybe)


[ Home | Calendar | Section A | Section B | Assignments & Exams | Staff | E-mail Webmaster]