HELP! * YELLOW=global GREY=local Full HTML for

GLOBAL foilset Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview

Given by Nancy McCracken at CPS616 spring 1997 on Jan 22 1997. Foils prepared 1 February 97
Abstract * Foil Index for this file Secs 40.3 See also color IMAGE

What is Java!
Good Books
Java Compared to JavaScript
Language Characteristics (Why its Great)
Basic Applets and Graphics Classes
Language Syntax

Table of Contents for full HTML of Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview


1 CPS 616 Java Lectures
with Audio January 22 97
Introduction and Base Applets
See:
http://www.npac.syr.edu/users/gcf/cps616-97jan22

2 Abstract of CPS616-97 Lecture of January 22
3 Java Tutorial - Fall 1996
Part 1: Introduction to Java Language
and Applets
http://www.npac.syr.edu/users/gcf/javafall96/
http://www.npac.syr.edu/projects/tutorials/Java/

4 What are Java and HotJava in a NutShell?
5 HotJava's Future 1996- ?
6 Overview -- Java and the World Wide Web
7 Overview -- What are Java applets in detail?
8 Running a Java Applet
9 History of Java Language and Team
10 History of Java Language and Team (contd)
11 JDK 1.0 -- The Real Java Development Kit!
12 Java Beta Books -- I
13 Java Beta Books -- II
14 Java Beta Books -- III
15 Comparison of Java and JavaScript -- I
16 Some Key Java Features
17 Java Features -- It's Simple and Familiar!
18 Java Features -- It's Object-oriented
19 Java Features -- It's Architecture-Neutral
20 Java Features -- It's Portable
21 Java Features -- It's Somewhat Interpreted
22 Java Features -- It's Distributed
23 Java Features -- It's Robust
24 Java Features -- It's (Hopefully) Secure
25 Java Features -- High Performance
26 Java Features -- It's Multithreaded
27 Java Features -- It's Dynamic
28 Java Tutorial - Fall 1996
Part II: Java Language and
Object-Oriented Concepts
http://www.npac.syr.edu/users/gcf/javafall96/
http://www.npac.syr.edu/projects/tutorials/Java/

29 Resources for the Java Programming Language
30 Applications
Applets and their use from HTML
Java Applications

31 The Simplest Java Application: Hello, World!
32 Java Applets
33 Applet Tag: Calling Applets from HTML - I
34 Applet Tag: Calling Applets from HTML - II
35 <param> Tags and Applets
36 The Simplest Java Applet: Hello, World!
37 Displaying your applet from a Web page.
38 Java Language -- Lexical Issues I
39 Java Language -- Program Structure
40 Java Language -- Variable/Expression Types
41 Java Language -- Types: Array
42 Java Language -- More on Arrays
43 Java Language -- Expressions
44 Java Language -- Control Flow I
45 Java Language -- Control Flow II -- continue
46 The Graphics class
47 Using Graphics properties
48 Drawing simple shapes
49 Passing parameters to an applet: the HTML
50 Passing parameters to an applet: the applet
51 Centering a string in the applet window.
52 Applet Flow of Control
53 Random color boxes example
54 Arrays of random colors

This table of Contents Abstract



HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 1 CPS 616 Java Lectures
with Audio January 22 97
Introduction and Base Applets
See:
http://www.npac.syr.edu/users/gcf/cps616-97jan22

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 36 Full HTML Index
Instructor: Nancy McCracken
teamed with Meryem Ispirli, Geoffrey Fox,
Tom Scavo, John Yip
Syracuse University
111 College Place
Syracuse
New York 13244-4100

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 2 Abstract of CPS616-97 Lecture of January 22

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 40.3 Full HTML Index
What is Java!
Good Books
Java Compared to JavaScript
Language Characteristics (Why its Great)
Basic Applets and Graphics Classes
Language Syntax

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 3 Java Tutorial - Fall 1996
Part 1: Introduction to Java Language
and Applets
http://www.npac.syr.edu/users/gcf/javafall96/
http://www.npac.syr.edu/projects/tutorials/Java/

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 70.5 Full HTML Index
Instructors: Geoffrey Fox
Nancy McCracken
Syracuse University
111 College Place
Syracuse
New York 13244-4100

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 4 What are Java and HotJava in a NutShell?

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 48.9 Full HTML Index
What is Java?
  • A simple, object oriented, distributed, interpreted, robust, safe, architechture neutral, portable, high performance, multithreaded, dynamic language.
