Java programs are stored in plain-text files and then compiled into bytecode, which is one step removed from executable code. Each platform (each hardware and operating system combination) has a Java Virtual Machine, specific to that platform, whose job is to interpret and execute the bytecode. By writing Java code for a virtual machine, rather than a specific machine, it is hoped that programmers can “write once, run everywhere.”
Programs can be written in any plain-text editor, like Note Tab Light. Sun Microsystems provides free of charge a Java Software Development Kit (normally called the “SDK”) which comprises a compiler (javac
), an application launcher (java
), and an API documentation generator(javadoc
). (Also available is an applet viewer, which will not be discussed here.) The compiler is used to convert plain-text files (with the extension .java
) to bytecode files (with the extension .class
). The bytecode files can then be interpreted and executed by the application launcher. The compiler and application launcher are command-line tools, and provide the minimum functionality necessary for code development.
In this course, we will use instead the DrJava integrated development environment (IDE). The IDE comprises a text editor, compiler, debugger, and a runtime environment. The integration of these tools makes easier the iterative program-development cycle of code, compile, run, and debug.
On your workstation (and later, on your home computer), create a directory where all of your programs will be kept. Here are some examples:
H:\code
H:\school work\2007-2008\cs\java code
H:\My Documents\Computer Science\program code
For obvious reasons, we will refer to this directory as your code directory.
Your programs will be organized in packages, each of which contains one or more Java source-code files. Some of these programs will be used again and again, so you'll want to store them in a special package library.
By convention, this library is stored in a subdirectory whose pathname is the reverse of your e-mail address. (Look at an example.)
On your workstation (and later, on your home computer), create the directories need to store your package library.
Launch DrJava and choose Edit > Preferences…. (What does that mean?)
In the dialogue box which appears, click the Add button. (Self-test: how could you predict that a dialogue box would appear?)
In the second dialogue box which appears, navigate to the directory which contains the directory you’ve chosen to hold your package library, select the package-library directory, and click the Select button. For example, Victoria Windsor would navigate to the “tel” directory inside the “tdsb” directory inside the “on” directory inside the “ca” directory, and select the “victoria.windsor” directory. (If you’re confused, then look at an example.)
In the first dialogue box, the fully-qualified pathname of your package library should appear in the field labelled “Extra Classpath.”
It’s a bit of a cliché, but by tradition the first program written in a new language is the “Hello, world!” program. So, that’s going to be our first program, too!
Type the following code into the definitions pane of DrJava. (You can use DrJava’s help feature to discover which is the definitions pane.) Don’t be surprised if the code doesn’t make sense to you, at first. It will, soon!
Please note that Java is case sensitive.
public class HelloWorld
{
public static void main(String[] arguments)
{
System.out.println("Hello, world!");
} // end of method main
} // end of class HelloWorld
Save the program in a file called “HelloWorld”. (DrJava will automatically append the necessary “.java” extension.)
Do you remember what the Introduction said about source files, byte code, and execuatable code? In order for your computer to run your program, it needs be compiled, and then the resulting byte code needs to be handed to the Java Virtual Machine for execution.
As luck would have it, DrJava makes these steps easy for you. Just find the menu choices for compilation and execution, and then look for the results of the program’s execution in the interactions pane.
If you’re ambitious, at home you could try running the same program at the command prompt:
HelloWorld.java
file and a HelloWorld.class
file. The former contains the source code; the latter contains the byte code.
java HelloWorld
. (Caution: For Java filenames, case is significant!)
Find the line in the code which controls the message displayed in the interactions pane, and modify it so that it displays some other message. If you’d like, feel free to add some additional lines.
By the end of this assignment, you should be able to demonstrate the operation of the DrJava IDE (and—if you’re really keen—the Java SDK), and be able to describe both the types of files required to create a Java application, and describe the way those files are related.
Please create a website which proves you have met the expectations listed above. Include a minimum of two annotated screenshots, along with text and other features. In class, you’ll be shown where to create this website.
Use the links at the bottom of this page to help you validate your code. The HTML specification and the CSS specification will also be helpful. If you need help with screenshots, please don't hesitate to ask.
As the course progresses, you will build an HTML-based glossary of computer- and information-science terms. You will be able to provide some of the glossary definitions from your existing knowledge. For other terms, you will have to research a definition.
For every term, you must provide a source, and at least 50% of your terms must be linked to authoritative definitions or other useful resources. Examples of useful resources include detailed illustrations, video clips, reviews, news articles, and thoughtful opinions. (If you’re uncertain as to the utility of a resource, please ask.)
Of the terms which are linked, aim to have no more than half linked to the same resource. For example, no more than half of the terms linked to the Free Online Dictionary of Computing (FOLDOC), or to How Stuff Works.
To help you compile all of the necessary terms, they will be identified within the class site as links with this style. In addition, a master list of terms is also provided.
Of course, your HTML code will be valid. The links at the bottom of this page will help you validate your code. The HTML specification and the CSS specification will also be helpful. If you think it will help, you may use the code of the master list of terms as the basis for your glossary.
Chapter 1 of: Horstmann, Kay. Big Java. 2002: John Wiley & Sons, Inc. ISBN 0-471-40248-6.
CSS specification
Free Online Dictionary of Computing (FOLDOC)
HTML specification
How Stuff Works
Webopedia
Wikipedia