Presentation is loading. Please wait.

Presentation is loading. Please wait.

Comp2513 Java and Applets Daniel L. Silver, Ph.D..

Similar presentations


Presentation on theme: "Comp2513 Java and Applets Daniel L. Silver, Ph.D.."— Presentation transcript:

1 Comp2513 Java and Applets Daniel L. Silver, Ph.D.

2 2001Daniel L. Silver2 Objectives To introduce the Java programming language and its fit with the Web 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 To discuss the use of Applets as a part of the E-Commerce infrastructure References: Chapter 3 References: Chapter 3

3 2001Daniel L. Silver3 Outline Java an Object Oriented Programming language Java an Object Oriented Programming language Why Java and the Web? Why Java and the Web? Java Applets Java Applets

4 2001Daniel L. Silver4 Programming Languages A programming language adheres to a specified syntax that is accepted by either an interpreter or a compiler. 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? What is the difference between an interpreter and a compiler? Basic code InterpreterCompiler C code Operating System Computer Hardware *.exe

5 2001Daniel L. Silver5 Function-Oriented Programming Traditional programming languages are known as function-oriented. Why? 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? What are some examples of function-oriented languages? –COBOL –Basic –Fortran –C–C–C–C Prone to misuse of data and process elements Not supportive of encapsulation, cohesion and loose coupling

6 2001Daniel L. Silver6 Object-Oriented Programmng Combines data and processes together into objects 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 is an entity that can contain data (attributes, properties) and can manipulate data using functions (methods) An object has state and behaviour An object has state and behaviour What are some examples of OO lang.? What are some examples of OO lang.? A simple example … Hello_app.java A simple example … Hello_app.java Attributes Methods

7 2001Daniel L. Silver7 Java: An OOP Language Java is a relatively new language Java is a relatively new language “Green”, 1991 Sun Microsystems – dev. for use in consumer devices such as intelligent TV controllers “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 2001Daniel L. Silver8 Java and the Java Virtual Machine program.class Java Virtual MachineCompiler program.java Operating System Computer Hardware

9 2001Daniel L. Silver9 Java Translation and Execution Java source code Java compiler Java (JVM) Interpreter Bytecode compiler Java bytecode Machine code hello_app.java hello_app.class hello_app.exe Efficient because of bytecode javac java

10 2001Daniel L. Silver10 Java and the Web In 1995 the first HotJava browser was demoed at SunWorld exhibition 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 It could download programs called applets from a the web and run them locally Provided animation and interaction Provided animation and interaction “Write once, run anywhere” “Write once, run anywhere” By 1996 both Netscape and MS supported Java within their browsers By 1996 both Netscape and MS supported Java within their browsers

11 2001Daniel L. Silver11 Java and the Web Java has been designed for the Web Java has been designed for the Web It has two attributes that make it suitable: 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 2001Daniel L. Silver12 Java Applet Security Programs that come from over the network can be malicious (destroy data on your PC) Programs that come from over the network can be malicious (destroy data on your PC) Java was designed to prevent malicious behaviour Java was designed to prevent malicious behaviour Two primary safety features: 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 2001Daniel L. Silver13 Java and the Web Reasons why Java has become the fastest growing programming language of all time: 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 2001Daniel L. Silver14 Java Applications vs Applets There are two classes of Java programs: Applications - such as Hello_app.java 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 Applets – as we shall see –Run by a Web browser using an imbedded Java interpreter –Graphical I/O – characters, diagrams

15 2001Daniel L. Silver15 Java Translation and Execution Java source code Java compiler Java applet bytecode Interne t Java (JVM) Interpreter Web Browser Client Server abc.java abc.class HTTP Server App Server

16 2001Daniel L. Silver16 Java Applets A Simple Example: HelloApplet.java / HelloApplet.html … HelloApplet.java / HelloApplet.html … HelloApplet.javaHelloApplet.html HelloApplet.javaHelloApplet.html Nothing is passed to the applet from the HTML Nothing is passed to the applet from the HTML Anatomy of an Applet – fundamental methods: 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 2001Daniel L. Silver17 Java Applets Parameter Passing Example: FirstApplet.java / FirstApplet.html … FirstApplet.java / FirstApplet.html … FirstApplet.javaFirstApplet.html FirstApplet.javaFirstApplet.html tag is used to pass parameters from HTML to Java program at run time tag is used to pass parameters from HTML to Java program at run time has two attributes: has two attributes: –NAME - name of parameter being passed –VALUE – value of parameter being passed -e.g.:

18 2001Daniel L. Silver18 Java Applets The Graphics object class allows you to do many things: The Graphics object class allows you to do many things: –setColor() –fillRect() –drawLine() –drawRect() –drawOval() –drawImage()

19 2001Daniel L. Silver19 Java Applets Threads and Event Handling Example: AnimationApplet.java / AnimationApplet.html … AnimationApplet.java / AnimationApplet.html … AnimationApplet.java AnimationApplet.html AnimationApplet.java AnimationApplet.html Thread – a portion of a Java program that executes independently, e.g.: 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 2001Daniel L. Silver20 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 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 In AnimationApplet.java a mouseDown() event is used to start and stop the scrolling message

21 2001Daniel L. Silver21 Java Applets A more advanced example – link.html A more advanced example – link.htmllink.html –Provides sources of further information on Java and Applets Notice how in link.java: Notice how in link.java:link.java – is used in this example –showDocument(theURL,targetFrame) is used to link to a URL

22 THE END danny.silver@acadiau.ca


Download ppt "Comp2513 Java and Applets Daniel L. Silver, Ph.D.."

Similar presentations


Ads by Google