What is HotJava?
  • Web browser written entirely in Java-based language
  • Toolkit for building Web-aware applications
  • Alpha version received a lot of attention from april to november 1995 but the latest version only came in april 1996 and has not been evaluated in detail by NPAC
    • It is clearly less sophisticated than Netscape 2.0/3.0 at the moment!

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 5 HotJava's Future 1996- ?

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 50.4 Full HTML Index
HotJava toolkit (1996-): class libraries for building web-aware applications i.e. The "Browser" class
  • HTML parsing
  • Document editing, formating, presentation (MVC-based)
  • Web navigation
  • Communications
Natural Use of HotJava is for applications where it is critical to customize User Interface to a greater degree than Netscape allows
Netscape hopes you will use JavaScript to customize a core browser supplied by Netscape

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 6 Overview -- Java and the World Wide Web

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 120.9 Full HTML Index
Browsers (HotJava, Netscape 2.0/3.0 ..) supporting Java allow arbitrarily sophisticated dynamic multimedia applications inserts called Applets, written in Java, to be embedded in the regular HTML pages and activated on each exposure of a given page.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 7 Overview -- What are Java applets in detail?

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 48.9 Full HTML Index
Applet constructs are implemented in terms of a
  • special HTML tag: <APPLET codebase="URL directory path" code="Java class file name" width=".." height=".." >
  • where the URL and class file name points to a chunk of server side software that is to be downloaded and executed at the client side on each presentation of a page containing this applet which executes in window specified in size by width and height in picxels.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 8 Running a Java Applet

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 28.8 Full HTML Index
Steps to running a Java Applet:
  • 1. Write an HTML file that refers to the applet using the APPLET tag, described in later pages.
  • 2. If necessary, write the Java code and compile into class files
  • 3. Visit the HTML file with a web browser or with appletviewer.
Using a Browser
  • With a Java-enabled web browser, such as Netscape 2.0/3.0 or HotJava, you run an applet by "surfing" to a web page containing the APPLET tag.
Using appletviewer
  • When doing development, use appletviewer to run applets by specifying the HTML file on the command line:
    • appletviewer stock.html

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 9 History of Java Language and Team

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 59 Full HTML Index
Starts in 1991 by Project Green --- a group in Sun that detaches from the main campus as a semi-autonomous task force focused on operating software for consumer electronic devices such as smart set-top boxes
Gosling (creator of Sun NeWS which had major conceptual impact both on current Java and Telescript models) realizes that C++ is not adequate and initiates development of a new language Oak, later renamed as Java.
A PDA (Personal Digital Assistant -- codename *7) based on Oak/Java ready in 1993. Green Team incorporates as FirstPerson, Inc.
*7 proposal to Time-Warner rejected in 1993. 3DO deal falls through in 1994. FirstPerson, Inc. dissolves.
Small group (~30 people, now Java Team) continues development and decides to adapt Oak as a Web technology.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 10 History of Java Language and Team (contd)

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 51.8 Full HTML Index
An experimental web browser written in Java, called WebRunner and later renamed as HotJava, ready in 1994.
Java/HotJava published in April '95.
Netscape licences Java in May '95 and builds Java into Netscape 2.0 -- This confuses ownership and open-ness of Java
Beta JDK (Java Development Kit) published in summer/fall '95. It is better software but lower functionality than Alpha.
First alpha Java books appear in fall '95 such as a popular overview by SAMS and technical book "Java!" by Tim Ritchey, edited by New Riders.
Dec 4 1995 Business Week cover story on "Software Revolution --- The Web Changes Everything" exposes Java as a breakthrough force in the expanding Web/Internet. Also points out that "Java as a business" is yet to be defined.
In next week, SGI IBM Adobe Macromedia and finally Microsoft adopt/license Java. It appears that Java will be open and should be adopted by open Web community

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 11 JDK 1.0 -- The Real Java Development Kit!

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 54.7 Full HTML Index
Version 1.0 of JDK released January 96 by JavaSoft
1.0 JDK should be the Internet standard and so compatible with ongoing Java implementations by all licensees, most notably Netscape. Beta/1.0 JDK includes:
  • Java Compiler (.java to .class) for Sun Solaris and Windows NT/95 avaliable as .class itself (Javac written in Java) but no source
  • Java source for the foundation classes (modified and incompatible with alpha)
  • appletviewer to run/preview applets
  • tools for converting alpha applets to beta applets.
  • Source code for the interpreter

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 12 Java Beta Books -- I

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 41.7 Full HTML Index
Hooked on Java, by Java developers Arthur van Hoff, Sami Shaio, Orca Starbuck, Addison-Wesley, is the (first) serious (but still rather high-level) book on beta Java. It contains example applets, but not much on programming.
Teach Yourself Java in 21 Days, by Laura Lemay and Charles L. Perkins, Sams.net Publishing, is a "how-to" book at the intermediate programming level. It concentrates on applets and windowing more than the object-oriented part of the language.
Java in a Nutshell, by David Flanagan, is the language reference book in the familiar O'Reilly series.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 13 Java Beta Books -- II

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 72 Full HTML Index
The Java Programming Language, by Ken Arnold and James Gosling, Addison-Wesley, May 1996, has lots of details on the language basics for intermediate and advanced programmers. It covers threads and i/o packages, but not applets or windowing packages.
  • All serious computer scientists should read to understand fundamentals
