Introduction to Java

Dr. C. Floyd Richmond

West Chester University

 

Abstract:

Java is a programming language designed primarily for use on the internet. A Java application, called an applet, can be included in an HTML page much like an image. When a Java-compatible browser is used to view the page, the applet’s code is transferred to the system and executed by the browser. Current versions of Netscape and Internet Explorer for Macintosh and IBM computers, and several other platforms, support Java.

Java addresses shortcomings of HTML such as the difficulty of implementing complex interactions between computer and user. Implementing even a simple series of interactions, such as a tic-tac-toe game, would be a daunting task with HTML. With Java, however, the game may be reduced to a few lines of instruction. Implementing an interactive CAI lesson on the internet in which the computer also keeps score would again be a daunting task with HTML. Java handles the task with ease.

Topics presented include the following: an introduction to Java, a look at Java sites on the internet, using existing instructional Java applets in the classroom and in web sites, creating custom Java applets, security concerns, and system requirements.

Introduction

Java was created in 1991 by Sun Microsystems, initially for use as an operating system for consumer devices such as televisions and VCRs. The real growth and popularity of Java, however, occurred when the focus of development shifted to the internet. The most commonly used internet browsers (Netscape Navigator and Internet Explorer) can load and execute Java applets. The execution of the applets is handled by the browser rather than the computer's operating system so Java applets may run on any computer platform (Macintosh, IBM, UNIX, etc.). Those without a Java-capable browser may also run applets by using Sun Microsystem’s Applet Viewer, available for most computer platforms. Java’s cross-platform portability is a feature that appeals to many developers. Java will soon be incorporated in the operating systems of most computers so its popularity should continue to grow.

Java's Future

Numerous computer companies have announced plans to embed Java into their operating systems. These companies include Apple, IBM, Microsoft, Hewlett-Packard, Hitachi, Novell, SiliconGraphics, SunSoft, and others.

A Look at Java Sites on the Internet

Java is in its infancy as a programming language, but music applets are already beginning to appear. Below are descriptions and addresses of pages that present musical concepts. Topics addressed include listening and moving to music, notating and composing music, analyzing and identifying music, and twentieth century compositional techniques.

