Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Java 7 (OSCON 2012)

1,474 views

Published on

OSCON 2012 tutorial session Part I

Published in: Technology, News & Politics
  • Be the first to comment

Introduction to Java 7 (OSCON 2012)

  1. 1. The Well-Grounded Java Developer Introduction to Java 7
  2. 2. This is not an Oracle legal slide 2
  3. 3. No, we’re not in sales!• Get in touch - Ben is: @kittylist - Martijn is: @karianna (and @diabolicaldev)• What we do - Authors of “The Well-Grounded Java Developer” - CEO/CTO of jClarity - JVM/Hardware/Performance stuff• We co-lead the LJC (London’s Java User Group) - Hold a seat on the JCP SE/EE Executive Committee - Run Adopt a JSR and Adopt OpenJDK programmes
  4. 4. Or in pictures...
  5. 5. How this session is going to work • This session may be a little different to advertised... - Being a “Well-Grounded Java Developer” changes over time • This session will go fairly quickly - But the slides will be made available - And you can always get hold of us for any questions • There are USB keys going around - Copy over the WGJD into $WORKSPACE - Install Java 7 if you havent done so already! - Your major IDEs should work • Pair/Group programming works best - Have the least experienced person do the actual typing!
  6. 6. Attempted TimetableIntroduction to Java 7 - 0900-0955 (~55 mins) – BREAK (5 minutes)Polyglot and functional programming - 1000-1030 (~30 mins)BREAK (30 minutes)Polyglot and functional programming - 1100-1125 (~25 mins) – BREAK (5 minutes)Modern Java Concurrency - 1130-1230(~60 mins)
  7. 7. Real developers code through bathroom breaks 7
  8. 8. The Well-Grounded Java Developer... • Is not just a Java language whizz - Understands the basics of the JVM - Understands software development is a social activity - Utilises software craftsmanship approaches - Understands physical and logical architectures • Is using Java 7 - At least at home if not at work • Is looking at polyglot and functional programming • Is looking at modern concurrency practices
  9. 9. Java 7 - Why is it important• The WGJD wants to code rapidly• The WGJD wants to code concisely• The WGJD wants to take advantage of: - The compiler (including JIT) - The JVM (including GC)• Java 7 gives you many improvements in these areas
  10. 10. OpenJDK - The Java 7/8 split• 20 Sep 2010 - Mark Reinhold announces Plan B - Splits OpenJDK plan into Java 7 (July 2011) & Java 8 (2013) - Popular choice with the community• July 2011 - Java 7 goes gold - Wow, a whole year ago now!• Some new features to be delayed until JDK 8 - Lambda Expressions - Modularisation (aka Jigsaw)• JRockit features to be merged into OpenJDK - Enhanced management of the JVM - Ongoing merge of the VM engineering groups
  11. 11. Contents of JDK 7 ReleaseProject CoinNIO.2Method HandlesinvokedynamicConcurrency RefreshOdds & Ends
  12. 12. Project Coin• “Small” changes• Language Level, not VM• Stay away from the type system• Developed in a very OSS manner - Was an ‘interesting’ experience for all involved
  13. 13. Project Coin - HighlightsStrings in switchtry-with-resources (aka ARM or TWR)Diamond SyntaxMulti-catch with precise re-throwEnhanced syntax for numeric literalsVarargs / autoboxing warning
  14. 14. Strings in switch• Code along exercise: FeedingSchedule.java
  15. 15. try-with-resources
  16. 16. Diamond syntax• Code along exercise: HordeOfOtters.java
  17. 17. Personally I’d stick to Java 1.4 17
  18. 18. NIO.2 - New I/O version 2• A new file system and path abstraction• Based on Path - An abstract view of a ‘file like’ system• Files class contains many helper methods, including - File manipulation (copy, move, rename etc) - Walking directory trees - Native file system support (e.g. symbolic links)• Works with existing java.io.File code
  19. 19. NIO.2 - New I/O version 2• Asynchronous (non-blocking) I/O• For sockets and files• Mainly utilises java.util.concurrent.Future• New NetworkChannel - Socket/Channel construct - Binding, options and multicast
  20. 20. Path and Files - Some examples• Code along exercise: Housekeeping.java
  21. 21. URL stream to file - Java 6 style NIO
  22. 22. URL stream to file in Java 7• Code along exercise: VetNotes.java
  23. 23. NIO.2 - Future base file I/O• See ExceptionExamples.java as well (multi-catch)
  24. 24. Method Handles• We already have Reflection API - It’s all pretty horrible• JDK 7 introduces a new way to inspect at runtime• Method Handles - Represent the ability to call a method - Implement subclass java.lang.invoke.MethodHandle - Are strongly-typed and typesafe - Needed for invokedynamic - but also used standalone
  25. 25. Example - ThreadPoolManager
  26. 26. Cancelling using Reflection
  27. 27. Cancelling using MethodHandle
  28. 28. invokedynamic• invokedynamic is a key new JVM feature - It’s the first new bytecode since Java 1.0 - Joins invokevirtual, invokestatic, invokeinterface and invokespecial• Relaxes a key part of the static typing system - User code can determine dispatch at runtime• Aims to be as fast as regular method dispatch - e.g. invokevirtual• No Java syntax in Java 7 - But maybe for Java 8
  29. 29. invokedynamic contd.• JRuby, Jython, Groovy, Clojure et al all benefit - JRuby gains a lot, Clojure not so much - Even Scala is using it now!• JRuby works closely with the JSR-292 team - Charlie Nutter (winner of JAX special jury award) - Big wins - Makes JRuby enticing to Ruby developers• Java 8 also gets a boost - Lambdas will be implemented with invokedynamic
  30. 30. Other JVM Languages?Meh - Use the Golden Hammer! 30
  31. 31. Java 7 Concurrency Refresh• Java 7 has a number of new concurrency toys• The headline item is Fork / Join - Similar to Map/Reduce, useful for a certain class of problems - Fork and join executions are not necessarily threads• We’ll cover this in the final hour!
  32. 32. Java 7 - That’s not all• Nimbus Look & Feel for Swing• New helper classes including Objects - deepEquals() and friends• JDBC with try-with-resources support• Better unicode support - Thanks in part to Tom Christiansen of Perl fame• More small changes in niche areas
  33. 33. New Faces in the OpenJDK
  34. 34. What We Didn’t Have Time To Talk About • Java 8 - Java FX 2.x • Java EE 6/7 • Java ME • JDK Enhancement Proposals (JEPs) • Java Community Process (JCP) - Java Specification Requests (JSRs) - Java User Groups (JUGs) and Adopt programs
  35. 35. What? You still here?Go take a break will you! 35

×