Java Primer Plus, supercharging Web applications with the Java programming language, by Paul M. Tyma, Gabriel Torok, and Troy Downing, Sams.net, doesn't assume a lot of programming background, has chatty explanations and still covers lots of programming detail.
Java, How to Program, by Deitel and Deitel, Prentice-Hall, starts with beginning programming concepts and progresses rapidly through Java language. It has the most programming exercises.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 14 Java Beta Books -- III

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 72 Full HTML Index
There are five books in the Java Series from SunSoft Press, Prentice-Hall.
  • instant Java*, by John A. Pew, contains multimedia and animation applets for HTML authors. This is not a programming book.
  • Java by example, by Jerry R. Jackson and Alan L. McClellan, covers all key features with examples, but not as much detail about the language.
  • just Java, by Peter van der Linden, for intermediate programmers, gives good explanations of key features without going into detail.
  • core Java, by Gary Cornell and Cay S. Horstmann, offers detailed coverage of the language and packages for advanced programmers.
  • graphic Java, by Gary McClellan, gives more details on windowing and user interface and includes new classes (not in originial Java release) for such things as "rubberbanding".
* this title is great, but what happened to "express Java", "Percolating through Java", and "Java for Drips"?

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 15 Comparison of Java and JavaScript -- I

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 56.1 Full HTML Index
Netscape renames Livescript as Javascript and this is an interesting variant of Java which is fully interpreted (code can be included directly in HTML file)-- use for overall customization of client
Use Java for detailed programming and JavaScript for overall integration of client interface and system
JavaScript: Interpreted by client and NOT compiled
Java: Compiled on Server before execution on client
  • Note both are reasonably "pure" C/C++ like languages and do NOT have useful sh/awk text and system enhancements of Perl(5)
JavaScript: Object based -- no classes or inheritance -- built in extensible objects
Java: Object-oriented. Programs consist of object classes with inheritance

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 16 Some Key Java Features

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 25.9 Full HTML Index
Document The Java: A White Paper by Sun Microsystems -- October 1995 draft by James Gosling and Henry McGilton -- enumerates the following main features of Java:
Simple and Familiar
Object-oriented
Architecture-neutral
Portable
Somewhat Interpreted
Distributed
Robust
Secure
High performance
Multi Threaded
Dynamic

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 17 Java Features -- It's Simple and Familiar!

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 87.8 Full HTML Index
Java omits several rarely used, poorly understood and confusing features of C++ including operator overloading, multiple inheritance, pointers and automatic type coercions.
It adds automatic garbage collection which makes dynamic programming easier in Java than in C or C++.
  • No more mallocs!
