1 CSC 551: Web Programming Spring 2004 Java Overview  Design goals & features  platform independence, portable, secure, simple, object-oriented, … 

Slides:



Advertisements
Similar presentations
In Review JAVA C++ GUIs - Windows Webopedia.com.
Advertisements

1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
got ? Research Project – April 1998 Hang Xia, Mark Wang, Richard S. Chang Updated: R Norman, August 1999.
Java: History and Introduction (Lecture # 1). History… Java – Based on C and C++ – Developed in 1991 for intelligent consumer electronic devices – Green.
Introduction to Java Kiyeol Ryu Java Programming Language.
JDK, Jan Pettersen Nytun - HiA 1 The Java Programming Environment: The programmer write source code with a text editor. The programmer write source code.
Principles of Object-Oriented Software Development The language Java.
COMP 519: Web Programming Fall 2006 Acknowledgment: The slides are by Dr. David Reed.Dr. David Reed Java Overview  Design goals & features  platform.
WWW and Internet The Internet Creation of the Web Languages for document description Active web pages.
1-1 Copyright (c) 1999 N. Afshartous Introduction to Java™
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
Getting Started What is Java? A programming language –Fully buzzword-compliant: A simple, object oriented, distributed, interpreted, robust, secure,
Java program.
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 1
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 v.s. C++ Programming Language Comparison By LI LU SAMMY CHU By LI LU SAMMY CHU.
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
+ Java vs. Javascript Jessi Style. + Java Compiled Can stand on its own Written once, run anywhere Two-stage debugging Java is an Object Oriented Programming.
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)
Java Overview  Design goals & features  platform independence, portable, secure, simple, object-oriented, …  Programming models  applications vs. applets.
CSCI 224 Introduction to Java Programming. Course Objectives  Learn the Java programming language: Syntax, Idioms Patterns, Styles  Become comfortable.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
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.
Why Java? A brief introduction to Java and its features Prepared by Mithat Konar.
Computer Programming 12 Mr. Jean March 19 th, 2013.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
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.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Java applets. Outline What is Java? Java Applications Java Applets Java Applets Securities Summary.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Computer Programming 2 Why do we study Java….. Java is Simple It has none of the following: operator overloading, header files, pre- processor, pointer.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Java Overview  Design goals & features  platform independence, portable, secure, simple, object-oriented, …  Programming models  applications vs. applets.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Java – in context Main Features From Sun Microsystems ‘White Paper’
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 15: Java Basics Fundamentals of Web Programming.
Introduction to JAVA Programming
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.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Applications Active Web Documents Active Web Documents.
Object Oriented Programming in
Introduction Enosis Learning.
Distributed Computing, M. L. Liu
Introduction Enosis Learning.
Distributed Computing, M. L. Liu
CSC 551: Web Programming Spring 2004
(Computer fundamental Lab)
CSC 551: Web Programming Spring 2004
Java History, Editions, Version Features
Chap 1. Getting Started Objectives
Presentation transcript:

1 CSC 551: Web Programming Spring 2004 Java Overview  Design goals & features  platform independence, portable, secure, simple, object-oriented, …  Programming models  applications vs. applets vs. servlets  intro to applets  libraries, comments, classes, inheritance  applet tag in HTML  applet parameters

2 Java was developed at Sun Microsystems, 1995  originally designed for small, embedded systems in electronic appliances  initial attempts used C++, but frustration at limitations/pitfalls recall: C++ = C + OOP features the desire for backward compatibility led to the retention of many bad features Java desired features (from the Java white paper): simpleobject-orientedrobust platform independentarchitecture neutralportable dynamicinterpretedhigh-performance distributedmulti-threadedsecure note: these are desirable features for any modern language thus, Java has become very popular, especially when Internet related also, Sun distributes free compilers (JDK) and open source

3 Language features simple  syntax is based on C++ (familiarity  easier transition for programmers)  removed many confusing and/or rarely-used features e.g., explicit pointers, operator overloading, automatic coercions  added memory management (reference count/garbage collection hybrid) object-oriented  OOP facilities similar C++, all methods are dynamically bound  pure OOP – everything is a class, no independent functions* robust  lack of pointers and memory management avoids many headaches/errors  libraries of useful, tested classes increases level of abstraction  arrays & strings are ADTs, well-defined interfaces

4 Language features (cont.) platform independence  want to be able to run Java code on multiple platforms  neutrality is achieved by mixing compilation & interpretation 1.Java programs are translated into byte code by a Java compiler  byte code is a generic machine code 2.byte code is then executed by an interpreter (Java Virtual Machine)  must have a byte code interpreter for each hardware platform  an Applet is a special form of Java application  byte code is downloaded with page, JVM is embedded in browser portable  byte code will run on any version of the Java Virtual Machine (JVM) architecture-neutral  no implementation dependent features (e.g., size of primitive types is set) high-performance  faster than traditional interpretation since byte code is "close" to native code  still somewhat slower than a compiled language (e.g., C++)

