3C-1 Purity Typing Language semantics Inheritance model  Single vs. Multiple inheritance  Common root Modular mechanisms Generics Object Oriented Languages.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Type Checking.
ITEC200 – Week03 Inheritance and Class Hierarchies.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Generics. 2 The Dark Ages: Before Java 5 Java relied only on inclusion polymorphism  A polymorphism code = Using a common superclass Every class.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Abstract Data Types and Encapsulation Concepts
Types in programming languages What are types, and why do we need them? Types in programming languages1.
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
Java Programming Review (Part I) Enterprise Systems Programming.
OOP Languages: Java vs C++
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Programming Languages
COSC 1P03 Data Structures and Abstraction 4.1 Abstract Data Types The advantage of a bad memory is that one enjoys several times the same good things for.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
Object Oriented Programming: Java Edition By: Samuel Robinson.
Predefined Classes in Java Ellen Walker CPSC 201 Data Structures Hiram College.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
1 COSC3557: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
1 Object Oriented Programming OOP: Many things to many people Some common elements –Objects = state + behavior –Interfaces –Classes –Subtyping, polymorphism.
Introduction to Object Oriented Programming CMSC 331.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Types in programming languages1 What are types, and why do we need them?
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Abstract Classes and Interfaces Chapter 9 CSCI 1302.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
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 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Session 24 Chapter 12: Polymorphism. Polymorphism polymorphism comes from the Greek root for “many forms” polymorphism is about how we can use different.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
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.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
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 How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
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.
Object Oriented Programming CMSC 331. Concept of Abstraction “An abstraction is a view or representation of an entity that includes only the attributes.
Dr. M. Al-Mulhem Introduction 1 Chapter 6 Type Systems.
Programming in Java: lecture 7
Java Primer 1: Types, Classes and Operators
CS230 Tutorial Week 3.
Java Programming Language
Java Programming Language
Chapter 8 Class Inheritance and Interfaces
Lecture 10 Concepts of Programming Languages
Subtype Substitution Principle
Presentation transcript:

3C-1 Purity Typing Language semantics Inheritance model  Single vs. Multiple inheritance  Common root Modular mechanisms Generics Object Oriented Languages Comparison

3C-2Purity Little smalltalk: Pure object oriented All predefined types are classes Exception: Integer x <- 4 y<- 2+2 a<- List new; add: 1 b<- List new; add: 1 What is the result of the following : ( hint: == for reference equality, = for value equality ) x == y x = y a == b a = b All user defined types are classes All operations are messages to objects No global functions

3C-3 Purity – Cont. Java: Almost pure object oriented Not all predefined types are classes Primitive types: int, long, float, double, boolean … Primitives have wrapper classes they can be boxed in: m_employees.put( new Integer(employee.getNumber()), employee); All user defined types are classes Not all operations are messages to objects basic arithmetic are built-in operators flow control blocks ( if, … ) No global functions

3C-4 Purity – Cont. C++: Not pure object oriented Not all predefined types are classes Primitive types: int, long, float, double, bool … No built-in wrapper classes Not all user defined types are classes typedef union Not all operations are messages to objects Global functions are allowed The reason: C compatibility.

3C-5 Type System Little smalltalk: Dynamic typing – type rules are enforced at runtime Variables have no associated types Values of different types may be assigned to a single variable Strong typing The relation between a value and its type can ’ t be changed Java: Static typing – compile-time type checking Strong typing C++: Static typing Weak typing Implicit type conversion by the compiler Relation between a value and its type can be broken

3C-6 Type System – Cont. Examples: u What is the value of y in the following code: l double x = 2.3; l int y = x; u C++ : 2 l Implicit conversion by the compiler u Java: compilation error !! l No conversion from double to int u What about LST ? ( hint: think how to write this code in LST )

3C-7 Language Semantics Little smalltalk: reference semantics Dynamic typing prevents from determining the size Java: reference semantics Exception: Primitives (value semantics) class myClass{ private int x; private Integer y; private Double z; myClass(){ y = new Integer(3); x = 3; int yValue = y. intValue (); // yValue = 3 double zValue = z. doubleValue(); // runtime error!! } Note the difference between objects and primitives

3C-8 Language Semantics – Cont. C++: Value semantics by default (C compatibility) Reference semantics on reference types int a = 5; int b = 6; int& iRef = a; iRef = b; What is the value of iRef? What is the value of a?

3C-9 Class Hierarchy Little smalltalk: Single inheritance of both interface and implementation class hierarchy with one common root class What does the following class do? Class mystery Object l Methods mystery new l <- List new. | DoIt : aClass l add: aClass. (aClass superClass notNil) ifTrue: [self DoIt :(aClass superClass)] ]

3C-10 Class Hierarchy – Cont. Java inheritance mechanisms: Single inheritance of combination of implementation and subtype (using extends keyword) Multiple subtype (interface) inheritance (using implements keyword). class hierarchy with one common root class class Employee2 extends Employee, implements Serializable, Comparable { … } What methods are inherited? What methods must be implemented?

3C-11 Class Hierarchy – Cont. C++: Multiple inheritance is allowed No common root class for all classes Person Student Teacher TA

3C-12 Modularity Mechanisms Little smalltalk: no modularity is required Source code can reside in one file or multiple files Java: modularity mechanisms One top-level class per source file It is possible to define inner classes within the top-level class Name of class must match the file name Packages – a mechanism for organizing classes into namespaces. The package is determined by the directory where the source file is located => Subdirectories create nested packages C++ Classes can be organized in name spaces Nesting of namespaces is obtained by defining a namespace within a namespace A class can spawn multiple files A file can contain multiple classes

3C-13Generics Generics - ability to have type parameters on a type AKA parametric polymorphism Little smalltalk: no special genericity support Dynamically typed languages support generic programming inherently. Java: Generics were introduce in JDK 1.5 Allows creating generic data structures and algorithms C++ Templates: A very powerful, Turing complete mechanism