Object Oriented Programming: Java Edition By: Samuel Robinson.

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Advertisements

MT311 (Oct 2007) Java Application Development Object-Oriented Programming Languages Tutorial 8.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Chapter 12: Support for Object-Oriented Programming
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Chapter 10 Classes Continued
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 12 Topics Introduction Object-Oriented Programming.
OOP Languages: Java vs C++
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Programming Languages and Paradigms Object-Oriented Programming.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Programming Languages and Paradigms Object-Oriented Programming.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Introduction to Object Oriented Programming CMSC 331.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Parameters… Classes Cont Mrs. C. Furman October 13, 2008.
Inheritance The Basics in Java. Definition  A class that is derived from another class is called a subclass (also a derived class, extended class, or.
Programming in Java CSCI-2220 Object Oriented Programming.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Object-Oriented Programming Chapter Chapter
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
ISBN Object-Oriented Programming Chapter Chapter
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Inheritance 2 Mehdi Einali Advanced Programming in Java 1.
COM S 228 Introduction to Data Structures Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Inheritance ndex.html ndex.htmland “Java.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
ISBN Chapter 12 Support for Object-Oriented Programming.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
BY:- TOPS Technologies
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Design issues for Object-Oriented Languages
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
Java Programming Language
Polymorphism and access control
Java Programming Course
Support for Object-Oriented Programming
Lecture 10 Concepts of Programming Languages
Chapter 11 Inheritance and Encapsulation and Polymorphism
Topics OOP Review Inheritance Review Abstract Classes
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Computer Science II for Majors
Presentation transcript:

Object Oriented Programming: Java Edition By: Samuel Robinson

Intro In order for a language to be Object Oriented, it must support abstract data types, inheritance, and dynamic binding. Along with these 3 features, the language should also support classes, objects, instances, abstraction, encapsulation, polymorphism, etc. basically the fundamental features of OOP. Java has these.

Classes and Objects All Java classes are either subclasses of the Object root class or a class that is descendant of Object. Java supports objects and non object data. Enumerations and Arrays are objects, but the values of primitive scalar types are not. All objects are explicit heap dynamic.

Object Exclusivity Primitive types such as int and double are not objects, but it is possible to manipulate them like objects. This is possible with wrapper classes, which contain one of the primitive types, which then allow for the creation of objects that represent primitive types. Certain operations are only possible this way

Examples System.out.println(Integer.toBinaryString(4)); – Returns 100 System.out.println(Integer.toHexString(16)); – Returns 10 int x = Integer.parseInt(“9”) returns 9 double c = Double.parseDouble(“5”) returns 5.0

Initialization of Objects Constructors Instance variable initialization Instance initialization Default value

Constructor class Demo { int a; public Demo() { // the initialization code for instance variables a=0; }

Instance Variable Initialization class Demo { private int a = 1; //this evaluates a with a value of 1 }

Instance Initialization class Demo { private int a; //initializer { a=2; }

Inheritance Direct support for single inheritance, partial support for multiple. Single Inheritance is done by using the extends keyword, multiple inheritance is done by using an interface.

Single Inheritance Public class Vehicle{ Int licensenum; Void getlicenseplate(int licensenum){ } Class Car extends Vehicle{ Int numofDoors; } Car SomeCar = new Car(); SomeCar. NumofDoors; SomeCar.licenseplatenum;

Multiple Inheritance Public interface Relatable { Public int isLargerthan (Relatable other); } Public class triangle implements Relatable { Public int base = 0; Public int height = 0; //other stuff and classes Public int getArea(){ return (base * height) / 2; } triangle otherTri = (triangle)other; if(this.getArea() < otherTri.getArea()) return -1; //and so on

Dynamic Binding All method calls are dynamically bound unless the method was defined as final, static or private. These 3 keywords prevent overriding.

Subclasses A Java subclass is a subtype only if there is a declared relationship (extends or implements) and for each method in the first one, there is a corresponding method in the other

Example public class Animal { public static void hide() { System.out.println("The hide method in Animal."); } public void override() { System.out.println("The override method in Animal."); } public class Cat extends Animal { public static void hide() { System.out.println("The hide method in Cat."); } public void override() { System.out.println("The override method in Cat."); } public static void main(String[] args) { Cat myCat = new Cat(); Animal myAnimal = (Animal)myCat; myAnimal.hide(); myAnimal.override(); }

Type Checking and Polymorphism Static type checking Example of polymorphism: /IandI/polymorphism.html

Object Allocation/Deallocation All objects are explicit heap dynamic. From the heap, most of allocated with the new operator, but there is no explicit deallocation operator (garbage allocation). Problem: If an object has access to a resource other than heap memory, garbage collection won't catch it (closing a file). Use finalize

Example protected void finalize() throws Throwable { try { close(); // close open files } finally { super.finalize(); }

Nested Classes Inner classes – nonstatic, have an implicit pointer to the nesting class. – An instance of a nested class can only exist within an instance of its nesting class Local nested class – defined in a method of its nesting class. – Never defined with an access specifier – A method in this class can access variables defined in its nesting class and final variables defined in the method in which the local nested class is defined