Chapter 7 Java Object Model

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Effective Java, Chapter 3: Methods Common to All Objects.
1 Class Design CS 3331 Fall Outline  Organizing classes  Design guidelines  Canonical forms of classes equals method hashCode method.
Lab#1 (14/3/1431h) Introduction To java programming cs425
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Searching. 2 Searching an array of integers If an array is not sorted, there is no better algorithm than linear search for finding an element in it static.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
1 Java Object Model Part 1. 2 Type Definition: set of values – a set of values and set of operations –a set of operations that can be applied to those.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
Searching. 2 Searching an array of integers If an array is not sorted, there is no better algorithm than linear search for finding an element in it static.
FrameworksFrameworks chap8. Framework Set of cooperating classes Structures the essential mechanisms of a problem domain Framework != design pattern Typical.
Comparing Objects in Java. The == operator When you define an object, for instance Person p = new Person("John", 23); we talk about p as if its value.
Searching Also: Logarithms. 2 Searching an array of integers If an array is not sorted, there is no better algorithm than linear search for finding an.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Searching Also: Logarithms. 2 Searching an array of integers If an array is not sorted, there is no better algorithm than linear search for finding an.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
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.
Object-oriented Programming in Java. What is OOP?  The goal is (subtype) polymorphism  Achieved by Classes (user-defined types) Classes (user-defined.
Your First Java Application Chapter 2. 2 Program Concepts Modern object-oriented programs help us build models to manage the complexity found in a problem.
Puzzle 3 1  Write the class Enigma, which extends Object, so that the following program prints false: public class Conundrum { public static void main(String[]
Non-static classes Part 2 1. Methods  like constructors, all non-static methods have an implicit parameter named this  for methods, this refers to the.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
DATA STRUCTURES Lecture: Polymorphism Slides adapted from Prof. Steven Roehrig.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Symbol Tables From “Algorithms” (4 th Ed.) by R. Sedgewick and K. Wayne.
Chapter 8 (Horstmann’s Book) Frameworks Hwajung Lee.
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.
Chapter 8 Frameworks. Frameworks Framework is a set of cooperating classes and interface types that structures the essential mechanisms of a particular.
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.
Java Type System and Object Model Horstmann ch , 7.7.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
1 Class Design CS 3331 Sec 6.1 & 6.3 of [Jia03]. 2 Outline  Organizing classes  Design guidelines  Canonical forms of classes equals method hashCode.
CS 151: Object-Oriented Design November 12 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Interfaces, Abstract Classes, and Polymorphism. What Is an Interface? An interface is the set of public methods in a class Java provides the syntax for.
COMP 110 Some notes on inheritance, review Luv Kohli December 1, 2008 MWF 2-2:50 pm Sitterson 014.
CS 151: Object-Oriented Design December 3 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
Chapter 02 Data and Expressions.
Modern Programming Tools And Techniques-I
Searching.
Object-oriented Programming in Java
CSE 413, Autumn 2002 Programming Languages
30 Java Applets.
COMP 110 Some notes on inheritance, review
Explicit and Implicit Type Changes
Your First Java Application
null, true, and false are also reserved.
Polymorphism.
Applets.
UNIT-5.
Java Applets.
Building Java Programs
Searching.
Lecture 25: Inheritance and Polymorphism
CS/ENGRD 2110 Spring 2019 Lecture 6: Consequence of type, casting; function equals
Applet Fundamentals Applet are small applications that are accessed on an Internet server, transported over the Internet, automatically installed and run.
Defining Classes and Methods
Java’s Central Casting
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Enabling Application Delivery Via the Web
ITEC324 Principle of CS III
Review for Midterm 3.
Presentation transcript:

Chapter 7 Java Object Model

Types Type: set of values and the operations that can be applied to the values Strongly typed language: compiler and run-time system check that no operation can execute that violates type system rules Compile-time check Employee e = new Employee(); e.clear(); // ERROR Run-time check:

Java Types Primitive types: int short long byte char float double boolean Class types Interface types Array types The null type Note: void is not a type

Java Values value of primitive type reference to object of class type reference to array null Note: Can't have value of interface type

Subtype Relationship S is a subtype of T if S and T are the same type S and T are both class types, and T is a direct or indirect superclass of S S is a class type, T is an interface type, and S or one of its superclasses implements T S and T are both interface types, and T is a direct or indirect superinterface of S S and T are both array types, and the component type of S is a subtype of the component type of T S is not a primitive type and T is the type Object S is an array type and T is Cloneable or Serializable S is the null type and T is not a primitive type

Type Inquiry Test whether e is a Shape: if (e instanceof Shape) . . . Common before casts: Shape s = (Shape) e; Don't know exact type of e Could be any class implementing Shape If e is null, test returns false (no exception)

The Class Class getClass method gets class of any object Returns object of type Class Class object describes a type Object e = new Rectangle(); Class c = e.getClass(); System.out.println(c.getName()); // prints java.awt.Rectangle

The equals Method equals tests for equal contents == tests : whether two references are the identical objects. Used in many standard library methods

Requirements for equals Method reflexive: x.equals(x) symmetric: x.equals(y) if and only if y.equals(x) transitive: if x.equals(y)  and y.equals(z), then x.equals(z) x.equals(null) must return false

Chapter 8 Frameworks

Frameworks Set of cooperating classes Structures the essential mechanisms of a problem domain Example: Swing is a GUI framework Framework != design pattern Typical framework uses multiple design patterns

Application Frameworks Implements services common to a type of applications Programmer forms subclasses of framework classes Result is an application Inversion of control: framework controls execution flow

Applets Applet: Java program that runs in a web browser Programmer forms subclass of Applet or JApplet Overwrites init/destroy start/stop paint

Applets

Applets Interacts with ambient browser getParameter showDocument HTML page contains applet tag and parameters <applet code="BannerApplet.class" width="300" height="100"> <param name="message" value="Hello, World!"/> <param name="fontname" value="Serif"/> <param name="fontsize" value="64"/> <param name="delay" value="10"/> </applet>

Example Applet Shows scrolling banner init reads parameters start/stop start and stop timer paint paints the applet surface Ch8/applet/BannerApplet.java

Example Applets

Applets as a Framework Applet programmer uses inheritance Applet class deals with generic behavior (browser interaction) Inversion of control: applet calls init, start,stop,destroy