It also adds 'Interface' construct, similar to Objective C concept, which often compensates for the lack of multiple inheritance by allowing method calling syntax to be "inherited".
The resulting language is familiar as it looks like C++ but is simpler and hence easier to program in.
It also results in a much smaller kernel which is suitable for planned Java ports to consumer electronic devices. Base (alpha) interpreter is ~40Kb, libraries and threads add additional 175Kb.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 18 Java Features -- It's Object-oriented

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 89.2 Full HTML Index
Java model can be viewed as a C++ subset, with some dynamic elements inherited from Objective-C (method overloading, garbage collection).
Structures, Unions and Functions are absorbed into data and methods of Java classes -- Java is Simple!
The strength of Java object-oriented model is not is sophistication but in simplicity and the extensive class library associated with the system (some 250 public classes were released in both alpha and beta).
Java class plays also a role of a communication atom in the Web embedding model. Applet classes identify themselves by names in the HTML applet tag. Applet downloads other classes, present in the applet source. Hence, the Java class names play the role of addressing mode for the distributed Java code database.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 19 Java Features -- It's Architecture-Neutral

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 67.6 Full HTML Index
C/C++ programming in a heterogeneous network environment requires use and compatibility across several vendor platforms and the corresponding compilers. This problem is solved in Java by designing platform-independent binary representation called Java bytecode (or opcode).
Java compiler (written in Java and platform-independent) reads Java source and generates Java bytecode. These bytecodes are shipped to client machines upon browser requests.
Each client machine must run Java interpreter which performs runtime execution of Java bytecodes. Java interpreter is written in POSIX compliant ANSI C and needs to be ported to and conventionally compiled (once) on each individual platform.
Once the interpreter is ported, application developers don't need to worry at all about platform specificity and differences between native compilers.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 20 Java Features -- It's Portable

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 86.4 Full HTML Index
Java language offers a uniform abstract (virtual) machine model which is identical for all platforms.
SUN owns the Java Virtual Machine (see online report) -- it is universal while classes can be added by any user
Unlike in C/C++ where various integers match the architecture of a physical machine at hand, Java byte, char short, int and long are always of the same size, equal to 8, 16, 16(unicode), 32 and 64 bits, respectively.
  • No header files, preprocessors,#define etc.
  • floating point is always IEEE 754
Differences between vendor specific windowing environments (X Windows, MS Windows, Macintosh) are removed in terms of the Abstract Windowing Toolkit (AWT) metaphor.
AWT is given by ~60 Java classes (alpha) which offer a universal GUI programming model, portable between UNIX, PC and Mac, and translated automatically to native windowing systems on individual platforms by Java interpreters.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 21 Java Features -- It's Somewhat Interpreted

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 11.5 Full HTML Index
Java represents a compromise between fully compiled (like C/C++) and fully interpreted (like Smalltalk or Perl) models.
Java "compiler" produces a binary bytecode output which is portable and much smaller than the real binary for a specific machine (Typical bytecode size is of order of the original source code, within a factor of 2).
Java "interpreter" executes this bytecode and is therefore less dynamic than e.g. Perl interpreter (which performs an equivalent bytecode construction internally and on-the-fly when reading the program source).
In general, the compilation process is: a) time consuming and b) platform specific. Hence, interpreters are built and used to facilitate a) rapid prototyping and/or b) portability. Java model is focused on platform independence but the development throughput is also reasonable since the Java compiler is fast and generates compact bytecode output.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 22 Java Features -- It's Distributed

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 24.4 Full HTML Index
Popular TCP/IP based protocols such as FTP or HTTP are supported in terms of network protocol classes. This facilitates various forms of distributed processing. New protocols (e.g. PVM etc.) can added and dynamically installed.
Distributed computing model of Java is mainly client-server, with Java compiler preparing the opcodes at the server side, and Java interpreter executing it at the client side.
One can expect more dynamic uses of Java with Java threads on both Server and Client side communicating with each other. This is illustrated by Java based Collaboratory developed by Vishal Mehra as NPAC/Ece Master's Thesis

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 23 Java Features -- It's Robust

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 48.9 Full HTML Index
Java enforces compiler-time type checking and eliminates this way some error prone constructs of C/C++.
Pointer arithmetic is fully eliminated which allows e.g. for runtime checking of array subscripts and enforces security of the Java model.
Explicit declarations are always required, i.e. C-style implicit declarations are abandoned. This allows the Java complier to perform early error detection.
Rapid prototyping in Java is less natural than in JavaScript,Lisp, Tcl, Smalltalk or Perl, but the software quality assurance of Java is higher than in these more dynamic and 'forgiving' languages.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 24 Java Features -- It's (Hopefully) Secure

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 116.6 Full HTML Index
Java bytecodes are shipped across the network and executed on client machines. Security is therefore a critical issue and strongly enforced in Java.
  • Java contains its own networking classes which are designed to be secure
