centre for computer technology ict214 object oriented design and programming week 1 - introduction...

30
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information and Communication Technology Box Hill Institute of TAFE

Upload: alice-anderson

Post on 31-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

Centre for Computer Technology

ICT214Object Oriented

Design and Programming

Week 1 - Introduction

Richard Salomon and Umesh PatelCentre for Information and Communication

TechnologyBox Hill Institute of TAFE

Page 2: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Java DefinitionJava DefinitionJava is: Java is:

a simple, object oriented, network a simple, object oriented, network savvy, interpreted,robust, secure, savvy, interpreted,robust, secure, architecture neutral,portable (platform architecture neutral,portable (platform independent), high performance, independent), high performance, multi-multi-threaded, dynamic threaded, dynamic language.language.

Page 3: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

HistoryHistory Java was developed primarily by SUN engineers Java was developed primarily by SUN engineers

named named James Gosling James Gosling and and Patrick NaughtonPatrick Naughton.. Original focus was on Original focus was on smallsmall consumerconsumer devicesdevices Growth of the Web and its Growth of the Web and its write once, run write once, run

anywhere anywhere ability made it the ubiquitous internet ability made it the ubiquitous internet language that it is today.language that it is today.

It was named It was named *7 *7 and and Oak Oak before the namebefore the name Java Java was settled. was settled.

Initial version fitted on a 1.4M floppy, now it Initial version fitted on a 1.4M floppy, now it occupies 50 MB + occupies 50 MB +

Page 4: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

What is Java?What is Java?

Java is an Object Oriented Programming [OOP] Language

Java is a very popular language for building applications for the Web

Java is robust, portable, architecture neutral, multithreaded

“WORA” - Write Once Run Anywhere“WORM” – Write Once Run Many

Page 5: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Java Byte-Code and PortabilityJava is and interpreted, application

language J2SDK uses

javac to compile the source codefilename.java into

bytecode file filename.class

java runs the filename.class code on the JVM.

Compile and Run Command

Page 6: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Java Development and Runtime Environment

Java Source Code

(java)

Java Byte Code

(class)

Java Compiler

Java Byte Code

moves locallyto the JVM

Java Class Loader and Byte Code Verifier

Java Class

Libraries

Java Interpreter

J-I-TCompiler

Runtime SystemJVM

Operating system

Hardware

Page 7: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Language TypesLanguage Types

Procedural - Basic, Pascal, CEvent Driven – Visual Basic [VB] Object Oriented [OO] - C++, C#, Java

Java’s major use - internet, web, e-commerce

Page 8: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Objects and Actions

object is anything world is a set of interacting objects objects have characteristics (attributes) and its value Instance – is an object that is used by an application objects have state with certain attributes and values objects have behaviour (actions - methods)

Page 9: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Objects and Methods

Method is a set of instruction describing the operations performed by an object

An object is an entity that stores data and can take actions defined by methods

A method is an action which can be performed by an object. The action takes place as the result of a method call

also known a method invocation. The calling objects calls or invokes the method.

Page 10: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Object-Oriented Programming

java program – collection of classes class - collection of interacting objects object has its instances Encapsulation (Data Hiding) Inheritance Protection Reusability

Page 11: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

JDK/SDK Utilities

Found in the \bin directory javac, java, javah (allows incorporation of a native part in

the code), jdb, javadoc, jar

We will use the IDE - BlueJ, Netbeans

Page 12: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Basic Language ElementsBasic Language Elements

Punctuation - the symbols that are used Punctuation - the symbols that are used by a computer languageby a computer language

Syntax - construction rules to code in Syntax - construction rules to code in that languagethat language

Vocabulary - the language keywordsVocabulary - the language keywords Operators - Symbols or commands for Operators - Symbols or commands for

processing data processing data Identifiers - symbols to reference data Identifiers - symbols to reference data

stored in memory of the computerstored in memory of the computer

Page 13: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Java Program ExampleJava Program Example /**

** HelloWorld.java* @author Richard

* @version 1.0*/

public class HelloWorld{ public static void main(String args []) { String name = “ Richard Salomon” ; System.out.println(“Hello World“);

System.out.println(“\nMy name is ” + name + “\n”); }}

Page 14: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Documentation

Documentation can impact the success or failure of a project

Documentation does two things: aid the design process communicate your design and describe your implementation to

other programmers

Page 15: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Good Design DocumentationGood Design DocumentationMeaningful name for variablesUse Comments according to Java Coding

Standards IndentationNamed Constants Simple Program StructureReduce class load

