Advances in Programming Languages: Type accuracy

Size: px
Start display at page:

Download "Advances in Programming Languages: Type accuracy"

Transcription

1 Advances in Programming Languages: Type accuracy Stephen Gilmore The University of Edinburgh January 29, 2007 Introduction Strongly typed programming languages catch programmer errors, leading to program code of higher quality. Static type-checking finds type errors at compile-time, which is the ideal time to find them. Dynamic type-checking traps type errors at run-time, preventing erroneous programs from continuing past the first occurrence of an obvious mistake. Most strongly typed languages use a combination of static and dynamic type-checking. The extent to which a strongly-typed programming language is useful depends on the accuracy of its type system, which is a measure of its ability to describe data well. Java s generics have made its type system more accurate because it is now possible to differentiate homogeneous collections from heterogeneous collections and to represent concepts such as generic ordered lists. To further emphasise the difference between strongly typed and accurately typed consider Stringy, a (fictional) programming language with only one type, string. In the Stringy API all functions take strings as arguments and return strings as results. The same is true for all built-in operators of the language. Thus, it is not possible to use a data value in a way not allowed by its type (because the language as only one type). However, the type system of the Stringy language is very inaccurate. We represent integers as strings, booleans as strings, arrays as strings, and so forth, where we would rather have values of these types be separated. Thus every function which would like to receive an integer must be prepared to deal with non-integers, every function on arrays prepared to deal with non-arrays, and similarly. This represents a significant extra burden for developers who must write additional code to check and re-check types. (Experience tells us that they probably will not write additional code for this.) Stringy sounds like a terrible programming language but weakly-typed programming languages are not very different from Stringy. Developers need to write code to check and re-check types or, more likely, they assume that their data is type-correct when in practice it is not. The impetus towards improving the accuracy of type systems is an advance in programming languages. Describing the data more accurately causes developers to have to write fewer routines to validate data. Accuracy and loss of accuracy Object-oriented languages lose accuracy when the type of an object is coerced up the class hierarchy in order to match the type specified for a formal parameter for a method. When the class B is a subclass of A then it is not wrong to describe an object instance of class B as an A but it is less accurate than describing it as an instance of B. This loss of accuracy can cause run-time type errors. Consider the following Java program. 1