Modifications of the C++ model such as eliminating pointer arithmetic and coercion were dictated mainly by the security requirements.
Most viruses are based on acquiring access to private/protected sectors of computer memory which is impossible in Java.
Java opcodes are executed at the client side by Java interpreter which operates exclusively on the virtual memory. Hence, unless there are security bugs in the Java interpreter itself, the model is safe and users cannot create security holes by incorrectly or maliciously written applets.
The bytecodes sent across network are verified at the client which prevents evil/corrupted classes from causing problems

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 25 Java Features -- High Performance

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 73.4 Full HTML Index
Java interpreter performs on-the-fly runtime execution of the Java bytecodes which results typically in a satisfactory performance.
  • NOT true in initial software which is often 100 times slower than C
  • performance is improved in new "just-in-time" interpreters, which saves code for repeated sections to provide compiled code efficiency after first execution
Support for generating native machine code out of Java bytecodes, viewed as intermediate compiler form, is also provided and useful for performance demanding applications.
The performance of the machine code, generated from Java bytecodes, is comparable to that offered by typical C/C++ compilers on the same platform.
Several of these concepts are in fact similar as in the OSF/ANDF project. Using ANDF terminology, we would call Java compiler a 'producer', and the machine code generator discussed here, an 'installer'. Default Java working mode doesn't use installers but directly interprets the intermediate form (this mode is supported in ANDF by GAI -- Generalized ANDF Interpreter).
Java/HotJava system implements ANDF concepts for the Java language.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 26 Java Features -- It's Multithreaded

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 18.7 Full HTML Index
Java model offers preemptive multithreading, implemented in terms of the Thread class. Thread methods offer a set of synchronization primitives based on monitor and conditional variable paradigm by C.A.R. Hoare. Java threads inherit some features from the pioneering Cedar/Mesa System by Xerox Park that gave birth to Macintosh and object-oriented programming.
A typical use of Java multithreading in applet programming is to have several independent but related simulations (e.g. various sorting algorithms), running concurrently in an applet window. Multithreading is also used internally by the browser to handle multiple document dynamics.
Another interesting application domain are multi-HotJava environments to come such as collaboratory or gaming.
Java threads don't have built-in point-to-point communication primitives. Various thread communication environments can be provided by coupling the thread and network protocol objects.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 27 Java Features -- It's Dynamic

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 28.8 Full HTML Index
Java model is more dynamic than C++ and closer to Smalltalk or Perl.
Subclasses don't need to to be recompiled after superclass implementation is updated.
C++ has "fragile superclass" problem where must recompile children if change anything (method/instance variable) in a superclass or referenced class -- Java resolves references at runtime and avoids this.
Classes have runtime representation (implemented in terms of the Class class) which allows one to look up type of a given object instance at runtime (in C cannot know if pointer is to integer or browser!)

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 28 Java Tutorial - Fall 1996
Part II: Java Language and
Object-Oriented Concepts
http://www.npac.syr.edu/users/gcf/javafall96/
http://www.npac.syr.edu/projects/tutorials/Java/

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 28.8 Full HTML Index
Instructors: Geoffrey Fox ,
Nancy McCracken
Syracuse University
111 College Place
Syracuse
New York 13244-4100

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 29 Resources for the Java Programming Language

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 40.3 Full HTML Index
The original resource was the The Java Language Specification by Sun Microsystems, Inc., March 1995 updated to October 1995 but superceded by Gosling and Arnold Book
  • Addison Wesley has several other fundamental Java books on Application Programming Interface and Language Specification and Virtual Machine (by end of summer 1996)