5 Language features (cont.) secure  Java applications do not have direct access to memory locations  memory accesses are virtual, mapped by JVM to physical locations  downloaded applets cannot open, read, or write local files  JVM also verifies authenticity of classes as they are loaded  Sun claim: execution model enables virus-free*, tamper-free* systems distributed  extensive libraries for coping with TCP/IP protocols like HTTP & FTP  Java applications can access remote URL's the same as local files multi-threaded  a thread is like a separate program, executing concurrently  can write Java programs that deal with many tasks at once by defining multiple threads (same shared memory, but semi-independent execution)  threads are important for multi-media, Web applications

6 Java programming models Java applications are stand-alone programs  must be compiled into Java byte code by Java compiler, then distributed  executed by an interpreter (Java Virtual Machine) Java applets provide for client-side programming  compiled into Java byte code, then downloaded as part of a Web page  executed by the JVM embedded within the Web browser  unlike JavaScript, Java is full-featured with extensive library support  Java and its APIs have become industry standards  the language definition is controlled by Sun, ensures compatibility  Applications Programming Interfaces standardize the behavior of useful classes and libraries of routines Java servlets provide similar capabilities on the server-side  alternative to CGI programs, more fully integrated into Web server

7 important point: Java applets & applications look different!  if you want to define a stand-alone application, make an application requires public static void main function, similar to C++ main  if you want to embed the code in a Web page, make an applet requires public void paint, public void init, …  can define dual-purpose programs, but tricky Java applets as with JavaScript, security is central  when a Java applet is downloaded, the bytecode verifier of the JVM verifies to see if it contains bytecodes that open, read, write to local disk  a Java applet can open a new window but they have Java logo to prevent them from being disguised as system window (e.g., to steal passwords)  a Java applet is not allowed to connect back to other servers except the host  this secure execution environment is called sand box model

8 First Java applet import java.awt.*; import java.applet.*; /** * This class displays "Hello world!" on the applet window. */ public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 10, 10); // writes starting 10 pixels over & down } libraries: Java provides extensive library support in the form of classes  libraries are loaded using import ( similar to #include in C++) java.awt: contains Abstract Window Toolkit (for GUI classes & routines) java.applet: contains the applet class definition comments: // and /* */ work the same as in C++  also have /** */ which denote documentation comments (can be used to generate docs)

9 First Java applet import java.awt.*; import java.applet.*; /** * This class displays "Hello world!" on the applet window. */ public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 10, 10); // writes starting 10 pixels over & down } class definitions in Java  similar to C++ (but no semi-colon at end) can contain instance variables (data fields) & methods(member functions) precede class & method definitions with public to make available to all programs  there are no stand-alone functions in Java*  must be stored in a file of same name with.java extension e.g., HelloWorld.java

10 First Java applet import java.awt.*; import java.applet.*; /** * This class displays "Hello world!" on the applet window. */ public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 10, 10); // writes starting 10 pixels over & down } all applets inherit from the Applet class (in java.applet) default methods include:  init(): called when page is loaded to create/initialize variables by default, does nothing  paint(Graphics g): called to draw (after init) or redraw (after being obscured) here, the paint method is overridden to display text on the applet window

11 Embedding an applet in HTML Hello World Page You must use a Java-enabled browser to view this applet. to include an applet in a Web page, use either  APPLET tag (deprecated) CODE specifies applet name, HEIGHT and WIDTH specify window size text between the APPLET tags is displayed if unable to execute (e.g., Java not enabled)  OBJECT tag preferred for HTML 4, but not universally supported view page in browser

12 HTML & applets Hello World Page You must use a Java-enabled browser to view this applet. view page in browser an applet can be embedded within HTML elements just like any other element useful for formatting and layout

13 Parameters in HTML Hello World Page You must use a Java-enabled browser to view this applet. view page in browser can specify parameters to the APPLET when it is embedded in HTML each parameter must have its own PARAM tag inside the APPLET element specifies parameter name and value

14 Applet parameters import java.awt.*; import java.applet.*; /** * This class displays a message based on parameters. */ public class HelloWorld1 extends Applet { public void paint(Graphics g) { String userName = getParameter("name"); int userAge = Integer.parseInt(getParameter("age")); String message1 = "Hello " + userName + "."; String message2 = "On your next birthday, you will be " + (userAge+1) + " years old."; g.drawString(message1, 10, 10); g.drawString(message2, 10, 30); } can access parameters passed in from the HTML document getParameter accesses the value of the parameter (must know its name)  if the parameter represents a number, must parseInt or parseFloat