A presentation at DevNexus 2019 in March 2019 in Atlanta, GA, USA by Baruch Sadogursky
@jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
Baruch Sadogursky, Head of Developer Relations, @jfrog @jbaruch Viktor Gamov, Developer Advocate, @confluent @gamussa @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
-Shownotes! -jfrog.com/shownotes -Slides -Video (soon) -Links -Comments, ratings, raffle @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
Two funny folks on stage 2. Funny and educating puzzlers 3. You vote! (that’s important) 4. We throw t-shirts on you (sponsored by confuent, thank you!) 5. official: #javapuzzlersng #devnexus @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
Voting system check: what java are you running? A. B. C. D. E. F. Java 8 Java 12 Java 11 Java 9 Java 5 Java 2 @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
Java puzzlers are like: @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
Everything works (or doesn’t work) with the latest openjdk release! @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
class This { final String thіs; This() { this.thіs = This.this.thіs + “this”; } } public static void main(String[] args) { System.out.println(new This().thіs.length()); } class This { final String thіs; This() { this.thіs = this.thіs + “this”; } } A. First compiles, second does not B. Second compiles, first does not C. Both compile D. Stop drugs!! public static void main(String[] args) { System.out.println(new This().thіs.length()); } @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
class This { final String thіs; This() { this.thіs = This.this.thіs + “this”; } } public static void main(String[] args) { System.out.println(new This().thіs.length()); } A. Runtime Exception B. 4 C. 8 D. Won’t compile (yes, I am a slowpoke) @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
How we understand bitcoin/blockchain hype !Something is spinning/mining !High CPU load !High heat omission !Someone made a lot of money once !That’s all we know @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
What won’t compile? A. B. C. D. for for {;} for ; for (;;) (;;) (;;) (;;) {;;} ;; {;} ; E. All good, folks! @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
What won’t compile? A. B. C. D. for for {;} for ; for (;;) (;;) (;;) (;;) {;;} ;; {;} ; Unreachable statement E. All good, folks! @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
public static void main(String[] args) { final boolean rick; } if(true && (rick = true)) {} if(false && (rick = false)) {} System.out.println(rick); public static void main(String[] args) { final boolean rick; } if(false && (rick = false)) {} if(true && (rick = true)) {} System.out.println(rick); @jbaruch @gamussa #javapuzzlersng A. First compiles, second does not B. Second compiles, first does not C. Both compile D.Stop drugs!! #devnexus jfrog.com/shownotes
entry public static void main(String[] args) { final boolean rick; } if(true && (rick = true)) {} if(false && (rick = false)) {} System.out.println(rick); true rick = true false rick = false println @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
entry false rick = false public static void main(String[] args) { final boolean rick; } if(false && (rick = false)) {} if(true && (rick = true)) {} System.out.println(rick); true rick = true println @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
entry false public static void main(String[] args) { final boolean rick; } if(false && (rick = false)) {} if(true && (rick = true)) {} System.out.println(rick); true rick = true println @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
rick = false public static void main(String[] args) { final boolean rick; } if(false && (rick = false)) {} if(true && (rick = true)) {} System.out.println(rick); true rick = true println @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
public static void main(String[] args) { System.out.println(carOrder(” fuchsia”)); } static <Color> Color carOrder(Color color) { class ModelT extends RuntimeException { Color color; ModelT(Color color) { this.color = color; // 1 } } } if (color.equals(0x000000)) throw new ModelT(color); // 2 try { carOrder(0x000000); A.Won’t compile } catch (ModelT car) { color = car.color; // 3 B.Empty line } C.0 return color; D.ClassCastException @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
public static void main(String[] args) { System.out.println(carOrder(” fuchsia”)); } static <Color> Color carOrder(Color color) { class ModelT extends RuntimeException { Color color; ModelT(Color color) { this.color = color; // 1 } } } if (color.equals(0x000000)) throw new ModelT(color); // 2 try { carOrder(0x000000); Unchecked warning: } catch (ModelT car) { A.//1 color = car.color; // 3 } B.//2 return color; @jbaruch @gamussa C.//3 D.Not gonna happen #javapuzzlersng #devnexus jfrog.com/shownotes
public class Main { public static void main(String[] args) throws InterruptedException { new Object().wait(9223372036854775807L, 1); } } A.Long wait ahead B.Fails with IllegalMonitorStateException C. Fails with IllegalArgumentException D.Fails with InterruptedException @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
WTF, Java(script?) @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
What will print “true”? private static void doubleWtf(Double wtf1, Double wtf2) { if (!wtf1.equals(wtf2)) { DoubleBuffer dWtf1 = DoubleBuffer.allocate(1).put(wtf1); DoubleBuffer dWtf2 = DoubleBuffer.allocate(1).put(wtf2); } System.out.println(dWtf1.equals(dWtf2)); } A. B. C. D. E. @jbaruch Double.NaN and Double.NaN Double.NaN and any double 0.0 and -0.0 Any double and a null Nothing @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
RTFM @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
Var of thrones @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
final var targaryens = 2; final var lannisters = 25; final var starks = ‘1’; final var snow = true ? targaryens * lannisters : starks; System.out.println(snow); A. 2 B. 25 C. 1 D. 50 @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
final int targaryens = 2; final int lannisters = 25; final char starks = ‘1’; final char snow = true ? targaryens * lannisters : starks; System.out.println(snow); A. 2 B. 25 C. 1 D. 50 @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
-Write readable code! -Comment all the tricks -Sometimes it’s just a bug -Static code analysis FTW IntelliJ IDEA! -RTFM @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
-You get it, more releases – more puzzlers! -Puzzlers? Gotchas? Fetal position inducing behavior? -puzzlers+java@jfrog.com @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
-Did you like it? -Praise us on twitter! -# javapuzzlersng -# OracleCodeOne -@ jbaruch -@ gamussa -Didn’t like it? -/dev/null @jbaruch @gamussa #javapuzzlersng #devnexus jfrog.com/shownotes
View Java Puzzlers NG S04 - Looks like with this release cycle the puzzlers are here to stay.
Dismiss
You know what to expect in this session by now: funny and puzzling questions about Java, airborne Confluent t-shirts, and the usual combo of learning and fun ahead!