http://www.javasoft.com web site has plenty of references including
  • Tutorial: http://www.javasoft.com/books/Series/Tutorial/index.html
  • Books:http://www.javasoft.com/java.sun.com/aboutJavaSoft/book-news.html
  • Collection of Applets: http://www.gamelan.com
Most of the books cited earlier have CDROM's with examples or the JDK.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 30 Applications
Applets and their use from HTML
Java Applications

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 154 Full HTML Index
All Java programs are written into a file with a ".java" extension.
Applications are .java files with a main class which is excuted first.
How to compile and run a Java application:
  • Run the compiler on a .java file:
    • javac MyProgram.java
    • producing a file "myprogram.class" of Java bytecodes
  • Run the interpreter on a .class file:
    • java MyProgram
    • which executes the bytecodes
The resources javac and java are part of JDK and are not in Netscape and so are not necessarily available on the same machine as your web server.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 31 The Simplest Java Application: Hello, World!

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 145.4 Full HTML Index
Since Java is object-oriented, programs are organized into modules called classes, which may have data in variables and functions called methods.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 32 Java Applets

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 123.8 Full HTML Index
Java applets are classes written in Java which are intended not to run as stand-alone programs (as applications do) but as subprograms of a browser which is already managing a window.
Applets should NOT have main method but rather init, start, paint etc. for displaying on the browser window
The applet should be run through javac compiler getting a .class file as before:
    • javac MyApplet.java
Also create an HTML file (say MyApplet.html) with an applet tag.
Two ways to run an applet:
  • If you have JDK on one's machine, one can run the applet with appletviewer
    • appletviewer MyApplet.html
  • Alternatively, run Netscape 2.0 essentially anywhere, point the browser at MyApplet.html, and applet is downloaded from the webserver and run by Java interpreter built into Netscape. This requires that the .html and .class files are located in the document space of the web server.
This way we can compile on places with JDK installed but run almost anywhere!

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 33 Applet Tag: Calling Applets from HTML - I

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 44.6 Full HTML Index
Given the following HTML
  • <APPLET CODE="StockGraph"
    • CODEBASE="http://www.javasoft.com/applets/"
    • WIDTH=200 HEIGHT=200>
  • </APPLET>
Runs the "StockGraph.class" executable as an applet.
WIDTH and HEIGHT are attributes that are passed along to the applet.
If the optional CODEBASE attribute is provided, then load the executable image from the directory specified by CODEBASE.
  • Without the CODEBASE attribute, will look for StockGraph.class in the local server's hierarchy (relative to where the HTML was loaded)
  • With the CODEBASE attribute will look for StockGraph.class on the given http hierarchy.
Tag and attribute names are case insensitive.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 34 Applet Tag: Calling Applets from HTML - II

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 34.5 Full HTML Index
<APPLET CODE="StockGraph" WIDTH=200 HEIGHT=200
  • ALT="-- StockGraph Not Supported --"
  • NAME=SUNW ALIGN=top
  • VSPACE=5 HSPACE=5>
Put a bunch of text here to be displayed by browsers such as Netscape 2.0 on Windows 3.1 that do not support Java
</APPLET>
ALT specifies text to displayed if the browser understands the applet tag, but if unable to run applets.
NAME specifies the name of this instance of the applet; This will make it possible for applets on the same page to find and communicate with each other.
ALIGN specifies the alignment of the applet. The possible values are the same as those available in the IMG tag (top, middle, bottom, texttop, absmiddle, baseline, absbottom, left, right).
  • Align=top which aligns top of applet with top of tallest item in the line
  • Align=texttop which aligns top of applet with top of the tallest text in the line
VSPACE and HSPACE specifies the vertical and horizontal spacing in pixels, around the applet space.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 35 <param> Tags and Applets

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 43.2 Full HTML Index
The applet tag can be followed by parameters:
  • <applet . . . >
  • <param name=attributename1 value="attributevalue1" >
  • .......
  • <param name=attributenameN value="attributevalueN" >
  • </applet>
The Java program accesses this information by
  • String attribute;
  • attribute = getParamter("attributename1");
  • if( attribute == null )
  • attribute = yourdefaultvalue;
    • // null is Java way of saying unset