2 UG4 Advances in Programming Languages 2005/ /* File: programs/java/ooarrays.java */ public class OOArrays { static void assignfirst(object[] a) { a[0] = new Object(); if (args.length == 0) { System.out.println("usage: java OOArrays strings"); System.exit(1); assignfirst(args); System.out.println(args[0]); The above program compiles without warnings. In Java, String is a subclass of Object, meaning that String[] is a subclass of Object[], because of Java s covariant rule for arrays. Unfortunately the preceding Java program will fail at run-time with an ArrayStoreException (which is simply a type error). The command java OOArrays a b c produces this result. Exception in thread "main" java.lang.arraystoreexception: java.lang.object at OOArrays.assignFirst(OOArrays.java:4) at OOArrays.main(OOArrays.java:11) Thus, Java achieves type safety by a combination of static and dynamic type-checking. The benefit is that the language is type-safe, which is a huge gain. The disadvantage is that every array store incurs the cost of a bounds check on the index and a run-time type check on the object being stored. The former penalty is relatively common in strongly-typed languages with arrays but the cost of the second is due only to the loss of accuracy caused by coercing up the class hierarchy. C# arrays are covariant Like Java, C# uses a covariant rule for typing arrays, with the consequence that the following program is passed by the compiler. /* File: programs/cs/ooarrays.cs */ using System; class OOArrays { static void assignfirst(object[] a) { a[0] = new object(); static void Main(string[] args) { if (args.length == 0) { Console.WriteLine("usage: mint OOArrays strings"); Environment.Exit(-1); assignfirst(args);

3 UG4 Advances in Programming Languages 2005/ Console.WriteLine(args[0]); However, it too fails at run-time. Unhandled Exception: System.ArrayTypeMismatchException: Source array type cannot be assigned to destination array type #0: 0x00007 stelem.ref in.ooarrays::assignfirst #1: 0x00019 call in.ooarrays::main Generic types and covariance Generic types were introduced into Java to reduce the number of type-related errors which can occur at run-time. Java 1.5 includes a generic collection class which presents an array as a list, java.util.arraylist<e>. The methods in java.util.arraylist<e> include boolean add(e o); E get(int index); E set(int index, E element); Does this mean that we can reproduce the ArrayStoreException fault with a generic ArrayList? The following program tests this. /* File: programs/java/genericarraylist.java */ import java.util.arraylist; public class GenericArrayList { static void assignfirst(arraylist<object> ao) { ao.set(0, new Object()); ArrayList<String> as = new ArrayList<String>(); as.add("first"); assignfirst(as); System.out.println(as.get(0)); This program is (correctly) rejected by the Java 1.5 compiler. GenericArrayList.java:11: assignfirst(java.util.arraylist<java.lang.object>) in GenericArrayList cannot be applied to (java.util.arraylist<java.lang.string>) assignfirst(as); 1 error

4 UG4 Advances in Programming Languages 2005/ Generic classes are non-variant Generic classes are neither covariant nor contravariant. They are non-variant. There is no implicit super- or sub-type relationship between type parameters. That is, if B is a subclass of A and C<E> is a generic class then neither is C<B> a subclass of C<A> nor is C<A> a subclass of C<B>. Just to indicate that there is nothing special about built-in classes such as java.util.arraylist, we can implement our own simple array list, and show that it too is non-variant. /* File: programs/java/myarraylist.java */ public class MyArrayList<E> { private E[] data; public MyArrayList(int len) { // generates an unchecked cast warning data = (E[]) new Object[len]; public E get(int index) { return data[index]; public void set(int index, E e) { data[index] = e; We now attempt to use our array list class in a context where a covariant typing rule would be needed. /* File: programs/java/myarraylisttest.java */ public class MyArrayListTest { static void assignfirst(myarraylist<object> ao) { ao.set(0, new Object()); MyArrayList<String> as = new MyArrayList<String>(10); as.set(0, "first"); assignfirst(as); /* illegal */ The above program produces the same class of compilation error as we saw previously. Namely, assignfirst(myarraylist<java.lang.object>) in MyArrayListTest cannot be applied to (MyArrayList<java.lang.String>).

5 UG4 Advances in Programming Languages 2005/ Why generic classes are non-variant In an object-oriented language with a class hierarchy (and a concept of subclass) covariant generic classes would bring the complications which multiple inheritance brings to an objectoriented language. (Java has a single inheritance rule for classes.) Consider the class Stack<Integer>. The generic class Stack<T> extends Vector<T> and so inherits its methods. The Integer class extends Number. What would Stack<Integer> inherit from if Java had a covariant rule for generic classes? Would it be Stack<T> (for T above Integer) or Vector<Integer>? Diamond inheritance problems such as this led users of the C++ language to develop applications which had unexpected and unwanted behaviour due to a different method being invoked at runtime from the one which the developer expected. Generic Java classes are nonvariant to prevent problems such as this occurring. Run-time availability of generics Java s generics are not available at run-time (because of erasure). C# s generics are not erased and hence are available at run-time. We can see the difference between these two approaches if we attempt to test the run-time type of an object (using instanceof in Java and is in C#). /* File: programs/java/instancetest.java */ import java.util.stack; class InstanceTest { Stack<String> s1 = new Stack<String>(); Stack<Object> s2 = new Stack<Object>(); System.out.println(s1 instanceof Stack<String>); System.out.println(s1 instanceof Stack<Object>); System.out.println(s2 instanceof Stack<Object>); This Java program is faulted at compile-time because run-time type information on generic parameters is not available in the JVM. [scap]stg: javac InstanceTest.java InstanceTest.java:9: illegal generic type for instanceof System.out.println(s1 instanceof Stack<String>); InstanceTest.java:9: illegal generic type for instanceof System.out.println(s1 instanceof Stack<Object>); InstanceTest.java:10: illegal generic type for instanceof System.out.println(s2 instanceof Stack<Object>); 3 errors

6 UG4 Advances in Programming Languages 2005/ We now consider the C# version of the above program. /* File: programs/cs/instancetest2.cs */ using System; using System.Collections.Generic; class InstanceTest2 { public static void Main(string[] args) { Stack<string> s1 = new Stack<string>(); Stack<object> s2 = new Stack<object>(); Console.WriteLine(s1 is Stack<string>); // True Console.WriteLine(s1 is Stack<object>); // False Console.WriteLine(s2 is Stack<object>); // True I used Visual Studio 2005 to compile this program. The test in Console.WriteLine(s1 is Stack<object>); is not classed as an error but produces a warning of The given expression is never of the provided ( System.Collections.Generic.Stack<object> ) type. Thus showing that C# generics are non-variant also. The program runs without errors and produces the results True, False and True. Loss of accuracy: raw types Raw types are used in Java to achieve backwards compatability with non-generic code where one ArrayList is just like any other ArrayList. Variables can be given raw types and raw objects can be constructed. The following program assigns a raw type to an ArrayList. /* File: programs/java/rawarraylist.java */ import java.util.arraylist; public class RawArrayList { static void assignfirst(arraylist<object> ao) { ao.set(0, new Object()); ArrayList as = new ArrayList<String>(); // raw type as.add("first"); assignfirst(as); System.out.println(as.get(0)); This program compiles with warnings but runs and allows us to store an object in a class intended to hold strings (as with traditional heterogeneous collections in Java 1.4 and earlier). The program produces output similar to java.lang.object@ad3ba4

7 UG4 Advances in Programming Languages 2005/ In general if we mix raw types in with generic types we may compromise the usefulness of generic type descriptions. /* File: programs/java/weakening.java */ import java.util.date; import java.util.arraylist; public class Weakening { ArrayList<String> as = new ArrayList<String>(); ArrayList oo = new ArrayList(); // OO array list oo.add(new Date()); // warning here as = oo; // warning here also System.out.println(as.get(0)); // fail here [scap]stg: javac -Xlint:unchecked Weakening.java Weakening.java:8: warning: [unchecked] unchecked call to add(e) as a member of the raw type java.util.arraylist oo.add(new Date()); // warning here Weakening.java:9: warning: [unchecked] unchecked conversion found : java.util.arraylist required: java.util.arraylist<java.lang.string> as = oo; // warning here also 2 warnings Having generated warnings when compiled, this program fails at run-time with a class cast exception (casts are automatically inserted by the Java compiler in the compilation process). [scap]stg: java Weakening Exception in thread "main" java.lang.classcastexception: java.util.date at Weakening.main(Weakening.java:10)

8 UG4 Advances in Programming Languages 2005/ Accuracy and parametricity: wildcards Under the non-variance discipline it might seem that we have lost the ability to define parametric methods, because (for example) ArrayList<String> and ArrayList<Date> are not subtypes of ArrayList<Object>. We could resort to raw types but then we would lose the benefits of generic definitions, and we would be back in the OO world of heterogeneous collections. Another idiom is needed to have generic classess and parametric definitions co-exist: wildcards, denoted by?. /* File: programs/java/printarraylist.java */ import java.util.*; public class PrintArrayList { // parametric method: array list of something static void printall (ArrayList<?> a) { // enhanced for loop: "foreach" for (Object o : a) System.out.println(o); ArrayList<String> as = new ArrayList<String>(); as.add("first"); as.add("second"); printall(as); ArrayList<Date> ad = new ArrayList<Date>(); ad.add(new Date()); printall(ad); The above program will compile cleanly and print the list of strings followed by the singleton list containing the current date. To see that the unknown type is not just java.lang.object we can attempt to add object instances of random classes to the collection which we are passed.

9 UG4 Advances in Programming Languages 2005/ /* File: programs/java/querytest.java */ import java.util.*; public class QueryTest { // parametric method: array list of something static void printall (ArrayList<?> a) { // enhanced for loop: "foreach" for (Object o : a) System.out.println(o); // now stuff in a GregorianCalendar a.add(new GregorianCalendar()); // now stuff in an HTMLEditorKit a.add(new javax.swing.text.html.htmleditorkit()); // main method same as before ArrayList<String> as = new ArrayList<String>(); as.add("first"); as.add("second"); printall(as); ArrayList<Date> ad = new ArrayList<Date>(); ad.add(new Date()); printall(ad); This program is (correctly) faulted by the Java compiler. QueryTest.java:12: cannot find symbol symbol : method add(java.util.gregoriancalendar) location: class java.util.arraylist<capture of?> a.add(new GregorianCalendar()); QueryTest.java:14: cannot find symbol symbol : method add(javax.swing.text.html.htmleditorkit) location: class java.util.arraylist<capture of?> a.add(new javax.swing.text.html.htmleditorkit()); 2 errors The wildcard class variable is a qualified type. The compiler places restrictions on the use of?. It can appear in a return type position (and is treated as Object) but it cannot appear in a parameter type position. boolean add(e o); /* cannot call this */ E get(int index); /* can call this */ E set(int index, E element); /* cannot call this */

10 UG4 Advances in Programming Languages 2005/ Passing objects by value and by reference We have seen that loss of accuracy in type descriptions can have bad effects such as giving rise to an ArrayStoreException. In object-oriented languages passing objects to methods with more generous type descriptors (further up the class hierarchy) happens very frequently. One reason why this is allowable in practice, and only rarely a problem is that it is applied only when objects are passed by value, not when they are passed by reference. Java always passes object references by value. That is, the local variable of the method is a separate variable from the actual parameter. The local variable is simply initialised by pointer copy. If we update the local variable then the link to the formal parameter is lost. The local variable is destroyed when the method exits, as always. /* File: programs/java/passbyvalue.java */ public class PassByValue { static void passbyvalue(object o) { o = new java.util.date(); Integer i = new Integer(13); passbyvalue(i); System.out.println(i); // still 13 C# has pass-by-value calling but it also supports pass-by-reference. Under the pass-byreference discipline the local variable is the same variable as the actual parameter. If we update the local variable then the formal parameter changes also. However, to ensure type correctness coercions up the class hierarchy are not allowed by the compiler. The class description of the formal parameter used in the method header must match exactly the class description of the actual parameter when pass-by-reference is used. /* File: programs/cs/passbyref.cs */ using System; class PassByRef { static void passstringbyref(ref string s2) { s2 = "the new, updated string"; static void passobjectbyref(ref object o2) { o2 = new DateTime(); static void Main() { string s = "the original string"; object o = s; Console.WriteLine("s is {0", s); Console.WriteLine("o is {0", o); passstringbyref(ref s);

11 UG4 Advances in Programming Languages 2005/ Console.WriteLine("s is {0", s); Console.WriteLine("o is {0", o); passobjectbyref(ref o); Console.WriteLine("s is {0", s); Console.WriteLine("o is {0", o); It would be a compile-time error to attempt to pass the string s to the method passobjectbyvalue. The C# PassByRef class generates the following output. s is the original string o is the original string s is the new, updated string o is the original string s is the new, updated string o is Monday, 01 January :00:00 Improving accuracy with enumerations Type accuracy is improved whenever we can use a less general type to describe our data (because we rule out some values which we would otherwise have included). An example of this in the context of Java 1.5 is the use of enumerations which list only the values of interest. Before enumerations, fixed collections of values were approximated by integer constants. /* File: programs/java/values.java */ public class Values { /* Values declared as integer constants */ public static class DegreeType { public static final int BSc = 0; public static final int BEng = 1; public static class Class { public static final int Hons = 0; public static final int Ord = 1; public static class Degree { public static final int AI = 0; public static final int AICS = 1; public static final int AISE = 2; public static final int CS = 3; public static final int SE = 4; /* others omitted */

12 UG4 Advances in Programming Languages 2005/ This is a version suitable for Java 1.5 and higher. /* File: programs/java/enumerations.java */ public class Enumerations { enum DegreeType { BSc, BEng; enum Class { Hons, Ord; enum Degree { AI, AICS, AISE, CS, SE; /* others omitted */ for(degreetype dt : DegreeType.values()) for (Class c : Class.values()) for (Degree d : Degree.values()) System.out.println("" + dt + "(" + c + ") in " + d); Summary Implicit coercions up the class hierarchy reduce type accuracy when methods are invoked. In the context of arrays, such coercions can give rise to run-time type errors known as array store exceptions. The applied coercion uses a covariant rule for arrays. Generic classes are neither covariant not contravariant. They are non-variant. Generic type information is erased in Java compilation, but not in C# compilation. Java introduces a wild card? to represent an unknown type parameter. The use of this type is restricted to certain contexts. Implicit coercions on method parameters are not allowed when values are passed by reference. Enumerations improve type accuracy by introducing a new type for a new collection of values.

CSE 331 Software Design and Implementation. Lecture 14 Generics 2

CSE 331 Software Design and Implementation. Lecture 14 Generics 2 CSE 331 Software Design and Implementation Lecture 14 Generics 2 Zach Tatlock / Spring 2018 Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping Using wildcards

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

CSE 331 Software Design and Implementation. Lecture 14 Generics 2

CSE 331 Software Design and Implementation. Lecture 14 Generics 2 CSE 331 Software Design and Implementation Lecture 14 Generics 2 James Wilcox / Winter 2016 Hi, I m James! Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping

More information

CSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA

CSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA CSE 3302 Lecture 7: Polymorphism and generics 16 September 2010 Nate Nystrom UTA 2 Polymorphism poly = many morph = shape Allow a variable to contain values with different types 3 Subtype polymorphism

More information

23. Generics and Adapters

23. Generics and Adapters COMP 401 Prasun Dewan 1 23. Generics and Adapters The term generic implies unspecialized/common behavior. In an object oriented language, it seems to apply to the class Object, which describes the behavior

More information

CSE 8B Intro to CS: Java

CSE 8B Intro to CS: Java CSE 8B Intro to CS: Java Winter, 2006 March 7 (Day 17) ArrayList Generics Class that: works like a resizable array ArrayList Has a current capacity: if you add more elements, it ll allocate more space

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

Exercise 8 Parametric polymorphism November 18, 2016

Exercise 8 Parametric polymorphism November 18, 2016 Concepts of Object-Oriented Programming AS 2016 Exercise 8 Parametric polymorphism November 18, 2016 Task 1 Consider the following Scala classes: class A class B extends A class P1[+T] class P2[T

More information

Generics with Type Bounds

Generics with Type Bounds Generics with Type Bounds Computer Science and Engineering College of Engineering The Ohio State University Lecture 27 Generic Methods Like classes, methods can be generic class ArrayOps { //ordinary nongeneric

More information

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws Lecture 14 Summary Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws 1 By the end of this lecture, you will be able to differentiate between errors, exceptions,

More information

Announcements. Lecture 15 Generics 2. Announcements. Big picture. CSE 331 Software Design and Implementation

Announcements. Lecture 15 Generics 2. Announcements. Big picture. CSE 331 Software Design and Implementation CSE 331 Software Design and Implementation Lecture 15 Generics 2 Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 5 is due tomorrow Homework 6 due tomorrow Section tomorrow! Subtyping now

More information

CSE 331 Software Design and Implementation. Lecture 15 Generics 2

CSE 331 Software Design and Implementation. Lecture 15 Generics 2 CSE 331 Software Design and Implementation Lecture 15 Generics 2 Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 5 is due tomorrow Homework 6 due tomorrow Section tomorrow! Subtyping now

More information

CSE 331. Generics (Parametric Polymorphism)

CSE 331. Generics (Parametric Polymorphism) CSE 331 Generics (Parametric Polymorphism) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/ 1 Parametric polymorphism

More information

Polymorphism. CMSC 330: Organization of Programming Languages. Two Kinds of Polymorphism. Polymorphism Overview. Polymorphism

Polymorphism. CMSC 330: Organization of Programming Languages. Two Kinds of Polymorphism. Polymorphism Overview. Polymorphism CMSC 330: Organization of Programming Languages Polymorphism Polymorphism Definition Feature that allows values of different data types to be handled using a uniform interface Applicable to Functions Ø

More information

Lecture Outline. Parametric Polymorphism and Java Generics. Polymorphism. Polymorphism

Lecture Outline. Parametric Polymorphism and Java Generics. Polymorphism. Polymorphism Lecture Outline Parametric Polymorphism and Java Generics Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping. Wildcards

More information

Parametric polymorphism and Generics

Parametric polymorphism and Generics Parametric polymorphism and Generics Today s Lecture Outline Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping.

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

CSCE 314 Programming Languages

CSCE 314 Programming Languages CSCE 314 Programming Languages! Java Generics II Dr. Hyunyoung Lee!!! 1 Type System and Variance Within the type system of a programming language, variance refers to how subtyping between complex types

More information

Java Design Goals. Lecture 32: Java. Java Original implementations slow! Exceptions & Subtyping. - void method readfiles() throws IOException {...}!

Java Design Goals. Lecture 32: Java. Java Original implementations slow! Exceptions & Subtyping. - void method readfiles() throws IOException {...}! Java Design Goals Lecture 32: Java CSC 131 Fall, 2014 Kim Bruce Portability across platforms Reliability Safety (no viruses) Dynamic Linking Multithreaded execution Simplicity and Familiarity Efficiency

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Autumn 2013 Generics (Polymorphism) (Slides by Mike Ernst and David Notkin) 1 Varieties of abstraction Abstraction over computation: procedures int

More information

CS 11 java track: lecture 1

CS 11 java track: lecture 1 CS 11 java track: lecture 1 Administrivia need a CS cluster account http://www.cs.caltech.edu/ cgi-bin/sysadmin/account_request.cgi need to know UNIX www.its.caltech.edu/its/facilities/labsclusters/ unix/unixtutorial.shtml

More information

CS61B Lecture #25: Java Generics. Last modified: Thu Oct 18 21:04: CS61B: Lecture #25 1

CS61B Lecture #25: Java Generics. Last modified: Thu Oct 18 21:04: CS61B: Lecture #25 1 CS61B Lecture #25: Java Generics Last modified: Thu Oct 18 21:04:53 2018 CS61B: Lecture #25 1 The Old Days Java library types such as List didn t used to be parameterized. All Lists were lists of Objects.

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html

More information

Java Generics -- an introduction. Based on https://docs.oracle.com/javase/tutorial/java/generics/why.html

Java Generics -- an introduction. Based on https://docs.oracle.com/javase/tutorial/java/generics/why.html Java Generics -- an introduction Based on https://docs.oracle.com/javase/tutorial/java/generics/why.html Generics vs. Templates Templates in C++ are compiled into unique code based on the types passed

More information

DrStrangebrac<E,T> Or how I learned to stop worrying, and love generics...

DrStrangebrac<E,T> Or how I learned to stop worrying, and love generics... DrStrangebrac Or how I learned to stop worrying, and love generics... a presentation to The Seattle Java Users Group by Wilhelm Fizpatrick http://www.agileinformatics.com/ Java is Sun Microsystems,

More information

Lecture 14 Summary 3/9/2009. By the end of this lecture, you will be able to differentiate between errors, exceptions, and runtime exceptions.

Lecture 14 Summary 3/9/2009. By the end of this lecture, you will be able to differentiate between errors, exceptions, and runtime exceptions. Lecture 14 Summary Exceptions vs. Errors Exceptions vs. RuntimeExceptions...catch...finally throw and throws By the end of this lecture, you will be able to differentiate between errors, exceptions, and

More information

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles, Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design

More information

CS61B Lecture #25: Java Generics. Last modified: Thu Oct 19 19:36: CS61B: Lecture #25 1

CS61B Lecture #25: Java Generics. Last modified: Thu Oct 19 19:36: CS61B: Lecture #25 1 CS61B Lecture #25: Java Generics Last modified: Thu Oct 19 19:36:29 2017 CS61B: Lecture #25 1 The Old Days Java library types such as List didn t used to be parameterized. All Lists were lists of Objects.

More information

CSE 431S Type Checking. Washington University Spring 2013

CSE 431S Type Checking. Washington University Spring 2013 CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks

More information

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages Preliminaries II 1 Agenda Objects and classes Encapsulation and information hiding Documentation Packages Inheritance Polymorphism Implementation of inheritance in Java Abstract classes Interfaces Generics

More information

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Binghamton University. CS-140 Fall Dynamic Types

Binghamton University. CS-140 Fall Dynamic Types Dynamic Types 1 Assignment to a subtype If public Duck extends Bird { Then, you may code:. } Bird bref; Duck quack = new Duck(); bref = quack; A subtype may be assigned where the supertype is expected

More information

Test Class A. public class A { private int x, y; public int getx() { return x; } public int gety() { return y; }

Test Class A. public class A { private int x, y; public int getx() { return x; } public int gety() { return y; } Test Class A Two simple exampel classes public class A { private int x, y; public int getx() { return x; public int gety() { return y; public A( int ax, int ay ) { x = ax; y = ay; public String tostring()

More information

09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013

09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013 1 TYPE CHECKING AND CASTING Lecture 5 CS2110 Spring 2013 1 Type Checking 2 Java compiler checks to see if your code is legal Today: Explore how this works What is Java doing? Why What will Java do if it

More information

Discussion. Type 08/12/2016. Language and Type. Type Checking Subtypes Type and Polymorphism Inheritance and Polymorphism

Discussion. Type 08/12/2016. Language and Type. Type Checking Subtypes Type and Polymorphism Inheritance and Polymorphism Type Joseph Spring Discussion Languages and Type Type Checking Subtypes Type and Inheritance and 7COM1023 Programming Paradigms 1 2 Type Type denotes the kind of values that programs can manipulate: Simple

More information

301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2018-15: Java

More information

CS61B Lecture #24. Today: Java support for generic programming. Readings for today: A Java Reference, Chapter 10.

CS61B Lecture #24. Today: Java support for generic programming. Readings for today: A Java Reference, Chapter 10. CS61B Lecture #24 Today: Java support for generic programming Readings for today: A Java Reference, Chapter 10. Readings for Monday: Data Structures, 6.4. Last modified: Fri Oct 19 19:33:03 2012 CS61B:

More information

CS 310: ArrayList Implementation

CS 310: ArrayList Implementation CS 310: ArrayList Implementation Chris Kauffman Week 2-2 Logistics At Home Read Weiss Ch 5: Big-O Read Weiss Ch 15: ArrayList implementation Reminder to DrJava Users Consider Using GMU Edition of DrJava

More information

CS108, Stanford Handout #8. Java Generics

CS108, Stanford Handout #8. Java Generics CS108, Stanford Handout #8 Fall, 2007-08 Nick Parlante Java Generics Java generics (added in version 5) are a mixed bag. Some uses of generics are simple to understand and make the code cleaner. They are

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative

More information

COMP1008 An overview of Polymorphism, Types, Interfaces and Generics

COMP1008 An overview of Polymorphism, Types, Interfaces and Generics COMP1008 An overview of Polymorphism, Types, Interfaces and Generics Being Object-Oriented Exploiting the combination of: objects classes encapsulation inheritance dynamic binding polymorphism pluggability

More information

301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-14: Java

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

JAVA V Assertions Java, winter semester

JAVA V Assertions Java, winter semester JAVA Assertions 1 Assertion since Java 1.4 the statement with a boolean expression a developer supposes that the expression is always satisfied (evaluates to true) if it is evaluated to false -> error

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Checked and Unchecked Exceptions in Java

Checked and Unchecked Exceptions in Java Checked and Unchecked Exceptions in Java Introduction In this article from my free Java 8 course, I will introduce you to Checked and Unchecked Exceptions in Java. Handling exceptions is the process by

More information

20 Subclassing and Mutation

20 Subclassing and Mutation Object-Oriented Design Lecture 20 CS 3500 Spring 2010 (Pucella) Tuesday, Mar 30, 2010 20 Subclassing and Mutation Suppose we have a class A that subclasses a class B (which I will write A B). Should we

More information

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors

More information

Object-oriented programming in...

Object-oriented programming in... Programming Languages Week 12 Object-oriented programming in... College of Information Science and Engineering Ritsumeikan University plan this week intro to Java advantages and disadvantages language

More information

Java: exceptions and genericity

Java: exceptions and genericity Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: exceptions and genericity Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exceptions Exceptions

More information

Introduction to Java Written by John Bell for CS 342, Spring 2018

Introduction to Java Written by John Bell for CS 342, Spring 2018 Introduction to Java Written by John Bell for CS 342, Spring 2018 Based on chapters 1 to 6 of Learning Java by Patrick Niemeyer and Daniel Leuck, with additional material from other sources. History I

More information

Generics. IRS W-9 Form

Generics. IRS W-9 Form Generics IRS W-9 Form Generics Generic class and methods. BNF notation Syntax Non-parametrized class: < class declaration > ::= "class" < identifier > ["extends" < type >] ["implements" < type list >]

More information

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code Java Security The virtual machine principle: Source Code Compiler Abstract Machine Code Abstract Machine Code Compiler Concrete Machine Code Input Hardware Input Interpreter Output 236 Java programs: definitions

More information

Generics and Type Safety. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Generics and Type Safety. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Generics and Type Safety CS 180 Sunil Prabhakar Department of Computer Science Purdue University Dynamic Data Collections Already seen several examples of dynamic data Linked list, Stack, Queue, Trees

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result. Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs

More information

Object typing and subtypes

Object typing and subtypes CS 242 2012 Object typing and subtypes Reading Chapter 10, section 10.2.3 Chapter 11, sections 11.3.2 and 11.7 Chapter 12, section 12.4 Chapter 13, section 13.3 Subtyping and Inheritance Interface The

More information

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2 CITS2200 Data Structures and Algorithms Topic 2 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies Interfaces Exceptions Reading: Lambert and Osborne,

More information

generic programming alberto ferrari university of parma

generic programming alberto ferrari university of parma generic programming alberto ferrari university of parma contents generic programming java generic programming methods & generic programming classes & generic programming java with generics generic methods

More information

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong: Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception Ariel Shamir 1 Run-time Errors Sometimes when the computer

More information

Type Bindings. Static Type Binding

Type Bindings. Static Type Binding Type Bindings Two key issues in binding (or associating) a type to an identifier: How is type binding specified? When does the type binding take place? N. Meng, S. Arthur 1 Static Type Binding An explicit

More information

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6] 1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,

More information

Java 1.5 in a Nutshell

Java 1.5 in a Nutshell Java 1.5 in a Nutshell Including Generics, Enumerated Types, Autoboxing/Unboxing, and an Enhanced for Loop http://java.sun.com/j2se/1.5.0/docs/guide/language/ CS 2334 University of Oklahoma Brian F. Veale

More information

What are Generics? e.g. Generics, Generic Programming, Generic Types, Generic Methods

What are Generics? e.g. Generics, Generic Programming, Generic Types, Generic Methods What are Generics? e.g. Generics, Generic Programming, Generic Types, Generic Methods 6 Defining the idea Behind Java Generics Data Types are now used as TypeParameters 7 Defining the idea Behind Java

More information

Java Primer. CITS2200 Data Structures and Algorithms. Topic 0

Java Primer. CITS2200 Data Structures and Algorithms. Topic 0 CITS2200 Data Structures and Algorithms Topic 0 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies and Interfaces Exceptions Generics Reading: Lambert

More information

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong: Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception 22 November 2007 Ariel Shamir 1 Run-time Errors Sometimes

More information

AP CS Unit 6: Inheritance Notes

AP CS Unit 6: Inheritance Notes AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything

More information

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010 Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages Corky Cartwright Mathias Ricken October 20, 2010 Overview I In OO languages, data values (except for designated non-oo

More information

15CS45 : OBJECT ORIENTED CONCEPTS

15CS45 : OBJECT ORIENTED CONCEPTS 15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?

More information

CS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 23 Advanced Concepts in Object-Oriented Programming Dan Grossman Spring 2011 So far... The difference between OOP and records of functions with shared private state

More information

Generic programming in OO Languages

Generic programming in OO Languages CS 242 2012 Generic programming in OO Languages Reading Text: Sections 9.4.1 and 9.4.3 J Koskinen, Metaprogramming in C++, Sections 2 5 Gilad Bracha, Generics in the Java Programming Language Questions

More information

CSC 172 Data Structures and Algorithms. Lecture 3 Spring 2018 TuTh 3:25 pm 4:40 pm

CSC 172 Data Structures and Algorithms. Lecture 3 Spring 2018 TuTh 3:25 pm 4:40 pm CSC 172 Data Structures and Algorithms Lecture 3 Spring 2018 TuTh 3:25 pm 4:40 pm Agenda Administrative aspects Java Generics Chapter 1 ADMINISTRATIVE ASPECTS Workshops Workshops Workshops begin on this

More information

Object Oriented Programming Exception Handling

Object Oriented Programming Exception Handling Object Oriented Programming Exception Handling Budditha Hettige Department of Computer Science Programming Errors Types Syntax Errors Logical Errors Runtime Errors Syntax Errors Error in the syntax of

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

Java 5 New Language Features

Java 5 New Language Features Java 5 New Language Features Ing. Jeroen Boydens, BLIN prof dr. ir. Eric Steegmans http://users.khbo.be/peuteman/java5/ Enterprise Programming Last session. Jeroen Boydens 1. JDK v1.4: assert 2. Generics

More information

Java Overview An introduction to the Java Programming Language

Java Overview An introduction to the Java Programming Language Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/

More information

G51PGP Programming Paradigms. Lecture OO-4 Aggregation

G51PGP Programming Paradigms. Lecture OO-4 Aggregation G51PGP Programming Paradigms Lecture OO-4 Aggregation 1 The story so far We saw that C code can be converted into Java code Note real object oriented code though Hopefully shows you how much you already

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

1.1. Annotations History Lesson - C/C++

1.1. Annotations History Lesson - C/C++ 1. Additions Thanks to Dr. James Heliotis. He started it all :) See also here: and see also here: and here: You need to use the tools from the Java release candidate 1 % bash % export PATH=/usr/local/j2sdk1.5.0-rc1/bin:$PATH

More information

Generics method and class definitions which involve type parameters.

Generics method and class definitions which involve type parameters. Contents Topic 07 - Generic Programming I. Introduction Example 1 User defined Generic Method: printtwice(t x) Example 2 User defined Generic Class: Pair Example 3 using java.util.arraylist II. Type

More information

Exercise 3 Subtyping and Behavioral Subtyping October 13, 2017

Exercise 3 Subtyping and Behavioral Subtyping October 13, 2017 Concepts of Object-Oriented Programming AS 2017 Exercise 3 Subtyping and Behavioral Subtyping October 13, 2017 Task 1 In this question, we are in a nominal subtyping setting. Some languages have a special

More information

The Java Type System (continued)

The Java Type System (continued) Object-Oriented Design Lecture 5 CSU 370 Fall 2007 (Pucella) Friday, Sep 21, 2007 The Java Type System (continued) The Object Class All classes subclass the Object class. (By default, this is the superclass

More information

CS61B Lecture #23. Today: Java support for generic programming. Readings for today: A Java Reference, Chapter 10.

CS61B Lecture #23. Today: Java support for generic programming. Readings for today: A Java Reference, Chapter 10. CS61B Lecture #23 Announcements: Josh s office hours are now back in his office. HW6 now due Saturday. Partial solar eclipse tomorrow, starting at 1:52PM. Next one in August, 2017. See http://www.timeanddate.com/eclipse/list.html

More information

Jam: A Smooth Extension With Java Mixins

Jam: A Smooth Extension With Java Mixins Jam: A Smooth Extension With Java Mixins Davide Ancona, Giovanni Lagorio, Ellena Zucca Presentation created by Left-out Jam abstract syntax Formal definitions of Jam static semantics Formal definitions

More information

COMP1008 Exceptions. Runtime Error

COMP1008 Exceptions. Runtime Error Runtime Error COMP1008 Exceptions Unexpected error that terminates a program. Undesirable Not detectable by compiler. Caused by: Errors in the program logic. Unexpected failure of services E.g., file server

More information

INSTRUCTIONS TO CANDIDATES

INSTRUCTIONS TO CANDIDATES NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING MIDTERM ASSESSMENT FOR Semester 2 AY2017/2018 CS2030 Programming Methodology II March 2018 Time Allowed 90 Minutes INSTRUCTIONS TO CANDIDATES 1. This

More information

Announcements. Final exam. Course evaluations. No classes next week. Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA. Wednesday November 28th

Announcements. Final exam. Course evaluations. No classes next week. Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA. Wednesday November 28th Announcements Final exam Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA Course evaluations Wednesday November 28th No classes next week no lectures, labs, or recitations Happy Thanksgiving! 1 Generics

More information

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors Outline Overview history and advantage how to: program, compile and execute 8 data types 3 types of errors Control statements Selection and repetition statements Classes and methods methods... 2 Oak A

More information

Exceptions. What exceptional things might our programs run in to?

Exceptions. What exceptional things might our programs run in to? Exceptions What exceptional things might our programs run in to? Exceptions do occur Whenever we deal with programs, we deal with computers and users. Whenever we deal with computers, we know things don

More information

Self-review Questions

Self-review Questions 7Class Relationships 106 Chapter 7: Class Relationships Self-review Questions 7.1 How is association between classes implemented? An association between two classes is realized as a link between instance

More information

TeenCoder : Java Programming (ISBN )

TeenCoder : Java Programming (ISBN ) TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+

More information

More than you ever wanted to know about. Java Generics. Jeff Meister CMSC 420 Summer 2007

More than you ever wanted to know about. Java Generics. Jeff Meister CMSC 420 Summer 2007 More than you ever wanted to know about Java Generics Jeff Meister CMSC 420 Summer 2007 The obligatory review of the boring stuff, or GENERICS: A YOUNG LADY S ILLUSTRATED PRIMER IN FOUR SLIDES Java 1.4:

More information

Fundamentals of Programming Languages

Fundamentals of Programming Languages Fundamentals of Programming Languages 1. DEFINITIONS... 2 2. BUILT-IN TYPES AND PRIMITIVE TYPES... 3 TYPE COMPATIBILITY... 9 GENERIC TYPES... 14 MONOMORPHIC VERSUS POLYMORPHIC... 16 TYPE IMPLEMENTATION

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

Unit5: Packages and abstraction. Prepared by: Dr. Abdallah Mohamed, AOU-KW Updated by Mrs. Malak EL-Amir AOU SAB Fall 14-15

Unit5: Packages and abstraction. Prepared by: Dr. Abdallah Mohamed, AOU-KW Updated by Mrs. Malak EL-Amir AOU SAB Fall 14-15 Unit5: Packages and abstraction Prepared by: Dr. Abdallah Mohamed, AOU-KW Updated by Mrs. Malak EL-Amir AOU SAB Fall 14-15 1 1. Introduction 2. Java libraries 3. The documentation of standard packages

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Principles of Computer Science

Principles of Computer Science Principles of Computer Science Java Generics 19/09/2013 CSCI 2010 - Java Generics - F.Z. Qureshi 1 Topics Benefits of generics Using generic classes and interfaces Declaring generic classes and interfaces

More information

Introducing Generics

Introducing Generics Generics Introducing Generics Generics allow reference types (classes, interfaces, and array types) and methods to be parameterized with type information. An abstract data type (ADT) defines both the types

More information