Class 14: Object-Oriented Programming Fall 2010 University of Virginia David Evans cs2220: Engineering Software.

Slides:



Advertisements
Similar presentations
1 Exceptions: An OO Way for Handling Errors Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software.
Advertisements

A Programmer's Introduction to Java - from a S/370 user (c) IDMS/SQL News
Java Programming Abstract classes and Interfaces.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 20: Hair Dryer Attacks Image.
Software Engineering Implementation Lecture 3 ASPI8-4 Anders P. Ravn, Feb 2004.
Cs2220: Engineering Software Class 10: Generic Datatypes Fall 2010 University of Virginia David Evans.
Yoshi
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 16: Concurrent Programming.
Cs2220: Engineering Software Class 2: Introduction Java Fall 2010 University of Virginia David Evans.
Java Generics.
Introduction to Java Kiyeol Ryu Java Programming Language.
Generic types for ArrayList Old Java (1.4 and older): ArrayList strings = new ArrayList(); strings.enqueue(“hello”); String word = (String) strings.get(0);
Introduction to Java Programming, 4E
Outline Java program structure Basic program elements
How is Java different from other languages Less than you think: –Java is an imperative language (like C++, Ada, C, Pascal) –Java is interpreted (like LISP,
CS884 (Prasad)Java Goals1 “Perfect Quote” You know you've achieved perfection in design, Not when you have nothing more to add, But when you have nothing.
Generic Java 21/ What is generics? To be able to assign type variables to a class These variables are not bound to any specific type until the.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
JAVA v.s. C++ Programming Language Comparison By LI LU SAMMY CHU By LI LU SAMMY CHU.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Introduction to Java Programming with JBuilder 4
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
What is an exception? An exception is: – an event that interrupts the normal processing of the program. –an error condition that violates the semantic.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Effective Java: Generics Last Updated: Spring 2009.
May 9, 2002Serguei A. Mokhov, 1 Kickstart Intro to Java Part I COMP346/ Operating Systems Revision 1.6 February 9, 2004.
Introduction to Java Programming with Forte Y. Daniel Liang.
Core Java: Essential Features 08/05/2015 Kien Tran.
Java for C++ Programmers Clint Jeffery University of Idaho
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
Cs2220: Engineering Software Class 6: Defensive Programming Fall 2010 University of Virginia David Evans.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 12: Subtyping Rules What’s the.
Computer Programming 2 Why do we study Java….. Java is Simple It has none of the following: operator overloading, header files, pre- processor, pointer.
We will talking about story of JAVA language. By Kristsada Songpartom.
Types in programming languages1 What are types, and why do we need them?
Cs205: engineering software university of virginia fall 2006 Introducing Java David Evans Don’t forget to your registration.
GENERICS AND THE JAVA COLLECTIONS FRAMEWORK Lecture 16 CS2110 – Fall 2015 Photo credit: Andrew Kennedy.
Generic(Parameterized ) types Mehdi Einali Advanced Programming in Java 1.
Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 18: Code Safety and Virtual Machines
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 9: Designing Exceptionally.
Cs2220: Engineering Software Class 12: Substitution Principle Fall 2010 University of Virginia David Evans.
Cs2220: Engineering Software Class 13: Behavioral Subtyping Fall 2010 University of Virginia David Evans.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Cs205: engineering software university of virginia fall 2006 Programming Exceptionally David Evans
1 Chapter 21 Generics. 2 Objectives F To use generic classes and interfaces (§21.2). F To declare generic classes and interfaces (§21.3). F To understand.
Subtying Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
Cs205: engineering software university of virginia fall 2006 David Evans Object-Oriented Programming.
JAVA GENERICS Lecture 16 CS2110 – Spring 2016 Photo credit: Andrew Kennedy.
Introduction to Java Programming, 4E Y. Daniel Liang.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Chapter No. : 1 Introduction to Java.
CS216: Program and Data Representation
Java Programming Language
Lecture 15: Using Low-Level Languages CS201j: Engineering Software
Code Magnets problem for wk5
Subtyping Rules David Evans cs205: engineering software BlackBear
Concurring Concurrently
Security in Java Real or Decaf? cs205: engineering software
Lecture 9: Exceptions in Java CS201j: Engineering Software
Units with – James tedder
Units with – James tedder
Lecture 13: Subtyping Rules Killer Bear Climber
Presentation transcript:

Class 14: Object-Oriented Programming Fall 2010 University of Virginia David Evans cs2220: Engineering Software

Menu Subtyping with Parameterized Types – Arrays – Generics “Object-Oriented Programming”

Subtyping and Arrays Does B  A imply B[]  A []?

Array Subtyping static public Object getFirst (Object [] els) throws NoSuchElementException { if (els == null || els.length == 0) { throw new NoSuchElementException (); } else { return els[0]; } static public void main (String args[]) { try { Object o = getFirst (args); System.err.println ("The first parameter is: " + o); } catch (NoSuchElementException e) { System.err.println ("There are no parameters!"); }

Array Store static public void setFirst (Object [] els) throws NoSuchElementException { if (els == null || els.length == 0) { throw new NoSuchElementException (); } else { els[0] = new Object (); } static public void main (String args[]) { try { Object o = getFirst (args); System.err.println ("The first parameter is: " + o); setFirst (args); } catch (NoSuchElementException e) { System.err.println ("There are no parameters!"); } > javac TestArrays.java > java TestArrays test The first parameter is: test Exception in thread "main" java.lang.ArrayStoreException at TestArrays.setFirst(TestArrays.java:16) at TestArrays.main(TestArrays.java:25) > javac TestArrays.java > java TestArrays test The first parameter is: test Exception in thread "main" java.lang.ArrayStoreException at TestArrays.setFirst(TestArrays.java:16) at TestArrays.main(TestArrays.java:25)

Java’s Array Subtyping Rule Static type checking: B <= A  B[] <= A[] Need a run-time check for every array store to an array where the actual element type is not known What would be a better rule?

Generic Subtyping Does B  A imply T  T ?

Generic Subtyping: Novariant List as; List ao; ao = as; as = ao; Type mismatch: cannot convert from List to List

Wildcard Types! List ag; ag = ao; ag = as; String s = ag.get(0); Type mismatch: cannot convert from capture#3-of ? extends Object to String

Buzzword Description “A simple, object-oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, and dynamic language.” [Sun95] As the course proceeds, we will discuss how well it satisfies these “buzzwords”. You should especially be able to answer how well it satisfies each of the blue ones in your final interview. from Class 2...