Typically this processing would be in init() method of Applet

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 36 The Simplest Java Applet: Hello, World!

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 169.9 Full HTML Index
Java applets are part of the class hierarchy that can call methods to display on a screen (within the browser window). This example defines the public method paint in this class and calls a method drawString defined in the class Graphics.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 37 Displaying your applet from a Web page.

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 83.5 Full HTML Index
You should name the file with your applet name, HelloWorldApplet.java, run the compiler (javac), getting a bytecode file HelloWorldApplet.class, which you put in a web directory.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 38 Java Language -- Lexical Issues I

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 80.6 Full HTML Index
Lexical structure inherits a lot from C/C++. There are however some notable differences which are listed below.
Java characters are based on 16--bit wide Unicode Worldwide Character Encoding rather than the usual 8--bit wide ASCII.
This allows full support of all alphabets and hence all languages
Three types of comments are supported:
  • // ignore all till the end of this line
  • /* ignore all between starts */
  • /** an insert into an automatically generated software documentation */
for /** */ one inserts HTML documentation with some simple macros such as @see (to designate see also) BEFORE the method or class being documented

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 39 Java Language -- Program Structure

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 61.9 Full HTML Index
Source code of a Java program consists of one or more compilation units, implemented as files with .java extension.
Each compilation unit can contain:
  • a package statement
  • import statements
  • class declarations
  • interface declarations
Java compiler (called javac) reads java source and produces a set of binary bytecode files with .class extensions, one for each class declared in the source file. For example, if Foo.java implements Foo and Fred classes, then "javac Foo.java" will generate Foo.class and Fred.class files.
Suppose that Foo implements an applet and Fred is an auxiliary class used by Foo. If HotJava/Netscape encounters a tag <APPLET code="Foo.class">, it will download Foo.class and Fred.class files and it will start interpreting bytecodes in Foo.class.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 40 Java Language -- Variable/Expression Types

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 72 Full HTML Index
Each Java variable or expression has a definite type. There are three "types" of types!
  • There are Primitive or Simple types such as integers or booleans which are built-in.
  • New composite types (objects) can be constructed in terms of classes and interfaces. The type of an object is its class or interface
  • Arrays we will see are a sort of "almost" object!
First we discuss the Primitive Types
  • There are 4 integer types: byte, short, int, long of size 8, 16, 32 and 64 bits, respectively.
  • Float is 32 bits, double is 64 bits. Floating point arithmetic and data formats are defined by IEEE754 standard.
  • Characters are given by 16bit Unicode charset and represented as short integers.
One can use casts such as longint = (long) i; // which can be explicit as here and sometimes implied (see later)
Note booleans are either TRUE or FALSE -- they are not 0, 1 ,-1 ...

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 41 Java Language -- Types: Array

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 141.1 Full HTML Index
Arrays are "true" or "first class" objects in Java and no pointer arithmetic is supported.
An Array is declared as:
  • int vec[];
alternative syntax: int[] vec;
and created by:
  • vec = new int[128];
or concisely:
  • int vec[] = new int[128];
Arrays of arbitrary objects can be constructed,
  • e.g. Thread myThreadList[] = new Thread[1024];
  • The only difference is that in the case of primitive types, the array elements are actually allocated. In the case of arbitrary objects, an array of object references is created; before you use array elements, you must call the constructor of that type for each element.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 42 Java Language -- More on Arrays

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 89.2 Full HTML Index
An array of length 128 is subscripted by integers from 0 to 127.
Subscripts are range checked in runtime and so vec[-1] and vec[128] will generate exceptions.
Array length can be extracted via the length instance variable, e.g.
  • int len = vec.length will assign len = 128.
Arrays can have dynamic sizing (a fixed size determined at runtime)
  • int sizeofarray = 67;
  • int vec[] = new int[sizeofarray];
