Object Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
Road Map Introduction to object oriented programming. Classes
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
CPSC150 Spring 2006 Dr. L Lambert. Week 1/2 intro (and Chapter 1)
Understanding class definitions Looking inside classes 3.0.
HST 952 Computing for Biomedical Scientists Lecture 2.
Writing methods and Java Statements. Java program import package; // comments and /* … */ and /** javadoc here */ public class Name { // instance variables.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
Introduction to Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Object Oriented Software Development
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Slide 1 Data Types Object Interactions Tracing Introduction to Object-Oriented Programming Lesson 2: Classes and Instances.
Introduction to Programming Writing Java Beginning Java Programs.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
Object Oriented Design: Identifying Objects
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
The Java Programming Language
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Introduction to Java. 2 Textbook David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition, Pearson.
Object Oriented Programming … and other things you need to program in java.
1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
1 CSC 221: Computer Programming I Fall 2005 interacting objects  abstraction, modularization  internal vs. external method calls  primitives vs. objects.
1 CSC 221: Computer Programming I Fall 2004 interacting objects  abstraction, modularization  internal method calls  object creation, external method.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
Introduction to Programming Writing Java Beginning Java Programs.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 4 Introduction to Classes, Objects, Methods and strings
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
Javadoc. Purpose of javadoc javadoc is a program that reads your Java program and produces great-looking documentation in HTML format Without any help,
Arithmetic, Class Variables and Class Methods Week 11
Introduction to OOP CPS235: Introduction.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Classes, Interfaces and Packages
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
CSH Intro. to Java. The Big Ideas in Computer Science Beyond programming Solving tough problems Creating extensible solutions Teams of “Computational.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Chapter 1 Object Orientation: Objects and Classes.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Visit for more Learning Resources
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Chapter 3: Using Methods, Classes, and Objects
Road Map Introduction to object oriented programming. Classes
Programming without BlueJ Week 12
Java Programming with BlueJ
Workshop for Programming And Systems Management Teachers
Programs and Classes A program is made up from classes
Objects First with Java A Practical Introduction using BlueJ
Objects First with Java A Practical Introduction using BlueJ
February , 2009 CSE 113 B.
References Revisted (Ch 5)
Presentation transcript:

Object Interaction and Source Code Week 2

OBJECT ORIENTATION BASICS REVIEW

Object – Represents an actual thing! Class – ‘Blueprint’ for making an object Method – Things an object can do (behaviour) Parameter – input required by an object method Data type – what type of data is allowed Object Model Basics FUNDAMENTAL CONCEPTS

Many objects (instances) can be created from a single class. An object has attributes (fields), and those attributes have values assigned to them. The class defines what fields an object has, but each object stores its own set of values (state). Each class has source code (Java) associated with it that defines its fields and methods. Object Model Basics OTHER OBSERVATIONS

OBJECT ORIENTATION OBJECT INTERACTION

Create the outside wall: 1.wall = new Square(); 2.wall.moveHorizontal(-140); 3.wall.moveVertical(20); 4.wall.changeSize(120); 5.wall.makeVisible(); How To Draw A House A SEQUENCE OF METHOD CALLS

Create the window: 1.window = new Square(); 2.window.changeColor(“black”); 3.window.moveHorizontal(-120); 4.window.moveVertical(40); 5.window.changeSize(40); 6.window.makeVisible(); How To Draw A House A SEQUENCE OF METHOD CALLS

Create the roof: 1.roof = new Triangle(); 2.roof.changeSize(60, 180); 3.roof.moveHorizontal(20); 4.roof.moveVertical(-60); 5.roof.makeVisible(); How To Draw A House A SEQUENCE OF METHOD CALLS

Create the sun: 1.sun = new Circle(); 2.sun.changeColor(“yellow”); 3.sun.moveHorizontal(100); 4.sun.moveVertical(-40); 5.sun.changeSize(80); 6.sun.makeVisible(); How To Draw A House A SEQUENCE OF METHOD CALLS

How To Draw A House A SEQUENCE OF METHOD CALLS Final result after a sequence of 22 method calls

A house picture is composed of four different shape objects – representing a wall, window, roof and sun. The sequence of 22 method calls used to create and manipulate these objects will always be the same. It would be convenient to record the 22 method calls and replay them whenever we wished to draw a picture of the house. Object Interaction OBSERVATIONS ON DRAWING THE HOUSE

BlueJ Demonstration A First Look at the Picture class

/** * This class represents a simple picture. * You can draw the picture using the draw method… */ public class Picture { private Square wall; private Square window; private Triangle roof; private Circle sun; Java Source Code Picture.java

/** * Constructor for objects of class Picture */ public Picture() { // nothing to do... instance variables are automatically set to null } Java Source Code Picture.java A constructor is a ‘special method’ that is called when the object is created and is used for object initialisation. Constructors are defined like other methods but use the name of the class.

Creating a new object wall = new Square(); variable of type Square assignment creates an instance of the class calls the constructor

Sending messages to objects by invoking their methods wall.moveHorizontal(-140);

public void draw() { wall = new Square(); wall.moveHorizontal(-140); wall.moveVertical(20); wall.changeSize(120); wall.makeVisible(); window = new Square(); window.changeColor("black"); window.moveHorizontal(-120); window.moveVertical(40); window.changeSize(40); window.makeVisible(); Java Source Code Picture.java

Java Source Code Picture.java roof = new Triangle(); roof.changeSize(60, 180); roof.moveHorizontal(20); roof.moveVertical(-60); roof.makeVisible(); sun = new Circle(); sun.changeColor("yellow"); sun.moveHorizontal(100); sun.moveVertical(-40); sun.changeSize(80); sun.makeVisible(); }

A method of one class can create objects of other classes, and can invoke those object’s methods. An object’s method can only be called with its correct method signature, i.e. with the correct number, data types and order of its parameters. Always put comments in your source code to ensure others can understand your program. Object Interaction & Source Code IMPORTANT POINTS TO REMEMBER

Comments Comments are statements that are put into a program to help others understand what it does Comments are marked by: // this is a single line comment /* this is a multiline comment */ /** so is this */

Java syntax - blocks and semicolons Curly brackets { } mark the beginning and end of blocks of code including classes and methods Semicolons ; mark the end of statements

COMPILING AND RUNNING JAVA PROGRAMS Java compiler JVM Running program Edit & debug Libraries / Java API Source code Java byte code Each Java class definition is held in a separate.java file, and the byte code is held in a.class file. Java Source Code Picture.java holds our source code, and Picture.class holds the detail the computer needs to create Picture objects.

Required Reading Objects First With Java – A Practical Introduction using BlueJ Related reading for this lecture Chapter 1 pp 3-17 (Objects and Classes)