Java 7 new features

download Java 7 new features

If you can't read please download the document

Transcript of Java 7 new features

  • 1. Java 7 New Features

2. Diamond OperatorMap> offers = new HashMap(); 3. Strings in switch statementsString status = offer.getStatus();switch(status) {case NEW: newOffer(offer); Case Labelbreak;case PENDING: toString() pendingOffer(offer);break;default:break;} 4. Automatic ResourceManagement Automatic close Multiple Resourcestry(FileOutputStream fos = new FileOutputStream(movies.txt);DataOutputStream dos = new DataOutputStream(fos)) { dos.writeUTF(Java 7 New Features)} catch (IOException e) { ...}Implements java.lang.AutoCloseabletry-with-resources statement 5. Numeric literals with underscore int thousand = 1_000;int million = 1_000_000; 6. Binary literalsint two = 0b10; int forty = 0b101_000; 7. Improved exception handlingtry { methodThatThrowsThreeExceptions();} catch (ExceptionOne | ExceptionTwo | ExceptionThree e) { ...} Multi-catch block 8. NIO 2.0 Working with Path: Path, Paths,FileSystem, FileSystems, ... File change notifications: WatchService,WatchKey 9. Fork and Join Framework ForkJoinPoolint numberOfProcessors =Runtime.getRunTime().availableProcessors();RecursiveActionForkJoinPool pool = new(void compute())ForkJoinPool(numberOfProcessors)RecursiveTaskpublic class BigProblemTask extends(V compute()) RecursiveAction {@Overrideprotected void compute() {// your problem invocation goes here}}pool.invoke(task);