What is Java?
-
A simple, object oriented, distributed, interpreted, robust, safe, architecture neutral, portable, high performance, multithreaded, dynamic language.
|
Java is interesting because
-
It is both a general purpose object-oriented language along the lines of C++
-
and it is particularly designed to interface with Web pages and to enable distributed applications over the internet.
|
The Web is becoming the dominant software development arena; this will drive Java as the best supported, most widely taught language
-
Particularly good as a language for K-12 teaching
-
Even outside the web, e.g. in scientific computing, Java is as good and in some (modest) respects better than all other languages
|
The Java Language has several good design features
-
secure, safe (wrt bugs), object-oriented, familiar (to C C++ and even Fortran programmers)
|
Java has a very good set of libraries covering everything from commerce, multimedia, images to math functions (under development at http://math.nist.gov/javanumerics)
|
Java has best available electronic and paper training and support resources, growing labor force trained in Java
|
Java is rapidly getting best integrated program development environments
|
Java naturally integrated with network and universal machine supports powerful "write once-run anywhere" model
|
Increasingly, Java is the language used for important computing paradigms that support applications: object-oriented computing, event-driven computing, distributed objects, linkage to databases, visual/component computing, client/servers, networking, multimedia computing . . .
|
So Java is an important language to include at an advanced computer science level, along with other languages such as C++, that are useful to students to get jobs.
|
But the good design features of Java also make it suitable for teaching basic computer science concepts: algorithms, data structures, software design, . . .
|
Since Java is object-oriented, programs are organized into modules called classes, which may have data in variables and subroutines called methods.
|
class HelloWorld
|
{ public static void main (String[] args)
|
{ System.out.println("Hello World!");
|
}
|
}
|
Each program is enclosed in a class definition.
|
main() is the first method that is run.
|
The notation class.method or package.class.method is how to refer to a public method (with some exceptions).
|
Syntax is similar to C - braces for blocks, semicolon after each statement. One difference: upper and lower case matter!
|
Java applets are part of the class hierarchy that can call methods to display on a screen (within the browser window). One way to draw on the screen is to call the method drawString from the standard method paint.
|
import java.awt.Graphics;
|
public class HelloApplet extends java.applet.Applet
|
{ public void paint (Graphics g)
|
{ g.drawString("Hello World!", 5, 25);
|
}
|
}
|
The import statement (similar to an include) allows the use of methods from the Graphics class .
|
The paint method displays a graphics object on the screen - one of the standard methods that takes the place of main for applets.
|
Puts this as a subclass of Applet.
|
<APPLET CODE="StockGraph.class" 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.
|
Despite the word "java" in the name, JavaScript is a different language than Java, albeit with some similarities.
|
A JavaScript program is written directly into the HTML page, and is executed by the JavaScript intrepeter, so also executes dynamic web page content in the browser window.
|
JavaScript is special purpose - it is an object-based language that deals directly with browser entities such as windows, textfields, forms, frames and documents.
|
JavaScript can respond to browser events (not as many as Java's more complex capabilities with the user interface) such as mouse clicks and user-typed text.
|
JavaScript is easy and fast to write, but not as powerful as Java.
|
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.
|
An experimental web browser written in Java, called WebRunner and later renamed as HotJava, ready in 1994.
|
Alpha release of Java and browser HotJava 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. Java goes into open standards process and is adopted by Web community.
|
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++.
|
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.
|
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.
|
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.
|
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
|
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.
|
A substantial new version of Java released March 97 by JavaSoft.
|
This release includes many developments both by Sun and by partner companies such as IBM. There are minimal changes to the language - primarily development of new classes to support enterprise computing.
|
Netscape4.0 and Internet Explorer 4.0 do support JDK 1.1, on some platforms you must explicitly download the "AWT" version to get all of 1.1 support.
|
Features: better event model in the AWT, Java Database Connectivity (JDBC), Remote Method Interface (RMI), internationalization, security certificates and encryption, and JavaBeans.
|
http://www.javasoft.com/products/jdk/1.1
|