Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.

Slides:



Advertisements
Similar presentations
Introduction to classes Sangeetha Parthasarathy 06/11/2001.
Advertisements

Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
1 Object-Oriented Programming OOP. 2 Object-oriented programming is a new paradigm for program development in which the focus is on the data instead of.
Classes & Objects Computer Science I Last updated 9/30/10.
Introduction to Object Oriented Programming Java.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
HST 952 Computing for Biomedical Scientists Lecture 2.
Object-Oriented Programming Concept. Concepts of Object Orientation Objects and classes. method Message passing Inheritance.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Object-oriented Programming Concepts
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-1 Thinking in Objects u Analogies: Legos, PCs u Components u Assemblies u Defined interfaces.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
C++ fundamentals.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Abstraction, Inheritance, and Polymorphism in Java.
Inheritance using Java
Object-Oriented Programming Concepts
Programming Languages and Paradigms Object-Oriented Programming.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
Introduction to Object-oriented programming and software development Lecture 1.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
: Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Object Oriented Programming
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Inheritance ndex.html ndex.htmland “Java.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Object-Oriented Programming
JAVA By Waqas.
Objects as a programming concept
Chapter 11 Object-Oriented Design
COMPUTER 2430 Object Oriented Programming and Data Structures I
OOP What is problem? Solution? OOP
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Object Oriented Analysis and Design
Object-Oriented Programming
Week 6 Object-Oriented Programming (2): Polymorphism
Software Design Lecture : 12.
Object-Oriented Programming
Chapter 9 Carrano Chapter 10 Small Java
Object-Oriented Programming
By Rajanikanth B OOP Concepts By Rajanikanth B
Programming For Big Data
Topics OOP Review Inheritance Review Abstract Classes
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Presentation transcript:

Object Oriented Programming in Java

Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for software, where the program is structured according to the information it manipulates, rather than the operations it does. Data, not procedures, shape the program.

What is an Object ? An Object is defined as a software package that incorporates a set of related data and all the functions needed to manipulate this data. The related set of data, the data members, captures the state of an object.

Defining Objects : STATE (Attributes) Encompasses all of the properties of an object. Each property has a value. All objects of the same type have same properties ( although they may have different values). Properties are implemented with Object Variables or instance variables.

A motorcycle class might include the following attributes and have these typical values: color : red, green, silver, brown style : cruiser, sport bike, standard Make : Honda, BMW, Bultaco Here color, style, make are the instance variables. Example :

Defining Objects : BEHAVIOR Is how an object reacts, in terms of state changes and interaction with the other objects. Behavior is the only way objects can do anything to themselves or have anything done to them.

A motorcycle class might have some behavior like: Start the engine Stop the engine Speed up Change gear Stall Example :

Defining Objects : BEHAVIOR The behavior is defined by the use of functions which are confined to a Class and are called member functions or Methods.

Classes A class is a set of objects that share the same properties and behavior. Its where state and behavior of objects is defined through Variables and Methods. Example: Every Motorcycle is defined in the Motorcycle class.

class Motorcycle { String make; String color; boolean enginestate = false; void startEngine() { if (enginestate = = true) Example of the Motorcycle Class

System.out.println (“The engine is already on”) else { enginestate = true; System.out.println ( “The engine is now on”); }

public static void main (String args[] ) { Motorcycle m = new Motorcycle(); m.make = “Yamaha RZ350”; m.color = “Yellow”; System.out.println(“Calling showAtts…”); m.showAtts(); The main() method for Motorcycle class

System.out.println (“………………”); System.out.println(“Starting Engine …”); m.startEngine(); System.out.println (“………………”); System.out.println(“Calling showAtts…”); m.showAtts(); System.out.println (“………………”); System.out.println(“Starting Engine …”); m.startEngine(); }

class Motorcycle { String make; String color; boolean enginestate = false; void startEngine() { if (enginestate = = true) System.out.println (“The engine is already on”) The final version of Motorcycle.java file

else { enginestate = true; System.out.println ( “The engine is now on”); } void showAtts () { System.out.println (“This motorcycle is a” +color+ “ ” +make);

if (engineState = = true) System.out.println (“The engine is on.”); else System.out.println (“The engine is off.”); } public static void main (String args[] ) { Motorcycle m = new Motorcycle(); m.make = “Yamaha RZ350”; m.color = “Yellow”;

System.out.println(“Calling showAtts…”); m.showAtts(); System.out.println (“………………”); System.out.println(“Starting Engine …”); m.startEngine(); System.out.println (“………………”); System.out.println(“Calling showAtts…”);

m.showAtts(); System.out.println (“………………”); System.out.println(“Starting Engine …”); m.startEngine(); } }

The three major concepts in OOP are: Encapsulation Inheritance Polymorphism

Encapsulation Embedding both data and code into a single entity. Allows us to use data hiding which is a way to prevent direct access to the variables in an object. Separates the interface to the class from its implementation.

Class Flight { int altitude; private int heading; int speed; float latitude; float longitude; // change the flight’s heading by angle degrees void turnFlight (int angle) { heading = (heading + angle) % 360; // make sure angle is in the range degrees if (heading < 0) heading = heading + 360; }

void setHeading (int angle) { heading = angle % 360; // make sure angle is in the range degrees if (heading < 0) heading = heading + 360; } int getHeading( ) { return heading; } // print information about the flight void printFlight () { System.out.println(altitude + “ / ” + heading + “ / ” + speed); }

Inheritance Inheritance is the process by which one object acquires the properties of another object.

Benefits of Inheritance Subclasses provide specialized behaviors from the basis of common elements provided by the superclass. Through the use of inheritance, programmers can reuse the code (in the superclass) many times. Programmers can implement superclasses called abstract classes that define “generic” behaviors. The abstract superclass defines and may partially implement the behavior but much of the class is undefined and unimplemented. Other programmers fill in the details with specialized subclasses.

Example of Inheritance class CommercialFlight extends Flight { // extra members in CommercialFlight int flightNumber; int passengers; }

The Commercial Flight Class inherits member variables and functions from Flight, and then adds its own member variables.

Polymorphism Polymorphism is the ability of a single function name to be used to operate on many different types. It is a feature that allows one interface to be used for a general class of actions. The specific action is determined by the exact nature of the situation.

Polymorphism We can deal with objects without the need to know what exact class they belong to. This is an extension of the inheritance concept.