Documents

Java5.0 TechBhginessWeek 2005

Description
hgf
Categories
Published
of 26
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  1 1 New Features in Java 5.0New Features in Java 5.0  Angelika Langer  Angelika Langer Trainer /Trainer /ConsultantConsultant http://http://wwwwww.. AngelikaLanger  AngelikaLanger ..comcom © Copyright 2003-2005 by Angelika Langer & Klaus Kreft. All Rights Reserved.http://www.AngelikaLanger.com/last update: 11/7/2005 ,05:49 J2SE 5.0 -new features 2 new featuresnew featuresin J2SE 5.0in J2SE 5.0 ãJ2SE 5.0releasedin September 2004ãnew featuresinlanguage&core libraries –generics –enums –annotations –autoboxing,for-each,loop,static import,varargs –concurrency utilities  2 © Copyright 2003-2005 by Angelika Langer & Klaus Kreft. All Rights Reserved.http://www.AngelikaLanger.com/last update: 11/7/2005 ,05:49 J2SE 5.0 -new features 3 agendaagenda ãgenericsãenumsãannotationsãautoboxing,for-each loop,static import,varargsãconcurrency utilities © Copyright 2003-2005 by Angelika Langer & Klaus Kreft. All Rights Reserved.http://www.AngelikaLanger.com/last update: 11/7/2005 ,05:49 J2SE 5.0 -new features 4 purposepurposeof of genericsgenerics ãgeneric types needed for collections  –implementation is independent of the contained elements –use a generic  List instead of IntList and StringList ãtraditionaltechnique for generic typesin Java:  –implementationintermsof Object references ã side effects:  –  no collection of primitive types ã use wrapper types and autoboxing  –  no homogeneous collections ã lots of casts required  3 © Copyright 2003-2005 by Angelika Langer & Klaus Kreft. All Rights Reserved.http://www.AngelikaLanger.com/last update: 11/7/2005 ,05:49 J2SE 5.0 -new features 5 useuseof nonof non--generic collectionsgeneric collections ã no homogeneous collections  –  lots of casts required ã no compile-time checks  –  late error detection at runtime LinkedListlist =new LinkedList();list.add(newInteger(0));Integer i = (Integer)list.get(0);String s = (String)list.get(0); casts requiredfine at compile-time, but fails at runtime © Copyright 2003-2005 by Angelika Langer & Klaus Kreft. All Rights Reserved.http://www.AngelikaLanger.com/last update: 11/7/2005 ,05:49 J2SE 5.0 -new features 6 useuseof of generic collectionsgeneric collections ã collections are homogeneous  –  no casts necessary ã early compile-time checks  –  based on static type information LinkedList<Integer>list =new LinkedList<Integer>();list.add(newInteger(0));Integer i = list.get(0);String s = list.get(0); compile-time error   4 © Copyright 2003-2005 by Angelika Langer & Klaus Kreft. All Rights Reserved.http://www.AngelikaLanger.com/last update: 11/7/2005 ,05:49 J2SE 5.0 -new features 7 benefitsbenefitsof of generic typesgeneric types ã increased expressive power  ã improved type safety ã explicit type parameters and implicit type casts © Copyright 2003-2005 by Angelika Langer & Klaus Kreft. All Rights Reserved.http://www.AngelikaLanger.com/last update: 11/7/2005 ,05:49 J2SE 5.0 -new features 8 definitiondefinitionof of generic typesgeneric types ã  type variable = placeholder foranunknown typeãusage  –insignaturesofmethods –for declarationoffieldsand variables –as type argumenttoother generic types interface Collection<A><A><A><A>{public void add(AAAAx);public Iterator<A><A><A><A>iterator();}class LinkedList<A><A><A><A>implements Collection<A><A><A><A>{protected class Node{AAAAelt;Node next= null;Node(AAAAelt) {this.elt=elt; }}...}
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks