Comp2513 Java and Applets - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Comp2513 Java and Applets

Description:

... that no evil applets can be written and assist in the writing of good code ... Programs that come from over the network can be malicious (destroy data on your PC) ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 23
Provided by: ACA99
Category:
Tags: applets | comp2513 | java

less

Transcript and Presenter's Notes

Title: Comp2513 Java and Applets


1
Comp2513Java and Applets
  • Daniel L. Silver, Ph.D.

2
Objectives
  • To introduce the Java programming language and
    its fit with the Web
  • To discuss the use of Applets as a part of the
    E-Commerce infrastructure
  • References Chapter 3

3
Outline
  • Java an Object Oriented Programming language
  • Why Java and the Web?
  • Java Applets

4
Programming Languages
  • A programming language adheres to a specified
    syntax that is accepted by either an interpreter
    or a compiler.
  • What is the difference between an interpreter and
    a compiler?

5
Function-Oriented Programming
  • Traditional programming languages are known as
    function-oriented. Why?
  • Consider the movement of data from function to
    function
  • Data and processing are considered separately
  • What are some examples of function-oriented
    languages?
  • COBOL
  • Basic
  • Fortran
  • C
  • Prone to misuse of data and process
  • elements
  • Not supportive of encapsulation,
  • cohesion and loose coupling

6
Object-Oriented Programmng
  • Combines data and processes together into objects
  • An object is an entity that can contain data
    (attributes, properties) and can manipulate data
    using functions (methods)
  • An object has state and behaviour
  • What are some examples of OO lang.?
  • A simple example Hello_app.java

Attributes
Methods
7
Java An OOP Language
  • Java is a relatively new language
  • Green, 1991 Sun Microsystems dev. for use in
    consumer devices such as intelligent TV
    controllers
  • Object Oriented but simpler than C
  • Architecture neutral
  • Real-time remote applications
  • Portable, Reliable and Secure

8
Java and the Java Virtual Machine
program.java
program.class
Java Virtual Machine
Compiler
Operating System
Computer Hardware
9
Java Translation and Execution
Java source code
hello_app.java
Java bytecode
Java compiler
hello_app.class
javac
Bytecode compiler
Efficient because of bytecode
Java (JVM) Interpreter
java
Machine code
hello_app.exe
10
Java and the Web
  • In 1995 the first HotJava browser was demoed at
    SunWorld exhibition
  • It could download programs called applets from a
    the web and run them locally
  • Provided animation and interaction
  • Write once, run anywhere
  • By 1996 both Netscape and MS supported Java
    within their browsers

11
Java and the Web
  • Java has been designed for the Web
  • It has two attributes that make it suitable
  • Security An assortment of security features that
    guarantee that no evil applets can be written and
    assist in the writing of good code
  • Portability Applications and Applets can run on
    Windows, Unix, Linux, Mac, IBM mid-range and
    mainframe

12
Java Applet Security
  • Programs that come from over the network can be
    malicious (destroy data on your PC)
  • Java was designed to prevent malicious behaviour
  • Two primary safety features
  • Signatures an applet can be signed and a
    browser can be set up to accept only trusted
    applet authors
  • Secuirty Priviledges by default an applet runs
    in the sandbox where I/O is limited to the
    keyboard/mouse and the display, trusted applets
    can be give higher level priveledges (e.g. disk
    I/O )

13
Java and the Web
  • Reasons why Java has become the fastest growing
    programming language of all time
  • It is an object-oriented language
  • Contains a vast library of software (object
    classes and methods)
  • Java Development Kit (J2SE SDK)
  • Objects that have been developed and tested
  • Imported for use at the beginning of a program
  • A good first language to learn ... Why?

14
Java Applications vs Applets
  • There are two classes of Java programs
  • Applications - such as Hello_app.java
  • I/O is by default with console and character
    oriented
  • Graphical I/O is an option that is commonly taken
  • Applets as we shall see
  • Run by a Web browser using an imbedded Java
    interpreter
  • Graphical I/O characters, diagrams

15
Java Translation and Execution
Java source code
abc.java
Internet
Java compiler
HTTP Server App Server
abc.class
Java applet bytecode
Web Browser
Java (JVM) Interpreter
Server
Client
16
Java Applets
  • A Simple Example
  • HelloApplet.java / HelloApplet.html
  • Nothing is passed to the applet from the HTML
  • Anatomy of an Applet fundamental methods
  • init() invoked once when applet is first loaded
  • start() invoked each time applet becomes
    visible
  • stop() invoked each time applet becomes
    invisible
  • paint() display of text and graphics
  • destroy() invoked once when applet is exited

17
Java Applets
  • Parameter Passing Example
  • FirstApplet.java / FirstApplet.html
  • ltPARAMgt tag is used to pass parameters from HTML
    to Java program at run time
  • ltPARAMgt has two attributes
  • NAME - name of parameter being passed
  • VALUE value of parameter being passed
  • e.g.
  • ltPARAM NAME"message" VALUE"Message from HTML
    File"gt

18
Java Applets
  • The Graphics object class allows you to do many
    things
  • setColor()
  • fillRect()
  • drawLine()
  • drawRect()
  • drawOval()
  • drawImage()

19
Java Applets
  • Threads and Event Handling Example
  • AnimationApplet.java / AnimationApplet.html
  • Thread a portion of a Java program that
    executes independently, e.g.
  • Thread 1 - allows animation to occur on the
    browser window
  • Thread 2 captures input from the keyboard

20
Java Applets
  • Threads and Event Handling Example
  • Event Handling is used within programs to
    associate events such as mouse clicks to revelent
    portions of code
  • In AnimationApplet.java a mouseDown() event is
    used to start and stop the scrolling message

21
Java Applets
  • A more advanced example link.html
  • Provides sources of further information on Java
    and Applets
  • Notice how in link.java
  • ltparamgt is used in this example
  • showDocument(theURL,targetFrame) is used to link
    to a URL

22
THE ENDdanny.silver_at_acadiau.ca
Write a Comment
User Comments (0)
About PowerShow.com