Introduction to Java. A tutorial from A-SQUARE, Inc. January 2003

© 2000-2003 A-Square, Inc. Cambridge, MA

Uploaded to www.rart.com/JavaIntro0301/ on Jan. 15, 2003

An Introduction to Java based on Java's Platform Independent Graphics Capabilities

This introduction to Java is provided as a continuing education service by A-Square, Inc. The course was developed by Jan Aminoff and reflects experiences from previous presentations. It has been offered over the Internet in various forms since 2000. The first face to face instance of this course was sponsored by IEEE and scheduled at the University of Maryland, in October, 2000. The second instance, also with IEEE, was scheduled at the University of Maryland in May, 2001. See also Rart® at http://www.rart.com

Summary

A unique feature of Java is its graphics capabilities which are used to develop user interfaces as well as platform independent animations. This course will emphasize the graphics of Java and use animations as a means to demonstrate the powerful capabilities inherent in object oriented programming generally and Java particularly. It can be seen as an introduction using a subset of Java. The course teaches the fundamentals of Java and goes into some dept with regard to graphics without going into the the richness of detail that would be required of a course touching even superficially all the application areas where Java has been enriched.

The course is intended to be offered as a face to face series of perhaps eight one hour lectures. The Exercises, however, are intended for selfstudy. A student with some experience with the platform should be able to complete the closed end exercises all in one evening, but may be inspired to spend considerable time on the open ended exercises.

After having attended the class, a student will have a general idea of the intent and the capabilities of Java, especially with regard to its graphics possibilities. If the student takes the time to do all the exercises, he or she should be able to do some useful and interesting customizations based on programs demonstrated during the course. The course leads the student to where he or she should be able to begin to use the Rart system to create Random Art.

Content

Lecture and Demonstrations

Exercises

Software for exercises

References

Acknowledgments

Lecture and Demonstrations

The following topics are covered in roughly the indicated order: (The lecture notes are not yet part f the Internet accessible course):

History of Java. The intent to make Java a platform independent net centric programming language. How Sun has developed and promoted Java. The evolution of Java, C# and Java, J2ME, for handheld devices. The Java Development Kit, JDK. Java today.

Java Basics. Applications and Applets. Demonstration of the Welcome Applet. Classes, Objects, and Methods. Byte code and the Java Virtual Machine. Platform Independence. The Applet HTML-tag.

Java Syntax. Walk through of Source of Banner1 with Demo of Banner1. The principle of Libraries. Basics of the Abstract Windowing Toolkit, AWT.

Object Oriented Programming. Structure of an Object Oriented language. Encapsulation and Inheritance. Abstract Classes. Banner2.

Java fundamentals used for Rart. The abstract class Universe and what it prescribes. uParameters. The Rart Development Kit. Banner3. The RRL rartrunner

The principles of Rart, Random Art. The Eggs universe. The RRlet rartrunner.

How to be a Rartist. Check out and modify Lines and Flakes. How to build your own universe. The Rart application environment, rartrunner RR11.

Top

Exercises

In the Exercises, we develop Java applets, that is programs that are written in Java, source code, and compiled to bytecode. Personal Computers, PCs, are boxes with hardware. Their main user characteristics are provided through the operating system that integrate the hardware and provide the user interfaces. The combination of PC hardware and operating system is often called a platform. One of the main advantages of Java is that, once a Java program has been compiled to bytecode it can run without any modifications on many platforms. In this course, the exercises can be completed using the most common platforms, Windows, Linux/Unix and Mac OSX. (That is the intent. Reality may take some time to catch up. The windows version is supported as of January 2003, with Linux shortly thereafter. It looks as if Mac OSX will have some catch up to do itself before all the pieces are in place)

The details of how to do the exercises are given in How to do Exercises in a platform independent way, but with links to any platform specific details. The Introduction to Java Exercises are displayed and commented b rieflyin a separate document actually Lecture Notes for JICC7

For the purposes of this class we will assume that you have the JDK 1.1.8 installed and that you have a Java enabled browser. We will also assume that you will use a simple text editor to enter and edit Java source as well as HTML documents.

Exercise 0. Compile and execute the Welcome applet. Modify and repeat until happy.

Exercise 1. Compile and execute the Banner1 applet. Modify and repeat.

Exercise 2. Compile and execute the Banner2 applet. Modify and repeat.

Exercise 3. Compile and execute Banner3, a simple Rart universe. Execute in RRL rartrunner applet. Modify and repeat.

Exercise 4. Compile and execute the Eggs universe.Execute in the RRlet rartrunner applet. Modify and repeat

Exercise 5. Compile and execute the Lines and Flakes universes, Execute in the RR11 rartrunner application. Modify and repeat.

Software for the Exercises.

These exercises require a Java development environment supporting Java as defined by JDK 1.1.8. This is readily available as a download from Sun ( about 8.8 Mb). Exercises 0, 1 and 2 require this environment only. If you are downloading and installing JDK for the first time, you should be careful to follow the directions including setting the CLASSPATH variable. See http://java.sun.com/products/jdk/1.1/download-jdk-windows.html .