Also available are applets that can be used to illustrate the connections between music and the visual arts. The Impressionist site (http://reality.sgi.com/grafica/impression/) allows users to convert electronic photographs into Impressionistic style "paintings". These creations contain many of the subtleties, and nuances of music of the age. The Mondrian Creator site (http://pobox.com/~piran/mondrian/creator.html) creates "paintings" in the style of Pier Mondrian, a twentieth-century painter whose rectangular shapes and lines capture the spirit of much twentieth-century music.

Table 1. Selected Music Sites

Java Music Box

A growing number of applets are used to organize and play musical excerpts.

http://www-a2k.is.tokushima-u.ac.jp/java/MusicBox.html

Java Keyboard Applet

Play tunes by clicking on the keyboard

http://www.pageplus.com/~bigears/keyboard.html

Ear Training on the Internet

Practice interval identification on the internet

http://www.pageplus.com/~bigears/index.html

Rainer Typke: Tune Recognition

Save a monophonic wave file (or write the tune in "contour code") and the computer will guess what it is. Java security prohibits reading local files when run over the internet.

http://wwwipd.ira.uka.de/tuneserver/

Java-Dance

Refresh your memory of ballroom and popular dances. Animations show where both partners should place their feet for waltzes, foxtrots, etc.

http://tech-www.informatik.uni-hamburg.de/dance/JDance-e.html

TwelveToneToyBox

Create, edit, and listen to twelve tone rows. Calculate matrices instantly. Graphically display the results on a clock face.

http://www-personal.umich.edu/~fields/TTTB

Musical Set Theory Calculator

Create, edit, and hear all types of pitch class sets.

http://php.indiana.edu/~ltomlin/settheory/

The vOICe Sonification Applet

Create polyphonic compositions by turning notes on and off on a grid. Art may be imported to the grid for interesting results.

http://ourworld.compuserve.com/homepages/Peter_Meijer/javoice.htm

JComposer

Competition for Finale, Encore, and Nightingale is looming. This program takes the initial step toward implementing notation software for the internet.

http://www.alulabs.com/projects/JComposer

 

Educational applets in a number of disciplines are becoming popular. Some distinguished sites are provided in Table 2.

Table 2. Selected Education Sites

Math Education Puzzles

http://mars.superlink.net/abogom/

Real-Time Satellite Ocean Imagery

http://narwhal.gso.uri.edu/cwatch1.html

Virtual Science - Basic Scientific Principles

http://www.dsuper.net/~ashabah/

College Physics for Biology and Chemistry

http://www.rwc.uc.edu/koehler/biophys/text.html

Educational Physics Simulations

http://ucsub.colorado.edu/~gleason/Home.html

Crossword Puzzles - Vocabulary Development

http://www.puzzledepot.com/java/czplayer.shtml

Weather Visualizer - Satellite/Radar Maps

http://covis.atmos.uiuc.edu/java/image.html

One of the most useful features of Java is the level of interactivity that it allows. Table 3 contains links to "arcade" games that illustrate the interactive strengths of Java.

Table 3. Java Games–Java has Significant Interactive Potential

- Yahoo Tetris List

http://www.yahoo.com/Recreation/Games/Computer_Games/Genres/Strategy/Titles/Tetris/

Interactive_Web_Games/Java/

- Yahoo Space Invaders List

http://www.yahoo.com/Recreation/Games/Video_Games/Classic_Arcade_Games/Titles/

Space_Invaders/Java/

- Yahoo Asteriods List

http://www.yahoo.com/Recreation/Games/Video_Games/Classic_Arcade_Games/Titles/

Asteroids/Java/

- Yahoo Pong List

http://www.yahoo.com/Recreation/Games/Video_Games/Classic_Arcade_Games/Titles/

Pong/Java/

- Solitaire

http://www.cogapp.demon.co.uk/piran/patience/

The best source of information about Java is its creator, Sun Microsystems. The Java Development Kit, Sun’s "official" documentation, and links to other sites of interest are found at Sun’s internet site (see Table 4).

Table 4. Sun Microsystems Java Sites

Sun Microsystems

http://java.sun.com/

Java Development Kit

http://java.sun.com/products/jdk/1.0.2/installation.html

Java API Documentation

http://java.sun.com/docs/api_documentation.html

A number of additional sites also disseminate information about Java. Table 5 contains some of the most useful sites.

Table 5. Other Java Sites of Interest

Applets from JavaSoft

http://java.sun.com/applets/js-applets.html

Gamelan

http://www.gamelan.com/

Yahoo Java Links

http://www.yahoo.com/Computers_and_Internet/Programming_Languages/Java/

JavaWorld

http://www.javaworld.com/javaworld/common/jw-jumps.html

Netscape’s Selected Java Applets

http://www.netscape.com/comprod/products/navigator/version_2.0/java_applets/index.html

A Java Tutorial

http://www.javasoft.com/nav/read/Tutorial/Index.html

Welcome to AppleJava

http://applejava.apple.com/index.html

Creating Java Applets

Java applets are written using any text editor or Java authoring tool. They are then compiled into "byte-code" class files using Sun Microsystems Java Development Kit (JDK) or a similar Java development tool. After testing and debugging, applet class files are copied to an internet server (just as any other internet file) and referenced by the html pages.

Security Concerns

Due to the fact that Java applets are widely distributed over the internet, Sun has built security features into them. When loaded from the internet using a browser such as Netscape, applets are not permitted to read or write files locally. They may read or write information to the host computer on which they reside. If an applet is viewed using Sun’s Applet Viewer or compiled into a stand-alone application, they have greater input and output privileges. The chart below summarizes what applets can and cannot do. Notice the strong restrictions in the left-most column of the following chart.

A recently added feature of applets is a signature. Unsigned applets are always restricted, but users may choose to extend greater liberty to known applets.

What Applets Can and Cannot Do*

 

Stricter –––––––––––––––––-–––––> Less strict

 

NN

NL

AN

AL

JS

Read File In /home/me,

acl.read=null

No

No

No

Yes

Yes

Read File In /home/me,

acl.read=/home/me

No

No

Yes

Yes

Yes

Write File In /tmp,

acl.write=null

No

No

No

Yes

Yes

Write File In /tmp,

acl.write=/tmp

No

No

Yes

Yes

Yes

Get File Info,

acl.read=null

acl.write=null

No

No

No

Yes

Yes

Get File Info,

acl.read=/home/me

acl.write=/tmp

No

No

Yes

Yes

Yes

Delete File,

Using File.Delete()

No

No

No

No

Yes

Delete File,

Using exec /usr/bin/rm

No

No

No

Yes

Yes

Read the User.Name Property

No

Yes

No

Yes

Yes

Connect to Port on Client

No

Yes

No

Yes

Yes

Connect to Port on 3rd Host

No

Yes

No

Yes

Yes

Load Library

No

Yes

No

Yes

Yes

Exit(-1)

No

No

No

Yes

Yes

Create a Popup Window Without Warning

No

Yes

No

Yes

Yes

Key:

•NN: Netscape Navigator 2.x, loading applets over the Net

•NL: Netscape Navigator 2.x, loading applets from the Local file system

•AN: Appletviewer, JDK 1.x, loading applets over the Net

•AL: Appletviewer, JDK 1.x, loading applets from the Local file system

•JS: Java Standalone applications

*This table was created using information from Sun Microsystem’s internet site. An extensive discussion of security issues is available at the site (http://java.sun.com).

Suggested Reading

The first place to turn for information on Java is the Sun Microsystems site on the internet. Complete API documentation and links to several on-line tutorials are available. Documentation and tutorials may also be downloaded.

Sun Microsystems http://java.sun.com/

Java Development Kit http://java.sun.com/products/jdk/1.0.2/installation.html

Java API Documentation http://java.sun.com/docs/api_documentation.html

A Java Tutorial http://www.javasoft.com/nav/read/Tutorial/Index.html

Selected Java Bibliography

The following list of books was found on America On-Line’s Java forum.

IDG Books (800-762-2974)

Creating Cool Web Applets with Java

Danny Goodman's JavaScript Handbook

Foundations to Java Programming for the World Wide Web

Osborne/McGraw-Hill (800-227-0900)

The Java Handbook

Que Books (800-428-5331)

Learn Java in 7 Days

The Coriolis Group Inc (800-410-0192)

Java Programming EXplorer (book/CDROM)

The Java Programming Language

O'Reilly & Associates (800-998-9938)

Java Explorer

Java in a Nutshell: Quick Reference for Desktop Java Programmers