Download - INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Transcript
Page 1: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

INM205Object Oriented Programming in

JAVA

Dr. Michael Casey

Department of Computing

Page 2: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

INM205 SyllabusWeek Date Content Chapters

1 29/09 JAVA and object concepts: classes, instances and invocation 1

2 06/10 Anatomy of objects: types, expressions and scope. Assignment 1

2-3

3 13/10 ? Polymorphism: Shapes and Simple Graphics 4

4 20/10 ? Control structures: conditional behaviour 5

5 27/10 Iteration: Assignment 2 6

6 03/11 READING WEEK, NO LECTURE 9,10,11,12

7 10/11 Interfaces, Inheritance 9,10,11,12

8 17/11 Collections, Exceptions and Streams 13,16

9 24/11 Graphical User Interface (The SWING Library) 13,15

10 01/12 Developing Applications 1

11 08/12 Developing Applications 2

12 15/12 Exam Prep.

Page 3: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

What this module is about

• Object-oriented programming languages • what they are • why they are the way they are • how to use them

• Java used as language to illustrate ideas

• software design not the main topic: • see Object-Oriented Analysis & Design (term 2)

Page 4: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

What is a Computer ?

• Central processing unit

• Memory

• Peripherals

• Executes very simple instructions

• Executes instructions very rapidly

• General purpose device

• Programs describe specific actions

Page 5: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Computer Architecture

Page 6: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Computer Architecture

Page 7: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

What is a Program ?

CPU

Data Bus

Inst

ruct

ion

s21 40 16 100 ...

Page 8: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

What is a Program ?

CPU

Data Bus

Inst

ruct

ion

s21 40 16 100 ...

Machine Code: specific to a machine (e.g. CPU)

Page 9: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

What is a Program ?

21 40 16 100 ...iload intRatebipush 100if_icmpgt intError

Assembly Language: specific to a machine

Page 10: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

What is a Program ?

21 40 16 100 ...iload intRatebipush 100if_icmpgt intError

Assembly Language: specific to a machine

if (intRate>100)...

Page 11: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

What is a Program ?

High-level Language: General Purpose (Not machine specific)

if (intRate>100)...

iload intRatebipush 100if_icmpgt intError

Page 12: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

The JAVA Programming Language

• Clean Object-Oriented implementation

• Safe (for beginners)

• Platform independent “write once, run anywhere”

• Virtual Machine

• Rich library

• Widely-Used for Internet / Business / Academic

Page 13: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Classes and Objects

• class – a set of objects that support a specified set of operations

(methods). Analogy: a type of machine, with buttons, levers, displays, etc.

• object – an instance of a class: some data, usually hidden from

the rest of the program, and manipulated by the specified methods. Analogy: a particular machine of that type.

Page 14: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Car Class

Class

Page 15: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Car Class

Instance

Page 16: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Car Class

InstanceFields

Page 17: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Car Class

Two Instances

Page 18: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Car Class

Two Instances

One Class

Page 19: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Car Class

JamesBond car object instanceJamesBond car instance fields

Page 20: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Student LabClass Class

Two Classes

•LabClass•Student

Dependency

Page 21: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Student LabClass Class

identifierstudent1

Page 22: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Student LabClass Class

instance fields

Page 23: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Student LabClass Class

Methods

Page 24: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Shape Classes

Four Classes

Page 25: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Shape Classes

One instance

Page 26: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Shape Classes

Instance Methods

Page 27: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Shape Classes

Methods

Output (Canvas)

Page 28: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

BlueJ and JAVA

Page 29: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

BlueJ and JAVA

UML Class Diagram

Page 30: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

BlueJ and JAVA

Object Instances

Page 31: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

BlueJ and JAVA

Source Code Editor

Page 32: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

JAVA Programming Flow Chart

Page 33: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

JAVA Programming Flow Chart

Page 34: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

JAVA Programming Flow Chart

Page 35: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

JAVA Programming Flow Chart

Page 36: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

JAVA Programming Flow Chart

Page 37: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

JAVA Programming Flow Chart

Page 38: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

JAVA Programming Flow Chart

Page 39: INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.

Summary• What is a Computer ?

• CPU, Memory, Storage, I/O

• What is a Program ?• machine code, assembly language, high level language

• Objects• model things in the world• classes vs. object instances• instance fields, methods

• The JAVA Programming Flowchart• editing, compiling, running (interpreter)