Page 16: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Design ProcessDesign Process

I. Comments serve as the first step of class design

II. Turn comments into pseudocode

III. Refine pseudocode into java code

IV. Comments help with debugging

Page 17: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

CommentsComments // single line comment

/* block commentover many lines

*/

Page 18: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

CommentsComments /** java doc comment, used by the javadoc

tool. Can include single line comments

and html tags. eg <tt> monos paced text </tt>

Some html tags cause problems in javadoc eg header and frame tags

All javadoc comments must be placed before declarations. Javadoc comments placed within code braces will be ignored by the javadoc tool*/

Page 19: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

CommentsCommentsBest to start program development with Best to start program development with

comments rather than spending a lot of comments rather than spending a lot of time after the code is written. time after the code is written. Why?Why?

Java documentation is available at Java documentation is available at java.sun.com/docs and should be java.sun.com/docs and should be installed in the jdk#.#.#/doc directoryinstalled in the jdk#.#.#/doc directory

Page 20: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

ElementsElements Java is case sensitive; FRED differs from fred

and also from Fred Keywords – must be lower case

there are 48 keywordsNB true, false, null are literals, not keywords

Identifiers – labels for data– first character must be alpha– no space– case sensitive– no keywords

Page 21: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

ElementsElementsOperators Operators

braces braces { }{ }bracketsbrackets [ ][ ]parenthesisparenthesis ( )( )white space white space

e.g. int myInteger = 27 ;e.g. int myInteger = 27 ;

keyword identifier

assignmentoperator literal

terminator

Page 22: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Data StorageData StorageRegisters -Registers - space within CPUspace within CPUThe stack -The stack - method variables in RAMmethod variables in RAMThe heap -The heap - objects in RAMobjects in RAMStatic storage – shared method or variableStatic storage – shared method or variableConstant - non-changing variable in RAMConstant - non-changing variable in RAMNon-RAM storage – disk spaceNon-RAM storage – disk space

Page 23: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

VariablesVariables Variables represent data in storage locations in

memory The data stored by a variable is called its value

The value is stored in the memory location The value can be changed.

Variable consist of 5 parts- identifier (name)- reference (memory address)- data type- scope (lifespan)- value (literal)

Page 24: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Data TypeData TypeData type tells the compiler how to Data type tells the compiler how to

interpret and store the data. interpret and store the data. It described the type of an attribute (field)It described the type of an attribute (field)Java allocates a set amount of storage to Java allocates a set amount of storage to

each type of data. each type of data. Thus Thus Java is strongly typedJava is strongly typed – – Assignment CompatibilitiesAssignment Compatibilities

Page 25: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Java Data Types

Primitive data types

Reference

boolean char numeric

Integralfloating point

byte short longint float double

Page 26: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Data Type StorageData Type Storage

boolean – 1 bit true/falseboolean – 1 bit true/false char - 16 bits unicodechar - 16 bits unicode bytebyte - 8 bits -128 to +127 - 8 bits -128 to +127 short - 16 bits -32768 to +32767 short - 16 bits -32768 to +32767 int - 32 bits - 2int - 32 bits - 23131 to +2 to +23131-1-1 long - 64 bits -9 x 10long - 64 bits -9 x 101818 to +9 x 10 to +9 x 101818 float - 32 bits up to 7 decimal places float - 32 bits up to 7 decimal places double - 64 bits up to 14 decimal placesdouble - 64 bits up to 14 decimal places

Page 27: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Object data default valuesObject data default valuesData type Default values

byte 0

short 0

int 0

long 0

float 0.0

double 0.0

boolean false

char \u0000

reference null

Page 28: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Assignment

assignment statement used to assign a value to a variable Operator is “=“

example lastName = ‘citizen’;

special operators can be combined with arithmetic operators (+, -, *, %)

Page 29: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Naming Conventions Class types begin with an uppercase letter Primitive types begin with a lowercase letter Variables of both class and primitive types begin with a lowercase

letters Java Class Naming Conventions

Must begin with a letter of any alphabet Can contain only letters, digits, underscores, or $ signs Can not be a Java keyword or literal Case sensitive Start with an upper case letter and then use lower case letters, with the

first character of a new word capitalised e.g. Person, MotorVehicle

a file may have many classes but only one public class file name must match the public class name

Page 30: Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information

April 19, 2023April 19, 2023 Copyright Box Hill Institute

Other Issues

Simple Input / Output Named and Numbered Constants Initialisation Parenthesis and Precedence Increment / Decrement Operators