Multidimensional arrays are arrays of arrays
  • char icon[][] = new char[16][16]
  • These arrays can be "ragged":
    • int graph[][] = new int[2][];
    • graph[0][] = new int[4];
    • graph[1][] = new int[7];

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 43 Java Language -- Expressions

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 90.7 Full HTML Index
Java's expressions are very similar to C and the following are valid:
2+3
(2+3)*i
i++ /* equivalent to i = i +1 */
(i > 0 ) && (j>0) /* Boolean */
i <<1 /* Left shift by 1 binary digit */
(i>0) ? true:false /* conditional expression */
i >>> 2 /* Signed right shift by 2 binary digits */
"fred" + "jim" is "fredjim"
/* + Equivalent to . in Perl */
(a instanceof B) /* True iff object a is of class B */

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 44 Java Language -- Control Flow I

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 72 Full HTML Index
if(some boolean expression) {..}
else if(another boolean) {..}
else {...}
while(any boolean) {/*DoStuff*/}
do {/*Whattodo*/} while(another boolean);
for(expression1; booleanexpression ; expression2) {...}
naturally starts with expression1, applies expression2 at end of each loop, and continues as long as booleanexpression true
switch (expression) { /* Just as in C */
case Constant1: /* Do following if expression=Constant1 */
/* Bunch of Stuff */
break;
case Constant2: /* Do following if expression=Constant2 */
/* Bunch of Stuff */
break; /* ....... */
default:
/* Bunch of Stuff */
break;
}

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 45 Java Language -- Control Flow II -- continue

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 44.6 Full HTML Index
One can break out of an iteration of a (nested) for loops in fashion offered by Perl but with a different syntax
outer: // label
for( int j=0; j<10; j++) { /* Note j only defined in for loop */
/* select course j */
  • for( int i=0; i<15; i++) {
  • if(studentgrade[j][i] == 4.0) {
    • /* Celebrate */
    • continue outer; // go to next iteration of outer loop
  • }
  • }
/* Continue jumps to here to next iteration of loop labelled with outer */
}

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 46 The Graphics class

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 66.2 Full HTML Index
An object of the graphics class represent a rectangular drawing grid, with a coordinate system in pixels.
When you draw objects, there is a current "state" consisting of a font and a color.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 47 Using Graphics properties

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 133.9 Full HTML Index
Fonts and colors are objects (sometimes called instances) of the font and color class in the awt package.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 48 Drawing simple shapes

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 84.9 Full HTML Index
Methods are available for drawing lines, rectangles, rounded rectangles, ovals, arcs, and polygons. This example draws a rectangle filled with green with a black border, and a circle filled with magenta.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 49 Passing parameters to an applet: the HTML

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 17.2 Full HTML Index
Within the applet tags, any number of param tags may occur. Attributes can control the alignment of the applet window on the html page.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 50 Passing parameters to an applet: the applet

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 54.7 Full HTML Index
A standard method, init(), is executed when your applet is loaded; it can call the method getParameter.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 51 Centering a string in the applet window.

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 18.7 Full HTML Index
The method applet.size() returns the width and height as a dimension object, which has width and height variables. FontMetrics has variables for various attributes of the font, including width and height.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 52 Applet Flow of Control

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * See also color IMAGE
Secs 67.6 Full HTML Index
Each applet's flow of control goes through a sequence of standard methods:
  • public void init() {...}
  • executed once when applet is downloaded to the browser.
  • public void start(){...}
  • executed each time the browser window is entered.
  • public void paint(){...}
  • executed whenever you want to draw in the window.
  • public void stop(){...}
  • executed each time the browser window in exited.
  • public void destroy(){...}
  • executed just before the applet exits.
There are also standard methods repaint (), which calls update(), which blanks out the old drawing and calls paint.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 53 Random color boxes example

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 90.7 Full HTML Index
This example fills the applet's drawing area with square boxes, each of which has a randomly chosen color.

HELP! * YELLOW=global GREY=local HTML version of GLOBAL Foils prepared 1 February 97

Foil 54 Arrays of random colors

From Jan 22 Delivered Lecture for Course CPS616 -- Java Lecture 1 -- Overview CPS616 spring 1997 -- Jan 22 1997. * Critical Information in IMAGE
Secs 61.9 Full HTML Index
This demonstrates 2-dimensional arrays by first filling arrays with random colors, and then drawing, uses a fixed size drawing window for simplicity.

Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Feb 16 1997