SlideShare una empresa de Scribd logo
1 de 67
JDK 1.5 and modern patterns Peter Antman, CTO, 2007 Mogul
Whats on in the Java space? ,[object Object]
The base to using J2EE effectively
New Language Feature, new libraries, new methods, new runtime ,[object Object]
Interceptors
Dependency Injection/IoC
AOP
New features in JDK 1.5 ,[object Object]
New for loop
Autoboxing
Varargs
Enums
Static import
Annotations
New concurrency libraries
New stuff in java.lang.System, java.util.*
New management API and tools (JMX)
Better runtime (gc)
And more...
Generics – stronger typing ,[object Object]
Makes it possible to write classes that handles any type logically, but bind it to a specific type when programming public interface List<E> extends Collection <E> {} ,[object Object]
A type parameter
Generics is parameterized classes (and methods)
Much like you may create new class instances with different values at runtime  ,[object Object],[object Object],[object Object]
Generics and Collections ,[object Object]
No more typecasts
Only use arrays for performance critical work
Cleaner code for simple cases
Generics –  compile time check ,[object Object],List strings = new ArrayList(); strings.add(new Integer(1));// Ok String s = (String)strings.get(0);//   Runtime error ,[object Object],List<String> strings = new ArrayList<String>(); strings.add(new Integer(1));//  Compile error String s = strings.get(0);//  No typecast
Generics - map ,[object Object],Iterator it = topMap.entrySet().iterator(); while(it.hasNext()) { Map.Entry e =  (Map.Entry) it.next(); Iterator itSub = ( (Map) e.getValue()).entrySet().iterator(); while(itSub.hasNext()) { Map.Entry eSub =  (Map.Entry) itSub.next(); String k =  (String) eSub.getKey(); } } ,[object Object],Iterator <Map.Entry<String,  Map<String, String>>>  it = topMap.entrySet().iterator(); while(it.hasNext()) { Map.Entry <String,  Map<String, String>>  e = it.next(); Iterator <<Entry.Set<String, String>>  itSub = e.getValue().entrySet().iterator(); while(itSub.hasNext()) { Map.Entry <String, String>  eSub = itSub.next(); String k = eSub.getKey(); } }
Generics – erasure ,[object Object]
The generic type informations is lost in byte code
Source code/Byte code roundtripping not possible List<String> strings = new ArrayList<String>(); strings.add(&quot;hello&quot;); String h = strings.get(0); ,[object Object],ArrayList arraylist = new ArrayList(); arraylist.add(&quot;hello&quot;); String s = (String)arraylist.get(0);
Generics – defining a class ,[object Object],interface Factory<P> { P create(); } ,[object Object],static class FactoryImpl<T> implements Factory<T> { FactoryImpl(Class<T> c) {...}; public T create() {...} } Factory<My> f1 = new FactoryImpl<My>(My.class); My m1 = f.create();
Generic methods ,[object Object]
Done by prepending a type parameter
Lets redo javax.rmi.PortableRemoteObject public class PortableRemoteObject { static  <T>  T narrow(Object o, Class<T> t) {...} } ,[object Object],My m2 = narrow(new My(), My.class); ,[object Object],static <T> List<T> trouble(T t1, T t2) ,[object Object],List<Object> lo1 = GenericsTest. <Object> trouble(new Integer(1), &quot;hello&quot;); //Must be a “.” before!
Generics – inheritance ,[object Object]
Parameterizing a class with “compatible” types does not make the classes type compatible List<Integer> does  NOT  inherit List<Number> ,[object Object],List<Number> ln = new ArrayList<Number>(); List<Integer> li = new ArrayList<Integer>(); ln.getClass().isInstance(li);// TRUE! ,[object Object],li instanceof List<Number> is not valid
Generics – inheritance example ,[object Object]
Can put both Integer and Double
ln.add(new Double(3.14));
List<Integer> li = new List<Integer>();
May only take Integer and subclasses, not Double
ln = new List<Integer>(); //  Compile error
Not OK, Integer can not risk being a Double
Generics – get principle ,[object Object]
To be able to read from an inheritable generic class one must use the extends wildcard
<? extends T>  says that we can use any instance of the generic class that has been instantiated with the typ T or any subtypes of T class Reader<S> { S read(Reader<? extends S> r) { return r.read(); } ,[object Object]
Generics – put principle ,[object Object]
<? super T>  say that any type that is a parent to T used to parameterized a generic class will make that class a subtype of the declaring class
Look at  List<? super Number> . What is List<Object>?
Since Object is a supertype of Number List<Object> is a subtype of List<? super Number>!
When writing the limiting factor is the type to write (the thing you write into must be same type or a parent) static class Writer<D> { void write(Writer<? super D> w)  { w.write(); } ,[object Object]
Generic – more complicated stuff ,[object Object]
Wildcard not allowed at top level during instance creation
Bounded type variables
Multiple bounds
Unbounded generics
Arrays and generics
Exceptions
New rule when overriding ,[object Object]
To override  public Object clone()  one had to do it like this class Person { public Object clone() {} } Person pc =  (Person) person.clone(); ,[object Object],class Person { public  Person  clone() {} } Person pc = person.clone();
Autoboxing ,[object Object]
Objects inheriting from java.lang.Object
Primitives have no common parent
Autoboxing - primitives Primitives does not work well with Collections or any other class that work on  Object void visit(String page) { int val = 0; if (stats.containsKey(page)) { val =  ((Integer) stats.get(page)).intValue(); } Integer newVal = new Integer(++val) ; stats. put (page, newVal); }

Más contenido relacionado

La actualidad más candente

Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7
Bryan O'Sullivan
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
Bryan O'Sullivan
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
Bryan O'Sullivan
 
Real World Haskell: Lecture 3
Real World Haskell: Lecture 3Real World Haskell: Lecture 3
Real World Haskell: Lecture 3
Bryan O'Sullivan
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love Game
Antony Stubbs
 

La actualidad más candente (20)

Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from java
 
Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and PitfallsJava Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and Pitfalls
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
 
Real World Haskell: Lecture 3
Real World Haskell: Lecture 3Real World Haskell: Lecture 3
Real World Haskell: Lecture 3
 
Java strings
Java   stringsJava   strings
Java strings
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
 
Strings
StringsStrings
Strings
 
Google06
Google06Google06
Google06
 
Java generics
Java genericsJava generics
Java generics
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love Game
 
04 variables
04 variables04 variables
04 variables
 
Scala Paradigms
Scala ParadigmsScala Paradigms
Scala Paradigms
 

Destacado

Destacado (13)

The Bespoke Software Product Factory (2007)
The Bespoke Software Product Factory (2007)The Bespoke Software Product Factory (2007)
The Bespoke Software Product Factory (2007)
 
Evolving Design - 5 vanliga designmissar på webbar i dag & 5 tips på hur du s...
Evolving Design - 5 vanliga designmissar på webbar i dag & 5 tips på hur du s...Evolving Design - 5 vanliga designmissar på webbar i dag & 5 tips på hur du s...
Evolving Design - 5 vanliga designmissar på webbar i dag & 5 tips på hur du s...
 
Strong decisions with consensus, Agila Sverige 2014
Strong decisions with consensus, Agila Sverige 2014Strong decisions with consensus, Agila Sverige 2014
Strong decisions with consensus, Agila Sverige 2014
 
Agila kontrakt - Frukostföreläsning för IT-chefer
Agila kontrakt - Frukostföreläsning för IT-cheferAgila kontrakt - Frukostföreläsning för IT-chefer
Agila kontrakt - Frukostföreläsning för IT-chefer
 
Lean Canvas - a hypotheses board
Lean Canvas - a hypotheses boardLean Canvas - a hypotheses board
Lean Canvas - a hypotheses board
 
Stop the line @spotify
Stop the line @spotifyStop the line @spotify
Stop the line @spotify
 
Pirateship - growing a great crew: workshop facilitation guide
Pirateship - growing a great crew: workshop facilitation guidePirateship - growing a great crew: workshop facilitation guide
Pirateship - growing a great crew: workshop facilitation guide
 
Core Protocols - A workshop
Core Protocols - A workshopCore Protocols - A workshop
Core Protocols - A workshop
 
Lean Dot Game
Lean Dot Game Lean Dot Game
Lean Dot Game
 
Lean UX i Agila Team
Lean UX i Agila TeamLean UX i Agila Team
Lean UX i Agila Team
 
Fluent at agile - agile sverige 2014
Fluent at agile - agile sverige 2014Fluent at agile - agile sverige 2014
Fluent at agile - agile sverige 2014
 
User Story Workshop
User Story WorkshopUser Story Workshop
User Story Workshop
 
Facilitating the Elephant carpaccio exercise
Facilitating the Elephant carpaccio exerciseFacilitating the Elephant carpaccio exercise
Facilitating the Elephant carpaccio exercise
 

Similar a Java 1.5 - whats new and modern patterns (2007)

Applying Generics
Applying GenericsApplying Generics
Applying Generics
Bharat17485
 
javasebeyondbasics
javasebeyondbasicsjavasebeyondbasics
javasebeyondbasics
webuploader
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
intelliyole
 
Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminar
Gautam Roy
 
Software Transactioneel Geheugen
Software Transactioneel GeheugenSoftware Transactioneel Geheugen
Software Transactioneel Geheugen
Devnology
 
Linq Sanjay Vyas
Linq   Sanjay VyasLinq   Sanjay Vyas
Linq Sanjay Vyas
rsnarayanan
 

Similar a Java 1.5 - whats new and modern patterns (2007) (20)

Applying Generics
Applying GenericsApplying Generics
Applying Generics
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
 
Effective Java - Still Effective After All These Years
Effective Java - Still Effective After All These YearsEffective Java - Still Effective After All These Years
Effective Java - Still Effective After All These Years
 
javasebeyondbasics
javasebeyondbasicsjavasebeyondbasics
javasebeyondbasics
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Scala en
Scala enScala en
Scala en
 
JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
 
Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminar
 
Software Transactioneel Geheugen
Software Transactioneel GeheugenSoftware Transactioneel Geheugen
Software Transactioneel Geheugen
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009
 
Linq Sanjay Vyas
Linq   Sanjay VyasLinq   Sanjay Vyas
Linq Sanjay Vyas
 
16 Linear data structures
16 Linear data structures16 Linear data structures
16 Linear data structures
 

Más de Peter Antman

Más de Peter Antman (13)

Growing up with agile - how the Spotify 'model' has evolved
Growing up with agile - how the Spotify 'model' has evolved Growing up with agile - how the Spotify 'model' has evolved
Growing up with agile - how the Spotify 'model' has evolved
 
Tear Down the Pyramid Again - Agile Management from the trenches
Tear Down the Pyramid Again - Agile Management from the trenchesTear Down the Pyramid Again - Agile Management from the trenches
Tear Down the Pyramid Again - Agile Management from the trenches
 
Piemonte vin
Piemonte vinPiemonte vin
Piemonte vin
 
Java Server Faces 1.2 presented (2007)
Java Server Faces 1.2 presented (2007)Java Server Faces 1.2 presented (2007)
Java Server Faces 1.2 presented (2007)
 
EJB 3.0 Walkthrough (2006)
EJB 3.0 Walkthrough (2006)EJB 3.0 Walkthrough (2006)
EJB 3.0 Walkthrough (2006)
 
Så funkar det (del 3) - webben
Så funkar det (del 3) -  webbenSå funkar det (del 3) -  webben
Så funkar det (del 3) - webben
 
Så funkar det (del 2) - mail
Så funkar det (del 2) - mailSå funkar det (del 2) - mail
Så funkar det (del 2) - mail
 
Så funkar det (del 1) - word
Så funkar det (del 1) - wordSå funkar det (del 1) - word
Så funkar det (del 1) - word
 
eXtreme Programming
eXtreme Programming eXtreme Programming
eXtreme Programming
 
SCRUM at Polopoly - or building a lean culture
SCRUM at Polopoly - or building a lean cultureSCRUM at Polopoly - or building a lean culture
SCRUM at Polopoly - or building a lean culture
 
Threads and concurrency in Java 1.5
Threads and concurrency in Java 1.5Threads and concurrency in Java 1.5
Threads and concurrency in Java 1.5
 
Lägg ner utvecklingssamtalen!
Lägg ner utvecklingssamtalen!Lägg ner utvecklingssamtalen!
Lägg ner utvecklingssamtalen!
 
Kanban at Polopoly
Kanban at PolopolyKanban at Polopoly
Kanban at Polopoly
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Java 1.5 - whats new and modern patterns (2007)