CIS 5930-04 - Spring 2001 Part 2: Overview of Java - PowerPoint PPT Presentation

Loading...

PPT – CIS 5930-04 - Spring 2001 Part 2: Overview of Java PowerPoint presentation | free to download - id: 5fe2bd-MWRiY



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

CIS 5930-04 - Spring 2001 Part 2: Overview of Java

Description:

... html Architecture of Java Applications Java applications are compiled and run on a machine just like any ... Java Applications in a Nutshell Java programs ... – PowerPoint PPT presentation

Number of Views:194
Avg rating:3.0/5.0
Slides: 37
Provided by: NeilJ8
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: CIS 5930-04 - Spring 2001 Part 2: Overview of Java


1
CIS 5930-04 - Spring 2001 Part 2 Overview of
Java
  • http//aspen.csit.fsu.edu/it1spring01/
  • Instructors Geoffrey Fox, Bryan Carpenter
  • Computational Science and Information Technology
  • Florida State University
  • Acknowledgements Nancy McCracken
  • Syracuse University

2
Plan of Java Tutorial
  • Part 1
  • Overview including History of Java Development
  • Overall Java Philosophy and Features including
    security etc.
  • Part 2
  • Java Programming Language
  • Object Oriented and Class Structure
  • Exceptions

3
What is Java, in a Nutshell?
  • What is Java?
  • A simple, object oriented, distributed,
    interpreted, robust, safe, architecture neutral,
    portable, high performance, multithreaded,
    dynamic, programming 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 respects
    better than other languages.

4
Java is an important language in the World
  • The Java language has several good design
    features
  • secure, safe (w.r.t. 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 (see http//math.nist.gov/javanumer
    ics)
  • 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.

5
Java is also important in computer science
  • 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 like C that help 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, . . .
  • See the (old, but still relevant) discussion by
    Doug Lea at http//gee.cs.oswego.edu/dl/html/javaI
    nCS.html

6
Architecture of Java Applications
  • Java applications are compiled and run on a
    machine just like any other general programming
    language such as C/C. No web server or network
    are required although Java applications may also
    use network connections for distributed computing.

Java code is compiled to produce native
code run directly on machine for
better performance
Java code is compiled to produce byte
code run by Java interpreter to produce results
7
Java Applications in a Nutshell
  • Java programs written in a file with extension
    .java.
  • Applications are .java files with a main()
    method. This is called by the Java system.
  • Compile and run a Java application (using
    bytecodes)
  • Run the compiler on a .java file
  • javac MyProgram.java
  • producing a file of Java byte code,
    MyProgram.class
  • Run the interpreter on a .class file
  • java MyProgram
  • which executes the byte code
  • The tools javac and java are part of JDK.

8
The Simplest Java Application Hello,World!
  • Since Java is object-oriented, programs are
    organized into modules called classes, which may
    have data in variables called fields, and
    subroutines called methods.

Each program is enclosed in a class definition.
main() is the first method that is run.
class HelloWorld public static void main
(String args) System.out.println(Hello
World!)
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.
9
Java Applets
  • Java applets are classes written in Java that are
    not intended to run as stand-alone programs (like
    applications) but as subprograms of a browser
    that is already managing a window.
  • Applets are not trusted by default, so they have
    several restrictions in running on the client
    machine
  • Applets should NOT have a main() method. Instead
    they have init(), start(), paint(), etc. for
    displaying on the browser window
  • no printing or file I/O
  • cannot connect through the network to any machine
    but its own server
  • any new windows created by the applet have a
    warning label

10
Architecture of Java Applets
  • Browsers (HotJava, Netscape 2.0/3.0/4.0,
    Microsoft IE ...) 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.

web server
web client, running browser such as Netscape or IE
Java code is compiled to produce applet
codes, part of web document collection
Internet
executes (restricted) applet code to display in
browser window
11
The Simplest Java Applet Hello, World!
  • Java applets can call methods to display on a
    screen (within the browser window). One way is
    to call the method drawString() from the standard
    method paint().

The import statement (similar to an include)
allows the use of methods from the Graphics class
.
import java.awt.Graphics public class
HelloApplet extends java.applet.Applet
public void paint (Graphics g)
g.drawString(Hello World!, 5, 25)
Makes this a subclass of Applet.
The paint() method displays a graphics object on
the screen - one of the standard methods that
takes the place of main() for applets.
12
Displaying your applet from a Web page.
  • Name the file HelloWorldApplet.java. Run the
    compiler, javac, to get a byte code file
    HelloWorldApplet.class. Put this in a web
    directory.

lthtmlgtltheadgt lttitlegtSimple Hello
Pagelt/titlegt lt/headgt ltbodygt My Java applet
says ltapplet codeHelloWorldApplet.class
width150 height25gt lt/appletgt lt/bodygtlt/htmlgt
Name of your applet class.
The browser will use a rectangle of width 150
pixels and height 25 pixels to display the applet
within the other html.
13
Java vs. JavaScript
  • Despite the name, JavaScript is a different
    language from Java, albeit with some
    similarities.
  • A JavaScript program is written directly in the
    HTML page, and executed by the JavaScript
    interpreter, so also allows dynamic web page
    content in the browser window.
  • JavaScript is special purpose - it is an
    object-based language that deals directly with
    browser entities like windows, text fields,
    forms, frames and documents.
  • JavaScript can respond to browser events like
    mouse clicks and user-typed text.
  • JavaScript is fast to write, but not as powerful
    as Java.

14
Multi-tier Architecture
  • Distributed applications on the web naturally
    have a multi-tier architecture.
  • Java plays a role at all three levels
  • Graphical User Interface and client side analysis
    systems, including visualization
  • Middle layer servers and software integration,
    including web servers, distributed object servers
    and other application servers.
  • Less important for back end client software,
    which may be legacy code.

Internet
Client user interface running through browser
Internet or proprietary network
Middle level servers
Backend computing or databases
15
Overview and History of Java Development
16
History of Java Language and Team
  • Starts in 1991 as Project Greensemi-autonomous
    task force in Sun focusing on operating software
    for consumer electronic devices, e.g. smart
    set-top boxes.
  • Gosling (creator of Sun NeWS) considers C too
    complex and initiates development of Oak, later
    renamed to Java. Similarities to UCSD P-system.
  • A PDA (Personal Digital Assistant), codename
    7, based on Oak/Java ready in 1993. Green
    Team becomes FirstPerson, Inc.
  • 7 proposal to Time-Warner rejected in 1993. 3DO
    deal falls through in 1994. FirstPerson, Inc.
    dissolves.
  • Small group (30 people, now the Java Team)
    continues and decides to adapt Oak as a Web
    technology.

17
History of Java Language and Team to Dec. 95
  • Experimental Web browser written in Java, called
    WebRunner, later renamed HotJava, ready in 1994.
  • Alpha release of Java and HotJava April '95.
  • Netscape licences Java in May '95 and builds Java
    into Netscape 2.0
  • Beta Java Development Kit (JDK) and first Java
    books Summer/Fall '95.
  • Dec 4, 1995 Business Week cover story "Software
    RevolutionThe Web Changes Everything" presents
    Java as a breakthrough force in the expanding
    Web/Internet.
  • In next week, SGI, IBM, Adobe, Macromedia and
    finally Microsoft adopt/license Java. Java is
    adopted by Web community.

18
More Recent Java History
  • 1996 JavaOne Developers Conference (now held
    annually in June) focused on applets. Attendance
    of 5000 people.
  • 1997 JavaOne focused on JavaBeans and new version
    of the language JDK1.1, both designed to put Java
    in line with other developments in component and
    secure distributed web object computing and use
    of databases.
  • 1998 JavaOne featured attendance of 14,000 and
    focused on Enterprise JavaBeans and other
    Enterprise classes, developing more on
    server-side applications.
  • 1999 JavaOne had over 20,000 attendees.
    Continued development of Jini for dynamic
    networking, embedded devices such as Palm Pilots.

19
Overall Java Philosophy and Features
20
Some Key Java Features
  • First we discuss original Java base language
    features as discussed in Java A White Paper by
    Sun MicrosystemsOctober 1995 draft by James
    Gosling and Henry McGiltonenumerates the
    original design goals of Java

Object-oriented Architecture-neutral Portable Somewhat Interpreted Simple and Familiar Distributed Robust Secure High performance Multi Threaded Dynamic
  • Finally we mention additional features added to
    Java in more recent versions.

21
Java FeaturesIt's Simple and Familiar
  • Familiar as it looks like C, but simpler to
    program.
  • omits several confusing features of C including
    operator overloading, multiple inheritance,
    pointers and automatic type coercions
  • Adds automatic garbage collection to make dynamic
    memory management much easier than in C or C.
  • No more frees or deletes. No more memory leaks.
  • Adds Interface construct, similar to Objective C
    concept, to compensate for the lack of multiple
    inheritance.
  • Small kernel is suitable for Java ports to
    consumer electronic devices.

22
Java FeaturesIt's Object-oriented
  • Java model is sometimes viewed as a C subset,
    with some elements imported from other languages.
  • This is arguable. In many ways Java and C are
    very different, and many of the similarities that
    do exist are at a fairly superficial syntactic
    level.
  • Structures, Unions and Functions are absorbed
    into data and methods of Java classesJava is
    simple.
  • The strength of Java object-oriented model is in
    simplicity and the extensive class library
    associated with the system.

23
Java FeaturesIt's Architecture-Neutral
  • C/C programming in a heterogeneous network
    environment demands compatibility across several
    vendor platforms and their compilers.
  • Solved in Java by designing platform-independent
    binary representation called Java
    bytecodecomparable to P-code in UCSD Pascal.
  • Java compiler reads Java source and generates
    Java bytecode, which is shipped to usere.g. on
    browser request, Jini lookup, etc.
  • Each client must have a Java Virtual Machine
    program, which interprets (runs) Java
    bytecodes.

24
Java FeaturesIt's Portable
  • Java Virtual Machine model is identical for all
    platforms.
  • Sun owns the Java Virtual Machine
    specificationwhile classes can be added by any
    user, JVM is Universal.
  • In C/C various integer types match the
    architecture of machine at hand. Java byte,
    char, short, int and long are always 8, 16
    (unicode), 16, 32 and 64 bits, respectively.
  • No header files, preprocessors, define etc.
  • floating point is always IEEE 754

25
Java FeaturesIt's Somewhat Interpreted
  • Java represents a compromise between fully
    compiled (e.g. C/C) and fully interpreted (e.g.
    typical scripting languages) models.
  • Java compiler produces a binary bytecode output
    which is portable and typically 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 interpreterthe JVMexecutes this bytecode.

26
Java FeaturesIt's Robust
  • Java enforces compile-time type checking and this
    eliminates some error prone constructs of C/C.
  • Pointer arithmetic is eliminated which allows
    for, e.g., runtime checking of array subscripts,
    and enforces security of the Java model.
  • Explicit declarations are always required
    argument types of methods are always checked
    (unlike C). This allows the Java complier to
    perform early error detection.

27
Java FeaturesIt's (Hopefully) Secure
  • Java bytecodes may be shipped across the network
    and executed on client machines. Security is
    therefore a critical issue and strongly enforced
    in Java.
  • The bytecodes sent across network are verified at
    the client which prevents evil/corrupted classes
    from causing problems

28
Java FeaturesHigh Performance
  • Early Java interpreters performed on-the-fly
    execution of the Java bytecodes, which gave
    moderate performance.
  • Initial software was often 100 times slower than
    C
  • Performance is improved in newer just-in-time
    JVMs, which compile methods after some number of
    executions, and save machine code to give
    compiled-code efficiency thereafter.
  • Support for generating native machine code out of
    Java bytecodes also exists (e.g. TowerJ).
  • The performance of the machine code, generated
    from Java bytecodes, may eventually be comparable
    to that offered by typical C/C compilers on the
    same platform.

29
Java FeaturesIt's Multithreaded
  • Java model offers multithreading, implemented in
    terms of the Thread class.
  • Thread methods offer a set of synchronization
    primitives based on monitor and condition
    variable paradigm of C.A.R. Hoare.
  • One use of Java multithreading in applet
    programming, for example, is having several
    independent but related simulations running
    concurrently in an applet window. Multithreading
    is also used internally by the browser to handle
    multiple document dynamics.

30
Java FeaturesIt's Dynamic
  • Java model is more dynamic than C, closer to
    Smalltalk or Perl.
  • Classes (often) dont need to to be recompiled
    after implementation of a superclass (or other
    used class) is updatedbinary compatibility.
  • Classes have runtime representation (available
    through the Class class) that allows one, e.g.,
    to discover and execute methods of a given object
    at runtime
  • In C, cant even distinguish at run-time whether
    a given pointer references, say, an integer or a
    browser!

31
Sun's Comparison of Language Features
  • Good Fair
    Poor

Java Smalltalk
TCL Perl Shells C
C Performance Simple Object-Oriented Robust Secu
re Interpreted Dynamic Portable Neutral Threads Ga
rbageCollection Exceptions
32
The Java 2 Platform
  • Sun are now offering 3 editions
  • Java 2 platform, Standard Edition (J2SE)
  • Develops earlier JDKs
  • Available in V 1.3.
  • Java 2 platform, Enterprise Edition (J2EE)
  • Incorporates multiple technologies for
    server-side and multi-tier applications.
  • Java 2 platform, Micro Edition (J2ME)
  • Optimized run-time environment for consumer
    products.

33
Java BooksI
  • Core Java, by Gary Cornell and Cay S. Horstmann,
    offers detailed coverage of the whole language
    and packages for advanced programmers, including
    the Swing Set. Also Volume 2 gives good coverage
    of advanced topics such as JDBC, RMI, JavaBeans
    and security.
  • 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
    and also has companion teaching multimedia books.
    The third edition has Swing Set and also the
    advanced APIs.

34
Java BooksII
  • The Java Programming Language, by Ken Arnold and
    James Gosling, David Holmes, 3rd Edition,
    Addison-Wesley, 2000, is the classic on the
    language basics for intermediate and advanced
    programmers. It covers threads and I/O packages,
    but not applets or windowing packages.
  • Java in a Nutshell, by David Flanagan, is the
    language reference book in the familiar O'Reilly
    series. One of the better references. Also Java
    Examples in a Nutshell.

35
Java Development Environments
  • These range from simple tools that give a
    windowing interface to the edit/compile/run or
    view cycle, e.g. JavaEdit from Dick Chase, on
    PCs, . . .
  • . . . to the elaborate commercial development
    environments that can also track projects and
    help generate code for user interface components
  • Microsoft Visual J
  • Symantec Visual Café
  • Java Workshop from Sun
  • Borland Jbuilder
  • Kawa from Tek-Tools

36
Resources for the Java Programming Language
  • The Java Language Specification, second edition.
    James Gosling, Bill Joy, Guy Steele, Gilad
    Bracha, April 2000. The ultimate reference for
    hardened computer scientists/compiler writers.
  • http//www.javasoft.com web site has plenty of
    references including
  • Tutorial
  • http//www.javasoft.com/books/Series/Tutorial/inde
    x.html
  • Books
  • http//www.javasoft.com/java.sun.com/aboutJavaSoft
    /book-news.html
  • Collection of Applets
  • http//www.gamelan.com
About PowerShow.com