Introduction to Object-oriented Programming Java API.

Slides:



Advertisements
Similar presentations
AP Computer Science A – Healdsburg High School 1 Unit 3 - Classes and Objects - Example.
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
Chapter 1: Introduction
Classes & Objects Computer Science I Last updated 9/30/10.
OBJECT-ORIENTED PROGRAMMING CONCEPTS (Review). What is an Object? What is an Object? Objects have states and behaviors. Example: A dog has states - color,
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 1 Introducing Java.
Chapter 1 Object-Oriented System Development
What is an object? Your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior;
HST 952 Computing for Biomedical Scientists Lecture 2.
Java Programming, 3e Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
Introduction to Alice Basics : What is Alice? Object Oriented Definitions What Does it Look Like? Where Can I Use it?
Visual Basic Introduction IDS 306 from Shelly, Cashman & Repede Microsoft Visual Basic 5: Complete Concepts and Techniques.
Introduction to Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
C++ fundamentals.
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
1 INTRODUCTION TO OOP Objective: Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know.
Chapter 1 - Introduction. Ch 1Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
Java Programming, 2E Introductory Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
M1G Introduction to Programming 2 1. Designing a program.
Programming Languages and Paradigms Object-Oriented Programming.
COMPUTER SOFTWARE Section 2 “System Software: Computer System Management ” CHAPTER 4 Lecture-6/ T. Nouf Almujally 1.
Microsoft Visual Basic 2005: Reloaded Second Edition
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
An Object-Oriented Approach to Programming Logic and Design
Basic Object-Oriented Concepts
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Programming 1 1. Introduction to object oriented programming and problem-solving.
Computer Programming 12 Mr. Jean March 19 th, 2013.
Lecture 1 Introduction to Java MIT-AITI Ethiopia 2004.
1. 2 Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage.
Introduction To System Analysis and Design
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
1. Introduction Based on Java Software Development, 5 th Ed. By Lewis &Loftus.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
Computer Concepts 2014 Chapter 12 Computer Programming.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
The Teacher Computing Computer Languages [Computing]
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Basic OOP Concepts and Terms. In this class, we will cover: Objects and examples of different object types Classes and how they relate to objects Object.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Learners Support Publications Object Oriented Programming.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Salman Marvasti Sharif University of Technology Winter 2015.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
CSC1200 INTRODUCTION TO PROGRAMMING Dr. Maureen Markel
Objects We are all familiar with the idea of an object. We are surrounded by them: cars, books, people, houses, cats, etc. Objects have attributes, e.g.
Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented.
Introduction to Classes, Objects, Methods and Attributes Lecture # 5.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
OCR A Level F453: High level languages Programming techniques a. identify a variety of programming paradigms (low-level, object- oriented,
WEEK 1 1 What is a Computer Program? An algorithm that can be executed on a computer is a program. A program usually contains several algorithms.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Computer Languages [Computing] Computing.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Objects as a programming concept
Object Oriented Concepts -I
Introduction to Object-oriented Programming
Presentation transcript:

Introduction to Object-oriented Programming Java API

OOP Concepts Object-oriented vs Procedure-oriented Programming Object-oriented vs Procedure-oriented Programming Objects and Classes Objects and Classes Encapsulation and Information Hiding Encapsulation and Information Hiding Java API Java API Java Programs Java Programs Example Programs Example Programs

Procedure-Oriented Programing In procedure-oriented programs (FORTRAN, COBOL, C, Pascal, BASIC, etc.), emphasis is on sequence of commands (procedure) to the computer. In procedure-oriented programs (FORTRAN, COBOL, C, Pascal, BASIC, etc.), emphasis is on sequence of commands (procedure) to the computer. For example, the following algorithm For example, the following algorithm reads a list of items from a file, reads a list of items from a file, sorts the list, and sorts the list, and prints the sorted list. prints the sorted list.

Open (aFile) cout  0 while (not isEOF (aFile)) Read (anItem from aFile) count  aList (count)  anItem end While Close (aFile) Sort (aList) Print ( elements of aList) Read, Sort, Print (procedural)

Object-oriented Programming As programs become complex, procedural programming becomes inadequate—too many data and actions to keep track of. As programs become complex, procedural programming becomes inadequate—too many data and actions to keep track of. Many program behaviors are not simply sequential but are concurrent. Many program behaviors are not simply sequential but are concurrent. In OOP, a program consists of a collection of objects that interact with each other. In OOP, a program consists of a collection of objects that interact with each other.

Emphasis on Objects aFile.open() while( aFile.EOF() is not true) anItem = aFile.read() aList.insertNewItem(anItem) end while aFile.close() aList.sort() aList.print()

In OOP Program, note… Objects—e.g., aList and aFile—are the focus of program, not procedures. Objects—e.g., aList and aFile—are the focus of program, not procedures. Each object possesses operations peculiar to it— e.g., aFile.open(), aFile.close(), aList.read(), aList.insertNewItem(), aList.sort() Each object possesses operations peculiar to it— e.g., aFile.open(), aFile.close(), aList.read(), aList.insertNewItem(), aList.sort() Objects are called (asked) to perform its operation to get a job done—e.g., aFile.open. Objects are called (asked) to perform its operation to get a job done—e.g., aFile.open. In OOP, the inner structure of aList is not revealed to the user of the object—user need not know whether it is an array, linked list, or something else. In OOP, the inner structure of aList is not revealed to the user of the object—user need not know whether it is an array, linked list, or something else.

Objects and Classes An OO program consists of a collection of objects interacting with each other. An OO program consists of a collection of objects interacting with each other. Class Class A template for creating objects A template for creating objects It consists of attributes (characteristics) and methods (operations) It consists of attributes (characteristics) and methods (operations) Object Object An instance of a class An instance of a class Many object can be created from a class Many object can be created from a class

Objects and Classes  Suppose you are writing a game that involves several dogs, cats, and cars. (Use your imagination.)  You need to define a Dog class.  Here are some dog objects: Fido—a big brown bulldog Fido—a big brown bulldog Lassie—a tall collie dog Lassie—a tall collie dog Taro—a small, white akita dog Taro—a small, white akita dog

Objects Attributes: name = Fido breed = bulldog color = brown weight = 30 kg height = 50 cm Operations: bark() display() Attributes: name = Lassie breed = collie color = brow weight = 25 kg height = 70 cm Operations bark() display() Attributes: name = Taro breed = akita color = white weight = 10kg height = 30 cm Operations bark() display() Dog object

Class A class A class Is an abstraction of the objects of the same type. Fido, Lassie, and Taro are all instances of the Dog class. Is an abstraction of the objects of the same type. Fido, Lassie, and Taro are all instances of the Dog class. Is a template for creating (specifying) objects of a particular type. Is a template for creating (specifying) objects of a particular type. Is like a blueprint for creating objects Is like a blueprint for creating objects Specifies attributes and methods (operations) Specifies attributes and methods (operations) Each objects has Each objects has Different attributes values Different attributes values Same operations Same operations

Class (cont.) A class is composed of A class is composed of Class Name Class Name Attributes Attributes Operations Operations Once a class is defined, objects can be created (instantiated) from it. Once a class is defined, objects can be created (instantiated) from it.

Class Diagram Dog breed color weight height Bark() display() Class name Attributes Operations Car make engineSize color maxSpeed Start() accelerate() stop() display()

Practice Specify some relevant attributes and operations for the following classes. Specify some relevant attributes and operations for the following classes. Bank Account Bank Account Book Book Browser window Browser window Circle (geometric figure) Circle (geometric figure) Rectangle (geometric figure) Rectangle (geometric figure)

Java API (Application Program Interfaces) API is a collection of predefined classes in the library. API is a collection of predefined classes in the library. You can use them to write complex programs. You can use them to write complex programs. You should bookmark it so that you can refer to it at anytime. ( ) You should bookmark it so that you can refer to it at anytime. ( )

Package A package is a sructure to organize a collection of related classes and other resources. A package is a sructure to organize a collection of related classes and other resources. java.io—contains classes related to File I/O java.io—contains classes related to File I/O java.util—contains classes like Date, Currency, and GregorianCalendar java.util—contains classes like Date, Currency, and GregorianCalendar javax.swing—contains classes for creating graphical interface javax.swing—contains classes for creating graphical interface

Java Programs Two types of Java Programs (both use the same syntax). Two types of Java Programs (both use the same syntax). Applications—general programs that executes on any computer (with a Java Virtual Machine) Applications—general programs that executes on any computer (with a Java Virtual Machine) Applets—designed to run in a Web page. Applets—designed to run in a Web page. In Java, every program unit is a class, even the main program. In Java, every program unit is a class, even the main program. In a Java program, one class must contain a method named main(). In a Java program, one class must contain a method named main().

Simple Greeting Source code Source code Source code Source code Note Note Import javax.swing.JOptionsPane;--for input panel Import javax.swing.JOptionsPane;--for input panel Class name SimpleGreeting—file must be saved as SimpleGreeting.java. Class name SimpleGreeting—file must be saved as SimpleGreeting.java. Method main()—starts the program Method main()—starts the program SimpleGreeting greet = new SimpleGreeting();-- instantiates an object SimpleGreeting greet = new SimpleGreeting();-- instantiates an object greet.greeting();--method call greet.greeting();--method call System.exit(0);--terminate program when window is closed System.exit(0);--terminate program when window is closed

Greeting with Current Time Source code Source code Source code Source code Note Note Import statements—uses three library classes Import statements—uses three library classes GregorianCalendar today;--declaration of object GregorianCalendar today;--declaration of object today = new GregorianCalendar();--instantiation (creation) of object. today = new GregorianCalendar();--instantiation (creation) of object.