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

Slides:



Advertisements
Similar presentations
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Advertisements

Java Applets. An applet is a Panel that allows interaction with a Java program. A applet is typically embedded in a Web page and can be run from a browser.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
1 Introduction to Applets Overview l What is an Applet? l Steps for creating an applet l What is HTML? l Basic HTML tags l Drawing Simple Graphical shapes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
18-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Applets. An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from a browser You.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
26-Jun-15 Applets. 2 An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from.
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
1 CSC 551: Web Programming Spring 2004 Java Overview  Design goals & features  platform independence, portable, secure, simple, object-oriented, … 
Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Applets & Servlets.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Java Lecture 16: Dolores Zage. WWW n Was a method for distributing passive information n added forms and image maps n interaction was only a new way to.
JAVA APPLETS By: Ms. Humaira Siddiqui. Java and the Internet Java is considered to be a language well suited to be used in the internet. In contrast with.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
Applets.
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
POS 406 Java Technology And Beginning Java Code
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Java Applets. An applet is a Panel that allows interaction with a Java program. A applet is typically embedded in a Web page and can be run from a browser.
1 CSC Computer Education (P) Ltd. DESIGNED BY K PRAKASH,
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Java Applets 1. What is an applet? An applet is a small Java program that is typically embedded in a Web page and can be run using the applet viewer or.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 35 – Overview of Java Web Programming Webpage:
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
Java and its Evolution. Contents Java Introduction Java Features How Java Differs from other OO languages Java and the World Wide Web Java Environment.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Lecture 1. Introduction to Programming and Java MIT- AITI 2003.
1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web.
1 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
Creating a Java Application and Applet
1 Applets. 2 What is an applet? Applet: a Java program that can be inserted into a web page and run by loading that page in a browser brings web pages.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
1 Java Applet Basics Chapter Eight. 2 Applets vs. Applications l Applications: Stand alone Java programs run by interpreter l Applets WWW browser embedded.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Applications Active Web Documents Active Web Documents.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Introduction to Computing Using Java
Java Applets.
Introduction to Applet, Application and JDK
Java applets 1/3/2019.
CSC 551: Web Programming Spring 2004
Applet in Java.
CSC 551: Web Programming Spring 2004
Handout-14 Applets and Graphics
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Enabling Application Delivery Via the Web
G6DICP - Lecture 27 Java Applets.
APPLET PROGRAMMING.
Presentation transcript:

Java applets

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

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 sameclass have the same methods.) Object oriented language

A method of the ATM class: parameters Money withdrawMoney(ATMCard card,int amount) type of return value myPurse.addMoney(theATM. withdrawMoney(myATMCard,1000)); type of the parameter name of the parameter 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. Object oriented language

Java Architecture Compiler source code byte code JVM Computer programmeruser

Java Architecure Compiler byte code Computer portability programmeruser security source code JVM speed

Why Java? simple portable secure free slow

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

Learning Java book, lectures language libraries documentation examples on the web (problem – often old version of Java)

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

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

Whatisanapplet?

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

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

Applets, web page, client, server

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.

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() stop() destroy() do some work

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" >

Applet's Attributes AttributeExplanationExample CodeName of class fileCode=“applet0.class” WidthWidth of appletWidth=300 heightHeight of appletHeight=60 CodebaseApplet’s DirectoryCodebase=“/applets” altAlternate text if applet not available Alt=“menu applet” nameName of the appletName=“appletExam” Align(top,left,right,bottom) Justify the applet with text Align=“right”

HTML Hello World Applet

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

Save as Hello.html

import java.applet.Applet; import java.awt.*; public class Hello extends Applet { public void paint(Graphics g) { g.drawString(“Hello World!”,30,30); } what to draw where to draw it Save as Hello.java

History of an Applet browser Hello.html 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

History of an Applet browser Hello.html 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

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) x (0,0) (width,0)

Sample Graphics methods A Graphics is something you can paint on g.drawString(“Hello”, 20, 20); 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); Hello

Passing Parameter to Applets: tag is used to pass the parameter value from HTML file to Applet code. In the example shown below parameter which is used is named as “name” and value of the parameter is initialized as “Achin Jain”. Now in the Applet code, you should use same parameter name as “name” to fetch the value.

Getting Input from User As you know that applet works in Graphics environment where inputs are treated as strings. So, in order to get input from user, we need to create TextField just we used to do in HTML coding. Below is the example that takes input user from as a Number and Seconf TextField displays the square of that number.

Display image in Applet An applet can display images of the format GIF, JPEG, BMP, and others. To display an image within the applet, you use drawImage() method.

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.

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

SummarySummary 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