University of Central Florida COP 3330 Object Oriented Programming

Slides:



Advertisements
Similar presentations
Classes & Objects Computer Science I Last updated 9/30/10.
Advertisements

OBJECT-ORIENTED PROGRAMMING CONCEPTS (Review). What is an Object? What is an Object? Objects have states and behaviors. Example: A dog has states - color,
Road Map Introduction to object oriented programming. Classes
Classes and Objects in Java. What Is an Object?. An object is a software bundle of related state and behavior. Software objects are often used to model.
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;
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
EEC-681/781 Distributed Computing Systems Java Tutorial Wenbing Zhao Cleveland State University
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object-oriented Programming Concepts
Terms and Rules Professor Evan Korth New York University (All rights reserved)
1 Pertemuan 6 Object Oriented Programming Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Object-Oriented Programming Concepts
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Object-oriented programming and software development Lecture 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
CSCE 2013L: Lab 1 Overview  Java Basics The JVM Anatomy of a Java Program  Object-Oriented Programming Overview  Example: Payroll.java JDK Tools and.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Object Oriented Programming Concepts. Object ► An object is a software bundle of related state and behavior. ► Software objects are often used to model.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 4.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 5 Introduction to Defining Classes
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
By : Robert Apeldorn. What is OOP?  Object-oriented programming is a programming paradigm that uses “objects” to design applications and computer programs.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Object and Classes อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 3.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
BY:- TOPS Technologies
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Introduction to Object-oriented Programming
Modern Programming Tools And Techniques-I
Programming paradigms
Inheritance and Polymorphism
University of Central Florida COP 3330 Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Can perform actions and provide communication
Introduction to Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
Interface.
Interfaces.
Inheritance Inheritance is a fundamental Object Oriented concept
Applying OO Concepts Using Java
COP 3330 Object-oriented Programming in C++
Object-Oriented Programming
Object Oriented Programming in java
Introducing Java.
Selenium WebDriver Web Test Tool Training
Object-Oriented PHP (1)
Chapter 11 Inheritance and Encapsulation and Polymorphism
ITE “A” GROUP 2 ENCAPSULATION.
CSG2H3 Object Oriented Programming
Presentation transcript:

University of Central Florida COP 3330 Object Oriented Programming

Agenda Administrative Key terminology lecture

Introduction to Object Oriented Technology Lecture

Key Terminology Object Class Inheritance Interface Package

Object What Is an Object? An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. Real-world objects share two characteristics: They all have state and behavior. State and behavior are intimately related

Object State is represented in object-oriented programming in the form of attributes called instance variables Instance variables are also known as member variables or fields Specific to the object they are representing

Object Behavior is represented in object-oriented programming in the form of task performance called methods methods should be specific to performing a very a task Update the state of a member variable Perform data analysis method call Calling a method tells the program to perform the tasks defined in the method

Object Dogs have state Dogs have behavior Name Color Breed Hungry Barking Fetching Wagging tail

Object Why objects? Software objects provide Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system. Information-hiding: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.

Object Code re-use: If an object already exists, you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code. Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.

Class What Is a Class? A class is the blueprint from which individual objects are created. A class models the state and behavior of a real-world object. In object-oriented terms that blueprint is an instance of the class of objects. Example: Dog public class Dog { // state using instance variables // also know as member variables String name; boolean hungry; // behavior using methods that can // be called public boolean isHungry() return hungry; } public void setName(String name) this.name = name;

Class How do we know it’s a class? Keyword class Name starts with an uppercase letter public class Dog { // state using instance variables // also know as member variables String name; boolean hungry; // behavior using methods that can // be called public boolean isHungry() return hungry; } public void setName(String name) this.name = name;

Class I only know C, how does it correlate? A class is like a struct, with it multiple variables Instead of functions being outside of the struct, they would be inside the struct Combine variables plus functions defined in a struct is a class in Java #include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }*head; // Function prototypes void append(int num); void add( int num ); void addafter(int num, int loc); void insert(int num); int delete(int num); void display(struct node *r); int count(); // main function int main() }

Object Encapsulation Classes and the objects created from them encase their attributes and methods (i.e. state and behavior) Objects can communicate with one another however how objects are implemented is not made public, in other words the details are hidden, hence information-hiding Do you really care how an ATM works as long as it gives you money????

Object What does “public” mean? How are details hidden? Public refers to what is called access level modifiers Java has public, protected, private, and default Anyone can access something is public How are details hidden? Use the private access level modifier Only the class itself can access something that is private More detailed discussion later!

Instantiation What Is Instantiation? What is an Instance? Creating an object of the defined class Dog puppy = new Dog(); Dog is the defined class new is the keyword to create the object Dog() is called a no-argument constructor which allocates the memory for the object What is an Instance? The created object is an instance of the class puppy is an instance of class Dog public class KeyTerminology { public static void main(String[] args) { // this is a declaration Dog dog; // this is instantiation // it calls the constructor and // allocates memory Dog puppy = new Dog(); } Declarations do not allocate memory therefore it is not an object or instance yet! = new Dog() is just like the malloc() in C, memory is being allocated!

Inheritance What Is Inheritance? Creating a new class using an existing class Inheritance provides a powerful and natural mechanism for organizing and structuring software. Classes inherit state and behavior from their superclasses public class Dog { private int age; private String breed; private String name; private String activity; private boolean hungry; public boolean isHungry() return hungry; } public void setName(String name) this.name = name;

Inheritance What Is Inheritance? The new class is a subclass Classes can be derived from another using the keyword extends followed by the superclass’s name public class SubclassDog extends Dog{ /* inherited from superclass Dog private int age; private String breed; private String name; private String activity; private boolean hungry; */ // extras unique to SubclassDog private boolean swimmer; private boolean barks; private boolean searchAndRescue; }

Inheritance Different kinds of objects often have a certain amount in common with each other. yet each also defines additional features that make them different Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

Inheritance The subclass has all the same fields and methods as the superclass Allows the subclass’s code to focus exclusively on the features that make it unique. Makes code for subclasses easy to read. Be sure to properly document the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass.

Inheritance In Java each class is allowed to have one direct superclass each superclass has the potential for an unlimited number of subclasses

Interface What Is an Interface? Collection of related methods that tell objects what to do but now how to do it They are just like function prototypes in C! An interface is a contract between a class and the outside world. #include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }*head; // Function prototypes void append(int num); void add( int num ); void addafter(int num, int loc); void insert(int num); int delete(int num); void display(struct node *r); int count(); // main function int main() }

Interface public interface IDog { public void run(); public void fetch(); public void sleep(); public void eat(); } When a class implements an interface, it promises to provide the behavior published by that interface In its most common form, an interface is a group of related methods with empty bodies. To implement this interface use the keyword implements in the class declaration. public class DogTwo implements IDog { @Override public void run() {} public void fetch() {} public void sleep() {} public void eat() {} }

Interface Implementing an interface allows a class to become more formal about the behavior it promises to provide If a class implements an interface, all methods defined by that interface must appear in its source code before the class will successfully compile A class can implement zero or more interfaces

Package What Is a Package? A package is a namespace for organizing classes and interfaces in a logical manner. Placing code into packages makes large software projects easier to manage. The Application Programming Interface (API) provided by the Java platform has many packages.

File system view In Netbeans each project has a standard structure, the directories include: build dist nbproject src

File system view build dist Compiled Java source code files File extension is .class Class files are used during runtime dist An executable compressed version of the class files for distribution Command to run is “java –jar BattleshipGame.jar” Can also double-click the .jar file

File system view nbproject src Netbeans specific files Do not modify Source code files File extension is .java