Exercises 3, 4 and 5, require software from A-Square in addition to that from Sun. This software is part of the Rart Development Kit, RDK, and can be provided after request to A-Square on a CD. The RART CD will, in addition to the required software, have a fairly complete mirror of the JavaIntro030115 web site. For the CD, A-Square requires a fee for postage and handling. Please allow one to two weeks for delivery and send a check for US$15.00 (fifteen dollars) to

A-Square Inc. Attention: JavaIntro
175 Richfield Ave, Suite 121
Cambridge MA 02140
Top

References

Printed References

The field is moving quite rapidly so books become obsolete or replaced with newer editions. It is necessary to consider any book in the context of what version of JDK it covers. In this tutorial we will deal with material stabilized with JDK 1.0.2. However, we will also refer to JDK 1.1.x, in particular the newer event model. In August 1999, Sun released JDK 1.1.8 as a stable release. However, JDK 1.2 was also released early in 1999 and to confuse matters somewhat Sun decided to rename 1.2 as 2.0 and you will see references to Java 2.0 on books, occasionally in the form of a sticker on top of 1.2. For people wanting to have additional references we recommend some listed below (although you might wish to defer any acquisition until you know that you will need the very latest). I would like to recommend one book in particular: JAVA in a Nutshell, Second Edition, David Flanagan, O'Reilly 1997. It is complete, well written, and dedicated to Java through JDK 1.1.8. Unfortunately it it was out of print in January 2003. The next best thing would now (January 2003) be a combination of the following two books in the Nutshell series. Java in a Nutshell, Fourth Edition, David Flanagan, O'Reilly 2002.which describes the Language fundamentals and Java Foundation Classes in A Nutshell, David Flanagan, O'reilly 1999, which describes the tools to build graphic user interfaces as well as other graphics.

The following books are updated editions of well considered earlier releases:

From Sun Microsystems Press: ( See http://www.sun.com/books/java_series.html)

Core JAVA 1.1 Volume I-Fundamentals, Cay S. Horstman and Gary Cornell, Sun Microsystems Press 1997. The 600 plus pages of this book covers well the materials in this tutorial. It is directed to persons with some programming experience and is a useful reference offering good programming patterns to emulate. The book is accompanied by a CD including JDK 1.1.2 and a sample excellent editor: WinEdit.

Core JAVA 1.1 Volume II - Advanced Features, Cay S. Horstman and Gary Cornell, Sun Microsystems Press 1998. Another 600 plus pages. You may wish to add this book to your library if you have some specifics you'd like to know about, but you can do about anything related to Applet animations with Volume I..

Core Java 2 Volume I - Fundamentals, Cay S. Horstman and Gary Cornell, Sun Microsystems Press 1999, 750 pages.Updated for Java 2. With CD.

Core Java 2 Volume II - Advanced Features, Cay S. Horstman and Gary Cornell, Sun Microsystems Press 2000, 920 pages.Updated for Java 2.With CD with Java2 SDK Standard Edition v. 1.2 for Windows.

Just Java 1.2 Fourth Edition, Peter van der Linden, Sun Microsystems Press 1999. This is a very good book for the intelligent and interested reader. In its 700 plus pages it provides "the most painless way to learn Java and object oriented programming".

From O'Reilly: (See http://www.oreilly.com/catalog/javanut3/)

JAVA in a Nutshell Second Edition, David Flanagan, O'Reilly 1997. This books greatest value is as a reference to Java through 1.1 which in compact and recoverable form lists details of JAVA classes not easily found elsewhere. A deluxe edition includes a searchable CD.

Java in a Nutshell 3rd Edition, David Flanagan, O'Reilly 1999. As Java has developed after JDK 1.1, the main additions have been in the form of new areas which have been provided with specific functionalities through packages of classes. It makes sense for this reason to split the references according to such areas. Accordingly, for a complete coverage, you will also need Java Foundation Classes in a Nutshell (which covers AWT in addition to other GUI subjects) as well as Java Enterprise in a Nutshell which includes descriptions of classes of particular interest to server-side or enterprise programmers.

Internet References

The ultimate Java Authority from Sun Microsystems: :http://java.sun.com/

Excellent Tutorials are listed on http://java.sun.com/docs/books/tutorial/

The central listing of Java resources: http://www.gamelan.com

A good and comprehensive Java FAQ is maintained by Peter van der Linden: http://www.afu.com/javafaq.html

For anything to do with Rart®, Random Art: http://www.rart.com

Top

Acknowledgments in Small Print

Java is a trademark of Sun Microsystems Inc.

RART® is a registered trade mark of A-Square Inc.

The material on this page and of the pages to which this page provides an index is copyrighted and all rights reserved to A-Square, Inc.. Cambridge MA.

© A-Square, Inc. 2000-2003.