$ time   groovy -e println "Hello, world!";Hello, world!real     0m1.177suser     0m1.321ssys      0m0.171s$ time   groovy...
String s = ...switch (s) { case "quux":    processQuux(s);    // fall-through    case "foo":    case "bar":      processFo...
import java.util.regex.MatcherObject x = ...switch (x) {  case "abc": // x         "abc"      break    case ~/a(.*)c/: // ...
switch (x) {    // ....    case String: // x   String      break    case {it % 2 == 0}: // x      break    case null: // x...
double highestScore = students    .filter(#{ s -> s.gradYear == 2010 })    .map(   #{ s -> s.score })    .max();
def highestScore = students.      findAll({ s -> s.gradYear == 2010 }).      collect({ s -> s.score }).      max()
InputStream in = null;OutputStream out = null;try {    in = new FileInputStream(“src”);    out = new FileOutputStream(“dst...
try (InputStream   in = new FileInputStream(“src”);     OutputStream out = new FileOutputStream(“dst”)) {        byte[] bu...
new File(“dest”).withOutputStream { out ->  new File(“src”).withInputStream { ins ->    byte[] buf = new byte[8192]    int...
Map<String, Map<String, List<Employee>>> map            = new HashMap<String, Map<String, List<Employee>>>();Map<String, M...
Map<String, Map<String, List<Employee>>> map = [:]map.put(1, “A”)                    //map.put(“HOGE”, new Date()) //
import java.util.concurrent.*;public class Fibonacci extends RecursiveTask<Integer> {   final int n;   public Fibonacci(in...
import static groovyx.gpars.GParsPool.*def fibo(num) {    withPool {        runForkJoin(num) { n ->            switch (n) ...
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
Upcoming SlideShare
Loading in …5
×

JavaSE7 Launch Event: Java7xGroovy

6,007 views

Published on

Published in: Technology, News & Politics
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,007
On SlideShare
0
From Embeds
0
Number of Embeds
4,198
Actions
Shares
0
Downloads
9
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

JavaSE7 Launch Event: Java7xGroovy

  1. 1. $ time groovy -e println "Hello, world!";Hello, world!real 0m1.177suser 0m1.321ssys 0m0.171s$ time groovyclient -e println "Hello,world!";Hello, world!real 0m0.029suser 0m0.001ssys 0m0.002s
  2. 2. String s = ...switch (s) { case "quux": processQuux(s); // fall-through case "foo": case "bar": processFooOrBar(s); break; case "baz": processBaz(s); // fall-through default: processDefault(s); break;}
  3. 3. import java.util.regex.MatcherObject x = ...switch (x) { case "abc": // x "abc" break case ~/a(.*)c/: // x assert Matcher.lastMatcher[0][0] == "abbc" assert Matcher.lastMatcher[0][1] == "bb" break case 1..3: // x 1 3 break case [1,3,5]: // x 1,3,5 break // ....}
  4. 4. switch (x) { // .... case String: // x String break case {it % 2 == 0}: // x break case null: // x null break case a: // a // a.isCase(x) true break}
  5. 5. double highestScore = students .filter(#{ s -> s.gradYear == 2010 }) .map( #{ s -> s.score }) .max();
  6. 6. def highestScore = students. findAll({ s -> s.gradYear == 2010 }). collect({ s -> s.score }). max()
  7. 7. InputStream in = null;OutputStream out = null;try { in = new FileInputStream(“src”); out = new FileOutputStream(“dst”); byte[] buf = new byte[8192]; int n = 0; while((n = in.read(buf)) >= 0) { out.write(buf, 0, n); }} catch (IOException e) { //} finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (out != null) { try { out.close(); } catch (IOException e) { } }}
  8. 8. try (InputStream in = new FileInputStream(“src”); OutputStream out = new FileOutputStream(“dst”)) { byte[] buf = new byte[8192]; int n = 0; while((n = in.read(buf)) >= 0) { out.write(buf, 0, n); }}
  9. 9. new File(“dest”).withOutputStream { out -> new File(“src”).withInputStream { ins -> byte[] buf = new byte[8192] int n = 0 while((n = ins.read(buf)) >= 0) { out.write(buf, 0, n); } }}new File("dest") << new File("src").bytes
  10. 10. Map<String, Map<String, List<Employee>>> map = new HashMap<String, Map<String, List<Employee>>>();Map<String, Map<String, List<Employee>>> map = new HashMap<>();
  11. 11. Map<String, Map<String, List<Employee>>> map = [:]map.put(1, “A”) //map.put(“HOGE”, new Date()) //
  12. 12. import java.util.concurrent.*;public class Fibonacci extends RecursiveTask<Integer> { final int n; public Fibonacci(int n) { this.n = n; } public Integer compute() { if (n <= 1) return n; Fibonacci f1 = new Fibonacci(n - 1); f1.fork(); Fibonacci f2 = new Fibonacci(n - 2); return f2.compute() + f1.join(); }}
  13. 13. import static groovyx.gpars.GParsPool.*def fibo(num) { withPool { runForkJoin(num) { n -> switch (n) { case 0..1: return n default: forkOffChild(n - 1) forkOffChild(n - 2) childrenResults.sum() } } }}assert fibo(10) == 55assert fibo(20) == 6765

×