Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;

Slides:



Advertisements
Similar presentations
wwwcsif.cs.ucdavis.edu/~jacksoni
Advertisements

Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Object Oriented Programming in JAVA
Lab#1 (14/3/1431h) Introduction To java programming cs425
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
Principles of Object-Oriented Software Development The language Java.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Client Side Programming Using Java Applet
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Getting Started What is Java? A programming language –Fully buzzword-compliant: A simple, object oriented, distributed, interpreted, robust, secure,
1 CSC 551: Web Programming Spring 2004 Java Overview  Design goals & features  platform independence, portable, secure, simple, object-oriented, … 
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
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 Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
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.
Computer Programming 12 Mr. Jean March 19 th, 2013.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
POS 406 Java Technology And Beginning Java Code
Java Programming, Second Edition Chapter One Creating Your First Java Program.
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
Java applets. Outline What is Java? Java Applications Java Applets Java Applets Securities Summary.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 35 – Overview of Java Web Programming Webpage:
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
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.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Creating a Java Application and Applet
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.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
OOP Basics Classes & Methods (c) IDMS/SQL News
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Lesson 2: First Java Programs. 2.1 Why Java? Java is one of the most popular programming languages in the world. Java is a modern object-oriented programming.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Applications Active Web Documents Active Web Documents.
A Programming Language for Web-based Computing with Graphics
Java Applet Programming Barry Sosinsky Valda Hilley
Internet and Java Foundations, Programming and Practice
Java Applets.
A Programming Language for
Chap 1. Getting Started Objectives
A Programming Language for
APPLET PROGRAMMING.
Presentation transcript:

Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs; –and how to write Java Applets for displaying images, playing sound, graphic effects and animations.

Java basics, development, and applets Introduction This section describes the Java language, the development process, and what an applet is. After completing this section, you should be able to: 1.What is Java? What are Java application and Java Applet? 2.Describe the syntax of a Java class 3.Code a simple Java source file 4.Understand the basic structure of an applet and how it interacts with a Web browser 5.Code a simple Java applet source file 6.Write output to the system console 7.Code HTML to invoke an applet

What is Java? –The Java language and companion class libraries provide a portable, interpreted, high-performance, simple, object-oriented, development environment. –There are two types of Java programs: applets and applications. Applets are Java programs that are usually embedded in an HTML Web page and downloaded from the Web to be run by a browser on the user’s computer system. Applications are full-fledged programs written in Java. They don’t require a Web browser to run, but they do require the Java VM to be installed on the target platform.

The Java Virtual Machine –The high-level programming language such as C, C++, Pascal must first be translated into an executable machine-language program. –Normally, there are two ways for translation: Using a complier to translate at once, in this case the compiled program can only run on one type of computer with same type of OS. (Such as C, C++, Pascal) Using a interpreter to translate instruction-by-instruction. (Such as Basic, Perl) –The designer of Java chose to use a combination of compilation and interpretation. Programs written in Java are compiled into machine language, but it is a machine language for a computer that doesn’t really exist. This so-called “virtual” computer is known as the Java virtual machine. The machine language for the Java VM is called Java bytecode.

A different Jave bytecode interpreter is needed for each type of computer, but once a computer has a Java bytecode interpreter, it can run any Java bytecode program. And the same Java bytecode program can be run on any computer that has such an interpreter. This is one of the essential features of Java: the same compiled program can be run on many different types of computers.

Anatomy of a Java class Any Java source file (.java) has this physical structure: import statements; class definition { instance variable definitions; method definition (argumentList) { local variable definitions statements; } // end of method definition // more methods... } // end of class definition A class is used to instantiate specific objects (each with possibly different values) in the heap. For example, the figure right shows help as an instance of class Button.

Primitive and object variables Variables are represented on the stack as either: –A built-in primitive type (byte, short, int, long, char, float, double, or boolean) that uses value semantics int i = 42; /* i holds value (42) */ –An object type (extended from java.lang.Object) that uses reference semantics (like a pointer) Button helpButton = new Button("Help"); /* helpButton is an object ref */

Primitive Data Types

Lifetime of a variable A variable has a storage class, which sets its lifetime. –Local variables are local to a block of code, that is, allocated at entry to a block and discarded at exit. (A block of code can be either a class or a method.) –Instance variables are local to an object, that is, allocated when an object is instantiated and discarded when it is garbage-collected. –Class (static) variables are local to a class, that is, allocated when a class is loaded and discarded when it is unloaded. An object (referred to by a variable) is marked for garbage collection when there are no references to it.

C-like Java Most of the C programming language statements are present in the Java language: float sqrt(float value) { /* compute a square root badly! */ float guess; int loops; if (value <= 0) return 0; else guess = value/2; for (loops = 0; loops < 5; loops++) { guess = (guess + value /guess) /2; } return guess; } As well as if/else, for, and return, the Java language has C's while, do/while, and switch/case/default statements.

Messages and object communication Objects use messages to communicate. Valid messages are represented by a public interface. Messages in Java correspond to method calls (invocations) in C. Messages must have a reference to the target object to send a message. /* Send help button a msg */ helpButton.setEnabled(false); If no object is specified, the current object (this) is assumed, for example, f() implies this.f().

Java development process The javac command compiles Java source code (.java) into bytecode (.class). Syntax: Javac YourJavaProgram.Java These bytecodes are loaded and executed in the Java virtual machine (JVM), which is embeddable within other environments, such as Web browsers and operating systems. Syntax: Java YourJavaProgram(.class)

“Hello world” Java application program( HelloWorlApp.java ) /** * The HelloWorldApp class implements an application that simply displays "Hello World!" to the standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); //Display the string. } This program has three part: 1.The enclosing class definition-In this case, it’s named HelloWorldApp 2.The body of the program, the main() method – for this application. The main() method is the subroutine that is executed when this application is run 3.The code that produces the actual output of the program.

Displaying applets An applet is a Java program that is referenced by a Web page and runs inside a Java- enabled Web browser. An applet begins execution when an HTML page that "contains" it is loaded. Either a Java-enabled Web browser or the appletviewer is required to run an applet. The browser detects an applet by processing an Applet HTML tag, for example:

Web browser-to-applet interface This figure shows the browser-to-applet interface.

Structure of a simple applet By inheriting from java.applet.Applet, the necessary structure is defined to coordinate with a Web browser. Extends is the keyword in the Java language used to inherit classes. public class MyApplet extends java.applet.Applet { public MyApplet( ) { //create applet System.out.println("In ctor"); } public void init( ) { // initialize System.out.println("In init"); } public void start( ) { // display page System.out.println("In start"); } public void stop( ) { // leave page System.out.println("In stop"); } public void destroy( ) {// clean up System.out.println("In destroy"); } The init() method is run only when the applet first starts; start() is executed when the applet is displayed or refreshed. Note that standard out (or output for the println command) is sent to the console window if you are running within a browser or to a DOS window if you are running your applet from appletviewer via a DOS window.

The “Hello World” applet example HelloWorld.java: Import java.applet.Applet; Import java.awt.Graphics; Public class HelloWorld extends Applet{ public void paint(Graphics g){ g.DrawString(“Hello world!”, 50,25); } Hello.html: A Simple Program Here is the output of my program: