whats new in java 5, 6, & 7 (webinar presentation - june 2013)

47
What’s New in Java 5, 6 & 7 Delivered by DevelopIntelligence

Upload: developintelligence

Post on 26-May-2015

669 views

Category:

Technology


1 download

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.

TRANSCRIPT

Page 1: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

What’s New in Java 5, 6 & 7

Delivered by DevelopIntelligence

Page 2: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 3: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 4: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 5: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Objectives

When we are done, you should be:

Familiar with current state of Java

Aware of new features

DevelopIntelligence http://www.DevelopIntelligence.com 5

Page 6: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Current State of Java

Copyright DevelopIntelligence LLC

Page 7: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 8: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 9: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 10: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 11: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 12: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Language Features

“newish”

Copyright DevelopIntelligence LLC

Page 13: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

General Language Niceties

Copyright DevelopIntelligence LLC

Page 14: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Single Static Import [1.5]

14 DevelopIntelligence http://www.DevelopIntelligence.com

provide direct access to static variables and methods

Page 15: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

On-Demand Static Import [1.5]

15 DevelopIntelligence http://www.DevelopIntelligence.com

Page 16: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Copyright DevelopIntelligence LLC

Literals [1.7]

Page 17: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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;}

Page 18: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Autoboxing [1.5]

18 DevelopIntelligence http://www.DevelopIntelligence.com

Page 19: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Collection Autoboxing [1.5]

19 DevelopIntelligence http://www.DevelopIntelligence.com

Page 20: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 21: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

For-each Loop [1.5]

21 DevelopIntelligence http://www.DevelopIntelligence.com

Page 22: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Iterable For-each Loop [1.5]

22 DevelopIntelligence http://www.DevelopIntelligence.com

Page 23: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Variable Method Arguments [old way]

23 DevelopIntelligence http://www.DevelopIntelligence.com

Page 24: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

varargs [1.5]

24 DevelopIntelligence http://www.DevelopIntelligence.com

Page 25: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

enums

Copyright DevelopIntelligence LLC

Page 26: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 27: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

enum [1.5]

27 DevelopIntelligence http://www.DevelopIntelligence.com

Page 28: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 29: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Accessing an Enum Value

29 DevelopIntelligence http://www.DevelopIntelligence.com

Page 30: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Enum Switch Example

30 DevelopIntelligence http://www.DevelopIntelligence.com

Page 31: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Enum Method Example

31 DevelopIntelligence http://www.DevelopIntelligence.com

Prints: SUNDAYMONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAY

Page 32: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Typesafe Collections

Copyright DevelopIntelligence LLC

Page 33: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 34: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Simple List Example [Old way]

34 DevelopIntelligence http://www.DevelopIntelligence.com

Page 35: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Simple List Example [1.5]

35 DevelopIntelligence http://www.DevelopIntelligence.com

Page 36: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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<>();

Page 37: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Annotations

Copyright DevelopIntelligence LLC

Page 38: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 39: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

@Override Example [1.5]

39 DevelopIntelligence http://www.DevelopIntelligence.com

Page 40: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Covariant Returns

Copyright DevelopIntelligence LLC

Page 41: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 42: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Covariant Return Example [1.5]

DevelopIntelligence http://www.DevelopIntelligence.com 42

Page 43: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

43

Auto-Closing Resources

DevelopIntelligence http://www.DevelopIntelligence.com

Page 44: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

Page 45: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

Copyright DevelopIntelligence LLC

Simplification of try/catch [1.7]

Do we really need all those catches?

Page 46: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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

[email protected]

[email protected]

DevelopIntelligence http://www.DevelopIntelligence.com 46

Page 47: Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)

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