Java facts
- A Java program is a collection of classes. Some classes are written
for you, for example the String class. Others
you have to write.
- To make life simple, organize your work this way:
- Keep all your work on a floppy, Zip disk, or USB drive. Label the medium with your name,
and phone number. Bring it to class each day and remember to take it with you when you
leave the class.
- Keep each program that you write as a separate Bluej project. This
means that your floppy will contain a folder for each of the many programs
that you write. For organizational purposes, a Bluej project corresponds
to a folder on the floppy.
-
- A class definition contains the properties (instance and class data)
and the behavior (instance and class methods), that objects of that class
possess.
- A class definition is contained in a file. You may use an editor program,
like EDIT, to create (type in) a class definiton. If you are using an Integrated Development Environment like Bluej, you will be using the
editor available in Bluej.
- Typically, each class is defined in a separate file. The file MUST
have an extension of .java, no exceptions. Also, the class name will typically
be identical to the file name. That is, the class named Sample will be defined
in a file named Sample.java. Begin class names with an uppercase letter.
- From the command line, you compile a Java class definition using a
command of the form javac Sample.java. If you are using an Integrated
Development Environment (IDE, like Bluej), you will compile a class definition
by clicking on an appropriate icon. The IDE then invokes the compiler and
compiles the source file.
- Syntax errors will be detected by the compiler at this time. Syntax
errors include missing commas, semi-colons, braces ({ }), or other incorrect
usage of the Java programming language. Java is case sensitive. Uppercase
is uppercase, and lowercase is lowercase. For instance, SketchPad is NOT THE
SAME AS Sketchpad!
- If the compiler produces error messages, READ THEM CAREFULLY till
you understand them. I repeat, READ THE ERROR MESSAGES till you understand them.
Then, edit the file and fix the mistakes. Save the file
and recompile.
- A successful compilation of Sample.java produces the file Sample.class.
To run the program from the command line, use the command java Sample. If you are using
an IDE like Bluej, the mechanism for running the program depends on the IDE. Regardless,
the IDE invokes the Java Runtime Environment and causes it to load and execute
the class file.