Jump to page content Jump to navigation

College Board

AP Central

AP Course Audit Web Site
Click for more information about College Board Online Events


Siemens Awards for Advanced Placement
Print Page
Home > Java as a Pre-AP Strategy in Computer Science, Part II

Java as a Pre-AP Strategy in Computer Science, Part II

by James Aldridge, Ph.D.
Fort Worth Country Day School
Fort Worth, Texas

This is Part II in a series of articles designed to take a computer science teacher in the Pre-AP years through the more difficult and confusing first components of teaching computer science in Java. In Part II we discuss how to get started with the course logistics: how we prepare the machines for the course, where to find information on IDEs and textbooks, and how to compile and execute a Java program without an IDE. Additional articles will discuss designing the course structure and the role of lectures and labs, integrating student projects in the course, and evaluating student assignments and projects.

The Java Software Development Kit
Under the SDK Hood
Textbooks and References

The logistics of getting a classroom up and running in Java is surprisingly easy and inexpensive, hardware aside. My experience is with workstations running some later versions of Microsoft Windows, though this information should also be generally applicable if you work with Apple or Linux workstations.

The Java Software Development Kit
The Java language Software Development Kit (SDK) is distributed for free by its developer, Sun Microsystems (a link to this and the other sites mentioned is available in "More," below). Go to their site and download the latest SDK. This is a 38 MB zipped file. You will want the Standard Edition (J2SE 1.4.1 is current as of this writing). Versions are available for Windows and Linux machines. Apple computers offer outstanding out-of-the-box support for Java, and further information can be obtained from Apple. Installation of the software is straightforward and includes both the software development tools and the runtime software needed to execute Java applets and applications.

You will also want to download and install the documentation. It is available in a variety of formats, including Windows help file and PDF formats, but I've found the HTML version to be the easiest to use. This is a 32 MB zipped file. Install the documentation files in a subdirectory of the SDK directory. I use the default install directory for the SDK: j2sdk1.4.1_01, and I place the documentation files in a \docs subdirectory.

If you are on a network, maintain a copy of the SDK install file and documentation file so that it can easily be installed on new or upgraded workstations throughout the year. Otherwise, or perhaps additionally, burn a CD with these files. Students might also like the CDs for installing the software at home.

The main Java executable files that you will be working with are located in the j2sdk1.4.1_01\bin subdirectory. The bin is short for binary, as opposed to, say, text or source files. The binaries include javac.exe (the Java compiler that processes Java source code to Java metacode) and java.exe (the Java runtime program that interprets Java metacode into native code). It is helpful to go into the j2sdk1.4.1_01\docs\api subdirectory and drag a shortcut for the file index.html onto the desktop. This will make the API documentation readily available as you work. You will quickly find that in this very object-oriented language, the API docs are your best friend.

Under the SDK Hood
To understand the basics of the Java SDK, I've found it helpful to do some simple command-line work. You may want your students to do this as well. It seems a little masochistic, but it's nice to know some of the things those smart editors and IDEs do for you behind the scenes. Let's do this to write and run the traditional Hello World! code.
  1. Invoke a simple text editor such as Windows Notepad and enter and save the following source code (save it as the file HelloWorld.java to a near-root subdirectory so that pathnames don't get overly long). Note that Java source files must be named exactly like the name of their public class: HelloWorld in our case.

    public class HelloWorld
    { 
    		public static void main(String args[])
    		{
    			System.out.println("Hello World!");
    		}
    }
  2. Drop to a command-line prompt (Start menu: Programs/Accessories/Command Prompt in Windows XP).
  3. Navigate to the directory containing your source file. Mine is in c:\my documents\, so I type cd c:\my documents.
  4. Enter the command to compile the source code to metacode:
    c:\j2sdk1.4.1_01\bin\javac HelloWorld.java
    You may need to modify the path for your particular installation.
  5. Do a directory listing (dir Hello*.*), and you should see entries for both your Java source file (HelloWorld.java) and the Java metacode file (HelloWorld.class) created by the Java compiler. This metacode file can be executed on any platform supported by Java. That's one of the real benefits of Java: portability.
  6. To execute the metacode file, enter:
    c:\j2sdk1.4.1_01\bin\java HelloWorld
    You should see those traditional words displayed on the console.
There, that's the full, basic Java development cycle. It is a lot easier to use an intelligent "programmer's" text editor such as TextPad for source code writing and for invoking both javac.exe and java.exe. My students and I typically use a full-blown integrated development environment (IDE) to edit source code, manage files, and invoke the proper Java executables. I am particularly fond of JCreator, which is available in both free and professional versions. If you monitor the AP Computer Science electronic discussion group (EDG), you will hear about a number of other editors and IDEs. You can find direct links to various available IDEs on Debbie Carter's Java Resources for AP Computer Science Teachers Web page.

Textbooks and References
There are many good textbook and reference possibilities, and I again refer you to the AP Computer Science EDG for suggestions and guidance. AP Central's Teachers' Resource Catalog posts teacher reviews of many of the more popular introductory Java texts. These reviews link to the publishers' Web sites to provide easy access to more information about the books being reviewed. Sun's online Java Tutorial is also an excellent source of information. My computer science students use Java: How to Program, 4th ed. by Harvey Deitel and Paul Deitel. The book is out (or about to be out) in the fifth edition now. It is a large text, but I like the fact that it starts by assuming no programming experience and yet has tremendous scope for more advanced studies. I also like that its code examples are fully executable small programs; my students find this very satisfying as well. If you don't choose to use it for class, I suggest a copy for your reference bookshelf.

In Part III of this series, I will write about how you might structure a year-long computer science course in Java.


Please note: Some topics covered in this series of articles are not included in the defined curriculum. Refer to the current official AP CS Course Description for the topics that will be tested on the AP Exams.

James Aldridge, Ph.D., is a science and computer science teacher at Fort Worth Country Day School in Fort Worth, Texas. He has taught computer programming for 10 years and currently teaches AP Computer Science using Scheme, Java, and C++. James also teaches AP Chemistry and has special computer science interests in the area of real time data acquisition and control subsystem hardware and software design.






  MY AP CENTRAL
    Course and Email Newsletter Preferences
  AP COURSES AND EXAMS
    Course Home Pages
    Course Descriptions
    The Course Audit
    Sample Syllabi
    Teachers' Resources
    Exam Calendar and Fees
    Exam Questions
    AP Credit Policy Information
  PRE-AP
    Teachers' Corner
    Publications
  AP COMMUNITY
    About Electronic Discussion Groups
    Become an AP Exam Reader

Back to top