Java applets. SwIG Jing He



Similar documents
CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

CSC 551: Web Programming. Spring 2004

SE 450 Object-Oriented Software Development. Requirements. Topics. Textbooks. Prerequisite: CSC 416

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

A Short Introduction to Writing Java Code. Zoltán Majó

1. Overview of the Java Language

Chapter 1 Java Program Design and Development

How to use the Eclipse IDE for Java Application Development

An Overview of Java. overview-1

How To Use A Sas Server On A Java Computer Or A Java.Net Computer (Sas) On A Microsoft Microsoft Server (Sasa) On An Ipo (Sauge) Or A Microsas (Sask

Installing Java. Table of contents

Java CPD (I) Frans Coenen Department of Computer Science

1001ICT Introduction To Programming Lecture Notes

CS 209 Programming in Java #1

9/11/15. What is Programming? CSCI 209: Software Development. Discussion: What Is Good Software? Characteristics of Good Software?

2 Introduction to Java. Introduction to Programming 1 1

The Basic Java Applet and JApplet

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Chapter 1 Programming Languages for Web Applications

Installing Java (Windows) and Writing your First Program

Applets, RMI, JDBC Exam Review

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

INTRODUCTION TO JAVA PROGRAMMING LANGUAGE

Java with Eclipse: Setup & Getting Started

There are some important differences between an applet and a standalone Java application, including the following:

Essentials of the Java(TM) Programming Language, Part 1

Java in Education. Choosing appropriate tool for creating multimedia is the first step in multimedia design

Introduction to Java Applets (Deitel chapter 3)

How To Write A Program For The Web In Java (Java)

Here's the code for our first Applet which will display 'I love Java' as a message in a Web page

Java Programming. Binnur Kurt Istanbul Technical University Computer Engineering Department. Java Programming. Version 0.0.

Essentials of the Java Programming Language

Java History. Java History (cont'd)

Syllabus for CS 134 Java Programming

Interactive Programs and Graphics in Java

Java Crash Course Part I

C# and Other Languages

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Mobile Application Languages XML, Java, J2ME and JavaCard Lesson 04 Java

WEEK 2 DAY 14. Writing Java Applets and Java Web Start Applications

Data Structures Lecture 1

Java SE 6 Update 10. la piattaforma Java per le RIA. Corrado De Bari. Sun Microsystems Italia Spa. Software & Java Ambassador

Crash Course in Java

Fundamentals of Java Programming

Creating a Java application using Perfect Developer and the Java Develo...

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Tutorial: Getting Started

02 B The Java Virtual Machine

Appendix A Using the Java Compiler

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Session 12 Evolving IT Architectures: From Mainframes to Client-Server to Network Computing

HOW TO CONFIGURE PASS-THRU PROXY FOR ORACLE APPLICATIONS

Hypercosm. Studio.

Real-time Device Monitoring Using AWS

Java is commonly used for deploying applications across a network. Compiled Java code

What Perl Programmers Should Know About Java

JAVA WEB START OVERVIEW

Lesson 06: Basics of Software Development (W02D2

Serving tn5250j in Web Documents from the HTTP Server for iseries

Enterprise Java. Where, How, When (and When Not) to Apply Java in Client/Server Business Environments. Jeffrey Savit Sean Wilcox Bhuvana Jayaraman

Packaging and Deploying Java Projects in Forte

CS506 Web Design and Development Solved Online Quiz No. 01

Introduction to Java Programming. Kary Främling

Overview. Java Programming Language. What is Java in a NutShell? Architecture of Java Applets

Software. Programming Language. Software. Instructor Özgür ZEYDAN. Bülent Ecevit University Department of Environmental Engineering

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

Tutorial 5: Developing Java applications

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Java Programming Unit 1. Your first Java Program Eclipse IDE

WHAT ARE PACKAGES? A package is a collection of related classes. This is similar to the notion that a class is a collection of related methods.

An Overview of Oracle Forms Server Architecture. An Oracle Technical White Paper April 2000

Chapter 1. Introduction to Computers, Programs, and Java

LAB4 Making Classes and Objects

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

JavaFX Session Agenda

System Requirements - Table of Contents

CS 170 Java Programming 1. Welcome to CS 170. All about CS 170 The CS 170 Online Materials Java Mechanics: Your First Program

Creating Java EE Applications and Servlets with IntelliJ IDEA

Tutorial Reference Manual. Java WireFusion 4.1

The Context of Software Development

understand how image maps can enhance a design and make a site more interactive know how to create an image map easily with Dreamweaver

Object-Oriented Programming and Data Structures

NetBeans IDE Field Guide

Habanero Extreme Scale Software Research Project

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.

Glassfish, JAVA EE, Servlets, JSP, EJB

For Introduction to Java Programming, 5E By Y. Daniel Liang

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

Chapter 27 Hypertext Transfer Protocol

Transcription:

Java applets SwIG Jing He

Outline What is Java? Java Applications Java Applets Java Applets Securities Summary

What is Java? Java was conceived by James Gosling at Sun Microsystems Inc. in 1991 Java is platform independent language Java programming is a/an object-oriented programming.

Object oriented language The world around us consists of objects. e.g. the ATM

Object oriented language The world around us consists of objects. Let the program consist of objects.

Object oriented language The program consist of objects. Objects of the same kind form a class. E.g. class ATM or class Money.

Object oriented language The program consist of objects. Objects of the same kind form a class. Each object has some methods. Money withdrawmoney(atmcard card,int amount) (Objects in the same class have the same methods.)

Object oriented language A method of the ATM class: parameters Money withdrawmoney(atmcard card,int amount) type of return value type of the parameter name of the parameter mypurse.addmoney(theatm. withdrawmoney(myatmcard,1000));

Object oriented language more ideas borrowed from the real world: encapsulation you do not need to know how the ATM works inside. inheritance you can easily create class ATMWithClocks extending class ATM. The new class inherits the methods of the ATM class.

Java Architecture source code Compiler JVM byte code Computer programmer user

Java Architecure portability security source code JVM Compiler byte code Computer programmer user speed

Why Java? simple portable secure free slow

So What s Java Good For? Web applications! Java Applet Java Applet Server

Learning Java language libraries book, lectures documentation http://java.sun.com/docs/ examples on the web (problem often old version of Java)

How are Java Applications written? HelloWorld.java: public class HelloWorld { } public static void main (String[] args) { } Compile HelloWorld.java Run System.out.println( Hello, World ); javac HelloWorld.java Output: HelloWorld.class java HelloWorld Output: Hello, World 15

Building JAVA Application Prepare the file HelloWorld.java using an editor Invoke the compiler: javac HelloWorld.java This creates HelloWorld.class Run the java interpreter: java HelloWorld

What is an applet?

PIGLET PIG

APPLE APPLET

What is an applet? An applet is a small Java program that is embedded and ran in some other Java interpreter program such as a Java technology-enabled browser Sun s applet viewer program called appletviewer

Applet TCP/IP (socket) Netscape(JVM) Loads HTML file Loads Java Applet TCP/IP (HTTP) Internet Client TCP/IP (HTTP) TCP/IP (socket) Server HTML files(applet Tags) Applets Web Server

Applets, web page, client, server server host web server reqeust for mywebpage.html browser host browser mywebpage.html... <applet code=helloworld.class</applet>... HelloWorld.class mywebpage.html request for HelloWorldclass HelloWorld.class HelloWorld.class

Applet Execution - 1 An applet program is a written as a inheritance of the java.applet class There is no main() method in an Applet. An applet uses AWT for graphics

Applet Execution - 2 Life Cycle of an Applet: init: This method is intended for whatever initialization is needed for an applet. start: This method is automatically called after init method. It is also called whenever user returns to the page containing the applet after visiting other pages. stop: This method is automatically called whenever the user moves away from the page containing applets. This method can be used to stop an animation. destroy: This method is only called when the browser shuts down normally. Ref: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html/

Applet Execution - 3 The applet is running and rendered on the web page. Every Applet needs to implement one or more of the init(), the start( ) and the paint( ) methods. At the end of the execution, the stop( ) method is invoked, followed by the destroy( ) method to deallocate the applet s resources.

Applet life cycle browser visits page containing an applet browser calls init on that applet, once browser calls start on that applet browser goes away from that page browser calls stop on that applet browser comes back to that page browser calls start again on that applet browser shuts down browser calls destroy on the applet, once init() start() do some work stop() destroy()

HTML tags for applets - 1 <APPLET // the beginning of the HTML applet code CODE="demoxx.class" // the actual name of the applet (usually a 'class' file) CODEBASE="demos/" // the location of the applet (relative as here, or a full URL) NAME= SWE622" // the name of the instance of the applet on this page WIDTH="100" // the physical width of the applet on the page HEIGHT="50" // the physical height of the applet on the page ALIGN="Top" // align the applet within its page space (top, bottom, center)

HTML tags for applets - 2 <APPLET CODE= test.class" CODEBASE="example/" WIDTH=460 HEIGHT=160 NAME="buddy" > <PARAM NAME="imageSource" VALUE="images/Beans"> <PARAM NAME="backgroundColor" VALUE="0xc0c0c0"> <PARAM NAME="endImage" VALUE=10> </APPLET>

Applet's Attributes Attribute Explanation Example Code Name of class file Code= applet0.class Width Width of applet Width=300 height Height of applet Height=60 Codebase Applet s Directory Codebase= /applets alt Alternate text if applet not available Alt= menu applet name Name of the applet Name= appletexam Align(top,left,right,bottom) Justify the applet with text Align= right

HTML <html> <head> <title> Hello World Applet </title> </head> <body> <applet code="helloworld.class width=300 height=200> </applet> </body> </html>

Your Turn! You first applet Hello World

History of an Applet Edit java source code & html notepad Hello.java notepad Hello.html Compile source to ByteCodes javac Hello.java produces Hello.class View applet (Java Virtual Machine) appletviewer Hello.html browser Hello.html

<html> <body> <applet code= Hello.class width=300 height=300> </applet> </body> </html>

<html> <body> <applet code= Hello.class width=300 height=300> </applet> </body> </html> Save as Hello.html

import java.applet.applet; import java.awt.*; public class Hello extends Applet { public void init() { repaint(); } public void paint(graphics g) { g.drawstring( Hello World!,30,30); } } what to draw Save as Hello.java where to draw it

History of an Applet Edit java source code & html notepad Hello.java notepad Hello.html Compile source to ByteCodes javac Hello.java produces Hello.class View applet (Java Virtual Machine) appletviewer Hello.html browser Hello.html

History of an Applet Edit java source code & html notepad Hello.java notepad Hello.html Compile source to ByteCodes javac Hello.java produces Hello.class View applet (Java Virtual Machine) appletviewer Hello.html browser Hello.html

The coordinate system The applet is drawn in a rectangle, which consists of pixels. width

The coordinate system Each pixel has a coordinate (x,y) (0,0) (width,0) x

Sample Graphics methods A Graphics is something you can paint on g.drawstring( Hello, 20, 20); Hello g.drawrect(x, y, width, height); g.fillrect(x, y, width, height); g.drawoval(x, y, width, height); g.filloval(x, y, width, height); g.setcolor(color.red);

Applet Security For security reasons, applets that are loaded over the network have several restrictions. an applet cannot ordinarily read or write files on the computer that it's executing on. an applet cannot make network connections except to the host that it came from. Ref: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html/

What are the disadvantages of applets? Applets can t run any local executable programs Applets can t with any host other than the originating server Applets can t read/write to local computer s file system

What are the disadvantages of applets? (Cont d) Applets can t find any information about the local computer All java-created pop-up windows carry a warning message Stability depends on stability of the client s web server Performance directly depend on client s machine

What are the advantages of applets? Automatically integrated with HTML; hence, resolved virtually all installation issues. Can be accessed from various platforms and various java-enabled web browsers. Can provide dynamic, graphics capabilities and visualizations Implemented in Java, an easy-to-learn OO programming language

What are the advantages of applets? (Cont d) Alternative to HTML GUI design Safe! Because of the security built into the core Java language and the applet structure, you don t have to worry about bad code causing damage to someone s system Can be launched as a standalone web application independent of the host web server

Summary An applet is a Java class Its code is downloaded from a web server It is invoked by a browser when it scans a web page and encounters a class specified with the APPLET tag For security reason, the execution of an applet is normally subject to restrictions: applets cannot access files in the file system on the client host Applets cannot make network connection exception to the server host from which it originated

Resources http://java.sun.com/ Java[tm] 2 Platform, Standard Edition v1.6.1 java, javac, jar, jre, etc. Any platform... FREE! Online documentation and tutorials http://www.eclipse.org/ Integrated development environment (IDE) for nothing in particular Java[tm] development tools (JDT) (comes with Eclips) Project management Editor Incremental compiler CVS support C/C++ extension in progress AspectJ support Windows, Linux, and Mac... FREE!