1 / 22

Comp2513 Java and Applets

Comp2513 Java and Applets. Daniel L. Silver, Ph.D. 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. Outline. Java an Object Oriented Programming language

jesse
Télécharger la présentation

Comp2513 Java and Applets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 Daniel L. Silver

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

  4. Basic code C code Interpreter Compiler *.exe Operating System Computer Hardware 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? Daniel L. Silver

  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 Daniel L. Silver

  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 Daniel L. Silver

  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 Daniel L. Silver

  8. Java and the Java Virtual Machine program.java program.class Java Virtual Machine Compiler Operating System Computer Hardware Daniel L. Silver

  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 Daniel L. Silver

  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 Daniel L. Silver

  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 Daniel L. Silver

  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 ) Daniel L. Silver

  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? Daniel L. Silver

  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 Daniel L. Silver

  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 Daniel L. Silver

  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 Daniel L. Silver

  17. Java Applets Parameter Passing Example: • FirstApplet.java / FirstApplet.html … • <PARAM> tag is used to pass parameters from HTML to Java program at run time • <PARAM> has two attributes: • NAME - name of parameter being passed • VALUE – value of parameter being passed • e.g.: <PARAM NAME="message" VALUE="Message from HTML File"> Daniel L. Silver

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

  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 Daniel L. Silver

  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 Daniel L. Silver

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

  22. THE ENDdanny.silver@acadiau.ca

More Related