Upload
developintelligence
View
667
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Kelby Zorgdrager from DevelopIntelligence explains the differences between the variations of Java and what's new in Java 7. If you need help with Java training DevelopIntelligence and provide on-site training within two weeks. Customized and affordable for any organization.
Citation preview
What’s New in Java 5, 6 & 7
Delivered by DevelopIntelligence
About DevelopIntelligence
Provide highly-customized, role-based, project-centric learning solutions to software teams
Specialize in areas of Java, Open Source, Web Development, and Mobile
Delivered training to over 40,000 engineers worldwide
Headquartered in Boulder CO
Copyright DevelopIntelligence LLC
About Kelby Zorgdrager
President of DevelopIntelligence
Working with and teaching Java since 1996 (1.0.1)
Former Sun Microsystems Java Platform engineer
Delivered training to over 5,000 engineers worldwide
Webinar Topics
In this presentation, we will cover:
Current State of Java
Newish Language Features
Questions at the end
DevelopIntelligence http://www.DevelopIntelligence.com 4
Objectives
When we are done, you should be:
Familiar with current state of Java
Aware of new features
DevelopIntelligence http://www.DevelopIntelligence.com 5
Current State of Java
Copyright DevelopIntelligence LLC
7
Java SE 5.0
Significant revamp of JavaNot largest revamp in terms of new APIs
Significance lies in new language features
Released Sept 2004 - Code named “Tiger”
EOL’d Oct 30, 2009
Current version 1.5 update 22
DevelopIntelligence http://www.DevelopIntelligence.com
8
Java SE 6
Focused on refreshing APIs, internals, and Scripting support
Released Dec 2006 - Code named “Mustag”
Current version 1.6 update 43
DevelopIntelligence http://www.DevelopIntelligence.com
9
Java SE 7
Focused on simplifying language, APIs, internals, and dynamic language support
Released July 2011 - Code named “Dolphin”
Current version 1.7 update 21
DevelopIntelligence http://www.DevelopIntelligence.com
Breadth of Java Across Versions
10 DevelopIntelligence http://www.DevelopIntelligence.com
1.0.2 1.1 1.2 1.3 1.4 1.5 1.6 1.70
500
1000
1500
2000
2500
3000
3500
4000
4500
8 22 59 76 135 166 203 209202
477
1524
1840
2723
3279
3793
4024
Growth of Java
PackagesClasses
Java Version
Am
ou
nt
Growth of Java Across Versions
11 DevelopIntelligence http://www.DevelopIntelligence.com
1.0.2 1.1 1.2 1.3 1.4 1.5 1.6 1.7
0
50
100
150
200
250
300
350
0
275268
129
178
123 122
103
0
236
319
121
148
120 116106
Growth of Java
Package Growth
Class Growth
Version
Perc
en
tag
e G
row
th
Language Features
“newish”
Copyright DevelopIntelligence LLC
General Language Niceties
Copyright DevelopIntelligence LLC
Single Static Import [1.5]
14 DevelopIntelligence http://www.DevelopIntelligence.com
provide direct access to static variables and methods
On-Demand Static Import [1.5]
15 DevelopIntelligence http://www.DevelopIntelligence.com
Copyright DevelopIntelligence LLC
Literals [1.7]
Copyright DevelopIntelligence LLC
Simplification of Strings [1.7]
Strings are constants - And - treated like primitives (at least from a coding perspective)
But until Java 7 – weren’t supported in switch statements
String a = “Hello”; . . . switch(a) { case “hello”: case “Hello”: case “HELLO” //do something break; default: //do something else break;}
Autoboxing [1.5]
18 DevelopIntelligence http://www.DevelopIntelligence.com
Collection Autoboxing [1.5]
19 DevelopIntelligence http://www.DevelopIntelligence.com
Autoboxing Support
Primitive Type Reference Typeboolean java.lang.Boolean
byte java.lang.Byte
short java.lang.Short
int java.lang.Integer
long java.lang.Long
float java.lang.Float
double java.lang.Double
char java.lang.Character
20 DevelopIntelligence http://www.DevelopIntelligence.com
For-each Loop [1.5]
21 DevelopIntelligence http://www.DevelopIntelligence.com
Iterable For-each Loop [1.5]
22 DevelopIntelligence http://www.DevelopIntelligence.com
Variable Method Arguments [old way]
23 DevelopIntelligence http://www.DevelopIntelligence.com
varargs [1.5]
24 DevelopIntelligence http://www.DevelopIntelligence.com
enums
Copyright DevelopIntelligence LLC
Working with an Enum
Enums are types – provide type safety for a closed set of values
Values are instances of an enum typeStored as static final fields in type
Defined in terms ofname - stringified representation of field name
ordinal - position in set
Referencable through dot-notation
Are switchable
26 DevelopIntelligence http://www.DevelopIntelligence.com
enum [1.5]
27 DevelopIntelligence http://www.DevelopIntelligence.com
Working with an Enum [cont.]
Reference using dot notation
Enums have some predefined static methodsvalues – retrieves all enum instancesvalueOf - transforms String value into enum instance
Have some predefined instance methodsname – upper-case name of enum instancetoStringequalshashCode
28 DevelopIntelligence http://www.DevelopIntelligence.com
Accessing an Enum Value
29 DevelopIntelligence http://www.DevelopIntelligence.com
Enum Switch Example
30 DevelopIntelligence http://www.DevelopIntelligence.com
Enum Method Example
31 DevelopIntelligence http://www.DevelopIntelligence.com
Prints: SUNDAYMONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAY
Typesafe Collections
Copyright DevelopIntelligence LLC
Typesafe Collection Advantages
Adds compile time type safety to collections
Type safety simplifies collection interactions (ie: iterating)
No advantages (or disadvantages) in speed or performance
33 DevelopIntelligence http://www.DevelopIntelligence.com
Simple List Example [Old way]
34 DevelopIntelligence http://www.DevelopIntelligence.com
Simple List Example [1.5]
35 DevelopIntelligence http://www.DevelopIntelligence.com
Copyright DevelopIntelligence LLC
Simplification of Generics [1.7]
1.5 way of declaring and initializing a collection:
List<String> list = new ArrayList<String>();
Compiler should be “smart enough” to infer type from declaration
1.7 way of declaring and initializing:
List<String> list = new ArrayList<>();
Annotations
Copyright DevelopIntelligence LLC
38
Annotations
Metadata facility for JavaAllowing you to provide additional data alongside Java classes
Similar to Javadoc “metadata” facility
Expanded and formalized mechanism“Competes” with Doclet / XDoclet
Recognized by Java compiler and other tools
DevelopIntelligence http://www.DevelopIntelligence.com
@Override Example [1.5]
39 DevelopIntelligence http://www.DevelopIntelligence.com
Covariant Returns
Copyright DevelopIntelligence LLC
Covariant Returns
What are they?Allows return type of inherited method to be narrowed
Applies to method over-riding not over-loading
Why do they exist?Needed to support generics mechanism
Removes narrowing cast on polymorphic returns
Prevents run-time ClassCastExceptions on returns
Provides compile-time type dependency checking
41 DevelopIntelligence http://www.DevelopIntelligence.com
Covariant Return Example [1.5]
DevelopIntelligence http://www.DevelopIntelligence.com 42
43
Auto-Closing Resources
DevelopIntelligence http://www.DevelopIntelligence.com
Copyright DevelopIntelligence LLC
Simplification of try/catch [1.7]
There’s a lot of try/catch/finally boiler-plate code out there
Why not let the compiler generate it for you?
FileInputStream fis; try { fis = new FileInputStream(“/tmp/myfile.txt”); …} catch(IOException ioe) { …} finally { fis.close()}
try (InputStream fis =new FileInputStream(“/tmp/myfile.txt”)) { …}
New way
Copyright DevelopIntelligence LLC
Simplification of try/catch [1.7]
Do we really need all those catches?
How DevelopIntelligence Can Help?
FAST: We can provide customized on-site training within two weeks to help with tight deadlines.
CUSTOMIZED: Complete customization of the training you need at no additional costs to your organization.
AFFORDABLE: We have the most flexible pricing module in the industry and can work with any budget.
CONTACT US: 877-629-5631
DevelopIntelligence http://www.DevelopIntelligence.com 46
Copyright DevelopIntelligence LLC
Win a Free Safari Account
Question:
“What date did the FCS of JDK 1.0 occur”
Post your answer to:LinkedIn: http://www.linkedin.com/company/developintelligence
Twitter: http://twitter.com/DevIntelligence
All correct answers will be entered into a raffle – winners will be announced Monday June 17