SlideShare a Scribd company logo
1 of 93
Download to read offline
Developer Advocate @JFrog
@jbaruch on the internetz
Solution Architect @Confluent
@gAmUssA on the internetz
@tagir_valeev
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
1. Two entertaining guys on
the stage
2. Funny puzzling questions
3. You think and vote
4.T-shirts are airborne
5. Official twitter hashtag:
#javapuzzlersng
Which Java version are you on?
A. Java 7
B. Java 8
C. Java 9
D. Java 6
E. Java 5
F. Java 2
@jbaruch http://jfrog.com/shownotes @gamussa
Watching the puzzlers like… #dafaq
@jbaruch http://jfrog.com/shownotes @gamussa
Everything works (or doesn't)
in the latest Java 8 and/or 9 update
@jbaruch http://jfrog.com/shownotes @gamussa
public class PerfectRobbery {
private Semaphore bankAccount = new Semaphore(-42);
public static void main(String[] args) {
PerfectRobbery perfectRobbery = new PerfectRobbery();
perfectRobbery.takeAllMoney();
perfectRobbery.checkBalance();
}
public void takeAllMoney(){
bankAccount.drainPermits();
}
public void checkBalance(){
System.out.println(bankAccount.availablePermits());
}
}
A. IllegalArgumentException –can’t create semaphore with negative
B. UnsupportedOperationException –can’t drain when negative
C. 0
D. -42
@jbaruch http://jfrog.com/shownotes @gamussa
A. IllegalArgumentException –can’t create semaphore with negative
B. UnsupportedOperationException –can’t drain when negative
C. 0
D. -42
public class PerfectRobbery {
private Semaphore bankAccount = new Semaphore(-42);
public static void main(String[] args) {
PerfectRobbery perfectRobbery = new PerfectRobbery();
perfectRobbery.takeAllMoney();
perfectRobbery.checkBalance();
}
public void takeAllMoney(){
bankAccount.drainPermits();
}
public void checkBalance(){
System.out.println(bankAccount.availablePermits());
}
}
Available
-42?!
@jbaruch http://jfrog.com/shownotes @gamussa
Available
-42?!
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
A. true/true
B. true/false
C. false/true
D. false/false
Collections.emptyList() == Collections.emptyList();
Collections.emptyIterator() == Collections.emptyIterator();
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
A. true/true
B. true/false
C. false/true
D. false/false
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();
Stream.empty() == Stream.empty();
Singleton Strikes Back!
@jbaruch http://jfrog.com/shownotes @gamussa
A. true/true
B. true/false
C. false/true
D. false/false
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();
Stream.empty() == Stream.empty();
@jbaruch http://jfrog.com/shownotes @gamussa
Even empty Stream has state!
@jbaruch http://jfrog.com/shownotes @gamussa
”Identical”
1. Has the same state
2. Not related to “equals and hashcode”contract
3. Not related to references to objects in memory
@jbaruch http://jfrog.com/shownotes @gamussa
List[] twins = new List[2];
Arrays.setAll(twins, ArrayList::new);
A. Absolutely identical empty lists
B. Absolutely identical non-empty lists
C. Non-identical empty lists
D. Non-identical non-empty lists
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
List[] twins = new List[2];
Arrays.setAll(twins, ArrayList::new);
A. Absolutely identical empty lists
B. Absolutely identical non-empty lists
C. Non-identical empty lists
D. Non-identical non-empty lists
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
How single is a Single Abstract Method Interface?
@jbaruch http://jfrog.com/shownotes @gamussa
A. WTF?! ’Single’means one,not three!
B. Problem is with partyHard(T),remove it and it will work
C. Problem is the drinkIn methods,removing one of them and it will
work
D. It will work fine! Both partyHard() and drinkIn() are merged in
SingleAndHappy,leaving one abstract method
public interface Single<T> {
default void partyHard(String songName) { System.out.println(songName); }
void partyHard(T songName);
void drinkIn(T drinkName);
void drinkIn(String dringName);
}
@FunctionalInterface
public interface SingleAndHappy extends Single<String> { }
@jbaruch http://jfrog.com/shownotes @gamussa
A. WTF?! ’Single’means one,not three!
B. Problem is with partyHard(T),remove it and it will work
C. Problem are the drinkIn methods,removing it will leave one abstract
method
D. Yes! Both partyHard() and drinkIn() are merged in SingleAndHappy,
leaving one abstract method
public interface Single<T> {
default void partyHard(String songName) { System.out.println(songName); }
void partyHard(T songName);
void drinkIn(T drinkName);
void drinkIn(String dringName);
}
@FunctionalInterface
public interface SingleAndHappy extends Single<String> { }
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
Hacking the bank
☑Bank software written in Java
☑Hack into it
☑Analyze the accounts
@jbaruch http://jfrog.com/shownotes @gamussa
Given the code above,which statement is wrong:
A. The Set is ordered by hashcode
B. The order is predictable across multiple runs of the JVM on the same machine
C. The order of elements in Set is not predictable
D. Statements A & B are correct
Set<String>	accounts=	new	HashSet<>(Arrays.asList("Gates",	"Buffett",	"Bezos",	"Zuckerberg"));
System.out.println(”accounts=	"	+	accounts);
@jbaruch http://jfrog.com/shownotes @gamussa
Given the code above,which statement is wrong:
A. The Set is ordered
B. The order is predictable across multiple runs of the JVM on the same machine
C. The order of elements in Set is not predictable
D. Statements A & B are correct
Set<String>	accounts=	new	HashSet<>(Arrays.asList("Gates",	"Buffett",	"Bezos",	"Zuckerberg"));
System.out.println(”accounts=	"	+	accounts);
@jbaruch http://jfrog.com/shownotes @gamussa
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}
@jbaruch http://jfrog.com/shownotes @gamussa
Your turn,FBI
@jbaruch http://jfrog.com/shownotes @gamussa
Given the code above,which statement is wrong:
A. The Set is ordered
B. The order is predictable across multiple runs of the JVM on the same machine
C. The order of elements in Set is not predictable
D. Statements A & B are correct
Set<String>	accounts	=	Set.of("Gates",	"Buffett",	"Bezos",	"Zuckerberg");
System.out.println(”accounts=	"	+	accounts);
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
Given the code above,which statement is wrong:
A. The Set is ordered
B. The order is predictable across multiple runs of the JVM on the same machine
C. The order of elements in Set is not predictable
D. Statements A & B are correct
Set<String>	accounts	=	Set.of("Gates",	"Buffett",	"Bezos",	"Zuckerberg");
System.out.println(”accounts=	"	+	accounts);
@jbaruch http://jfrog.com/shownotes @gamussa
private int probe(Object pe) {
int idx = Math.floorMod(pe.hashCode() ^ SALT, elements.length);
while (true) {
E ee = elements[idx];
if (ee == null) {
return -idx - 1;
} else if (pe.equals(ee)) {
return idx;
} else if (++idx == elements.length) {
idx = 0;
}
}
}
@jbaruch http://jfrog.com/shownotes @gamussa
Juggling Accident
What’s correct?
A. If you convert your application to module,classpath
dependencies will still be resolved correctly
B. If one of the dependencies was converted to a module,you
have to declare it in module-info in order to use
C. Once you added the module-info to your project you have to
declare the dependencies twice,in classpath and in module-
info
D. None of the above
@jbaruch http://jfrog.com/shownotes @gamussa
What’s correct?
A. If you convert your application to module,classpath
dependencies will still be resolved correctly
B. If one of the dependencies was converted to a module,you
have to declare it in module-info in order to use
C. Once you added the module-info to your project you have to
declare the dependencies twice,in classpath and in module-
info
D. None of the above
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
A. You killed them all
B. You killed only even ones
C. They all survived
D. You killed only odd ones
E. All answers are correct
static void killThemAll(Collection<Hero> expendables) {
Iterator<Hero> heroes = expendables.iterator();
heroes.forEachRemaining(e -> {
if (heroes.hasNext()) {
heroes.next();
heroes.remove();
}
});
System.out.println(expendables);
}
@jbaruch http://jfrog.com/shownotes @gamussa
A. You killed them all
B. You killed only even ones
C. They all survived
D. You killed only odd ones
E. All answers are correct
static void killThemAll(Collection<Hero> expendables) {
Iterator<Hero> heroes = expendables.iterator();
heroes.forEachRemaining(e -> {
if (heroes.hasNext()) {
heroes.next();
heroes.remove();
}
});
System.out.println(expendables);
}
Don’t do that.Really,don’t.
killThemAll(new ArrayList<String>(Arrays.asList("N","S","W","S","L","S","L","V")));
[]
killThemAll(new LinkedList<String>(Arrays.asList("N","S","W","S","L","S","L","V")));
[S,S,S,V]
killThemAll(new ArrayDeque<String>(Arrays.asList("N","S","W","S","L","S","L","V")));
[N,S,W,S,L,S,L,V]
killThemAll(new TreeSet<String>(Arrays.asList("N","S","W","S","L","S","L","V")));
[N,W,L,L]
@jbaruch http://jfrog.com/shownotes @gamussa
Subtle Difference
@jbaruch http://jfrog.com/shownotes @gamussa
A. Both work just fine
B. Lambda works,method ref fails
C. Method ref works,lambda fails
D. Won’t compile
@FunctionalInterface
public interface OriginalPredicate<T> {
boolean test(T t);
}
OriginalPredicate<Object> lambda = (Object obj) -> ”adidas".equals(obj);
OriginalPredicate<Object> methodRef = ”adidas"::equals;
A. Both work just fine
B. Lambda works,method ref fails
C. Method ref works,lambda fails
D. Not a functional interface,will fail on annotation processing
@FunctionalInterface
Public interface CopyCatPredicate {
<T> boolean test(T t);
}
CopyCatPredicate lambda = (Object obj) -> " adadas".equals(obj);
CopyCatPredicate methodRef = " adadas"::equals;
A. Both work just fine
B. Lambda works,method ref fails
C. Method ref works,lambda fails
D. Not a functional interface,will fail on annotation processing
@FunctionalInterface
Public interface CopyCatPredicate {
<T> boolean test(T t);
}
CopyCatPredicate lambda = (Object obj) -> " adadas".equals(obj);
CopyCatPredicate methodRef = " adadas"::equals;
@jbaruch http://jfrog.com/shownotes @gamussa
A	generic	function	type	for	a	functional	interface	may	be	implemented	by	a	
method	reference	expression	(§15.13),	but	not	by	a	lambda	expression	
(§15.27)	as	there	is	no	syntax	for	generic	lambda	expressions.	“
@jbaruch http://jfrog.com/shownotes @gamussa
A.[Data, Kirk, Spock]
B.[Spock, Kirk, Data, Data, Kirk, Spock]
C.[Spock, Kirk, Data]
D.[Data, Data, Kirk, Kirk, Spock, Spock]
E.Are you nuts? Won’t compile! Data with
Kirk?!
List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk",
"Spock").sequential()
.filter(new TreeSet<>()::add).collect(Collectors.toList());
System.out.println(list);
@jbaruch http://jfrog.com/shownotes @gamussa
A.[Data, Kirk, Spock]
B.[Spock, Kirk, Data, Data, Kirk, Spock]
C.[Spock, Kirk, Data]
D.[Data, Data, Kirk, Kirk, Spock, Spock]
E.Are you nuts? Won’t compile! Data with
Kirk?!
List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk",
"Spock").sequential()
.filter(new TreeSet<>()::add).collect(Collectors.toList());
System.out.println(list);
@jbaruch http://jfrog.com/shownotes @gamussa
A.[Data, Kirk, Spock]
B.[Spock, Kirk, Data, Data, Kirk, Spock]
C.[Spock, Kirk, Data]
D.[Data, Data, Kirk, Kirk, Spock, Spock]
E.Are you nuts? Won’t compile! Data with
Kirk?!
List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk",
"Spock").sequential()
.filter(new TreeSet<>()::add).collect(Collectors.toList());
System.out.println(list);
@jbaruch http://jfrog.com/shownotes @gamussa
filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))!=
New	instance	is	
created	every	time!
Instance	method	is	
created	once!
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
A. obvious / obvious
B. obvious / NullPointerException
C. NullPointerException / obvious
D. NullPointerException / NullPointerException
Optional.of("obvious").orElseGet(null);
Optional.empty().map(null).orElse("obvious");
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
A. obvious / obvious
B. obvious / NullPointerException
C. NullPointerException / obvious
D. NullPointerException / NullPointerException
Optional.of("obvious").orElseGet(null);
Optional.empty().map(null).orElse("obvious");
Will	never	happen
Will	never	happen
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
A. obvious / obvious
B. obvious / NullPointerException
C. NullPointerException / obvious
D. NullPointerException / NullPointerException
Optional.of("obvious").orElseGet(null);
Optional.empty().map(null).orElse("obvious");
@jbaruch http://jfrog.com/shownotes @gamussa
@jbaruch http://jfrog.com/shownotes @gamussa
Identical?
@jbaruch http://jfrog.com/shownotes @gamussa
A. All
B. 3 and 4
C. Only 3
D. Other
1. Consumer<String> agentA = s -> System.out.println(s);
Consumer<String> agentB = s -> System.out.println(s);
2. Consumer<String> agentA = System.out::println;
Consumer<String> agentB = System.out::println;
3. Supplier<Consumer<String>> supplier = () -> s -> System.out.println(s);
Consumer<String> agentA = supplier.get();
Consumer<String> agentB = supplier.get();
4. Supplier<Consumer<String>> supplier = () -> System.out::println;
Consumer<String> agentA = supplier.get();
Consumer<String> agentB = supplier.get();
When agentA == agentB?
@jbaruch http://jfrog.com/shownotes @gamussa
A. All
B. 3 and 4
C. Only 3
D. Other
1. Consumer<String> agentA = s -> System.out.println(s);
Consumer<String> agentB = s -> System.out.println(s);
2. Consumer<String> agentA = System.out::println;
Consumer<String> agentB = System.out::println;
3. Supplier<Consumer<String>> supplier = () -> s -> System.out.println(s);
Consumer<String> agentA = supplier.get();
Consumer<String> agentB = supplier.get();
4. Supplier<Consumer<String>> supplier = () -> System.out::println;
Consumer<String> agentA = supplier.get();
Consumer<String> agentB = supplier.get();
When agentA == agentB?
Reuse is only possible for pure functions
Consumers accept parameters == have
state
Supplier in 4 has state –the resolved
method reference
@jbaruch http://jfrog.com/shownotes @gamussa
Conclusions
@jbaruch http://jfrog.com/shownotes @gamussa
-Write readable code!
-Comment all the tricks
-Sometimes it’s just a bug
-Static code analysis FTW -
IntelliJ IDEA!
-RTFM!
-Don’t abuse lambdas and
streams!
-Trust us, we have much
more where those came
from.
-Puzzlers? Gotchas? Fetal
position inducing behavior?
-puzzlers@jfrog.com
-Shownotes!
-http://jfrog.com/shownotes
-Slides
-Video in 24 hours
-Links
-Ratings
-Raffle! (come early)
-Did you like it?
-Praise us on twitter!
-#javapuzzlersng
-@gamussa
-@jbaruch
-Didn’t like it?
-/dev/null

More Related Content

Similar to Java Puzzlers NG S02: Down the Rabbit Hole as it was presented at The Pittsburgh Java Meetup Group

Meetup django common_problems(1)
Meetup django common_problems(1)Meetup django common_problems(1)
Meetup django common_problems(1)Eric Satterwhite
 
Django O/R Mapper
Django O/R MapperDjango O/R Mapper
Django O/R MapperIan Lewis
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Andrzej Jóźwiak
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the BasicsJussi Pohjolainen
 
[Philly ETE] Java Puzzlers NG
[Philly ETE] Java Puzzlers NG[Philly ETE] Java Puzzlers NG
[Philly ETE] Java Puzzlers NGViktor Gamov
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimMir Nazim
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMockYing Zhang
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Java 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJava 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJosé Paumard
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpointwebhostingguy
 
Spring Certification Questions
Spring Certification QuestionsSpring Certification Questions
Spring Certification QuestionsSpringMockExams
 
Generics On The JVM (What you don't know will hurt you)
Generics On The JVM (What you don't know will hurt you)Generics On The JVM (What you don't know will hurt you)
Generics On The JVM (What you don't know will hurt you)Garth Gilmour
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On RailsWen-Tien Chang
 
Workshop State-management in React with Context and Hooks
Workshop State-management in React with Context and HooksWorkshop State-management in React with Context and Hooks
Workshop State-management in React with Context and HooksRoy Derks
 

Similar to Java Puzzlers NG S02: Down the Rabbit Hole as it was presented at The Pittsburgh Java Meetup Group (20)

Meetup django common_problems(1)
Meetup django common_problems(1)Meetup django common_problems(1)
Meetup django common_problems(1)
 
Django O/R Mapper
Django O/R MapperDjango O/R Mapper
Django O/R Mapper
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the Basics
 
[Philly ETE] Java Puzzlers NG
[Philly ETE] Java Puzzlers NG[Philly ETE] Java Puzzlers NG
[Philly ETE] Java Puzzlers NG
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Java 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJava 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelization
 
Groovy Basics
Groovy BasicsGroovy Basics
Groovy Basics
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Django
DjangoDjango
Django
 
Meerut Golden.pdf
Meerut Golden.pdfMeerut Golden.pdf
Meerut Golden.pdf
 
Spring Certification Questions
Spring Certification QuestionsSpring Certification Questions
Spring Certification Questions
 
Generics On The JVM (What you don't know will hurt you)
Generics On The JVM (What you don't know will hurt you)Generics On The JVM (What you don't know will hurt you)
Generics On The JVM (What you don't know will hurt you)
 
Rails OO views
Rails OO viewsRails OO views
Rails OO views
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
Workshop State-management in React with Context and Hooks
Workshop State-management in React with Context and HooksWorkshop State-management in React with Context and Hooks
Workshop State-management in React with Context and Hooks
 

More from Baruch Sadogursky

DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...Baruch Sadogursky
 
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...Baruch Sadogursky
 
Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Baruch Sadogursky
 
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018Baruch Sadogursky
 
Where the Helm are your binaries? as presented at Canada Kubernetes Meetups
Where the Helm are your binaries? as presented at Canada Kubernetes MeetupsWhere the Helm are your binaries? as presented at Canada Kubernetes Meetups
Where the Helm are your binaries? as presented at Canada Kubernetes MeetupsBaruch Sadogursky
 
Data driven devops as presented at Codemash 2018
Data driven devops as presented at Codemash 2018Data driven devops as presented at Codemash 2018
Data driven devops as presented at Codemash 2018Baruch Sadogursky
 
A Research Study into DevOps Bottlenecks as presented at Codemash 2018
A Research Study into DevOps Bottlenecks as presented at Codemash 2018A Research Study into DevOps Bottlenecks as presented at Codemash 2018
A Research Study into DevOps Bottlenecks as presented at Codemash 2018Baruch Sadogursky
 
Best Practices for Managing Docker Versions as presented at JavaOne 2017
Best Practices for Managing Docker Versions as presented at JavaOne 2017Best Practices for Managing Docker Versions as presented at JavaOne 2017
Best Practices for Managing Docker Versions as presented at JavaOne 2017Baruch Sadogursky
 
Troubleshooting & Debugging Production Microservices in Kubernetes as present...
Troubleshooting & Debugging Production Microservices in Kubernetes as present...Troubleshooting & Debugging Production Microservices in Kubernetes as present...
Troubleshooting & Debugging Production Microservices in Kubernetes as present...Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017Baruch Sadogursky
 
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...Baruch Sadogursky
 
Let’s Wing It: A Study in DevRel Strategy
 Let’s Wing It: A Study in DevRel Strategy Let’s Wing It: A Study in DevRel Strategy
Let’s Wing It: A Study in DevRel StrategyBaruch Sadogursky
 
Log Driven First Class Customer Support at Scale
Log Driven First Class Customer Support at ScaleLog Driven First Class Customer Support at Scale
Log Driven First Class Customer Support at ScaleBaruch Sadogursky
 
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOpsBaruch Sadogursky
 
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...Baruch Sadogursky
 
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Gr8Conf 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Gr8Conf 2017DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Gr8Conf 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Gr8Conf 2017Baruch Sadogursky
 

More from Baruch Sadogursky (20)

DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
 
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
 
Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018
 
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
 
Where the Helm are your binaries? as presented at Canada Kubernetes Meetups
Where the Helm are your binaries? as presented at Canada Kubernetes MeetupsWhere the Helm are your binaries? as presented at Canada Kubernetes Meetups
Where the Helm are your binaries? as presented at Canada Kubernetes Meetups
 
Data driven devops as presented at Codemash 2018
Data driven devops as presented at Codemash 2018Data driven devops as presented at Codemash 2018
Data driven devops as presented at Codemash 2018
 
A Research Study into DevOps Bottlenecks as presented at Codemash 2018
A Research Study into DevOps Bottlenecks as presented at Codemash 2018A Research Study into DevOps Bottlenecks as presented at Codemash 2018
A Research Study into DevOps Bottlenecks as presented at Codemash 2018
 
Best Practices for Managing Docker Versions as presented at JavaOne 2017
Best Practices for Managing Docker Versions as presented at JavaOne 2017Best Practices for Managing Docker Versions as presented at JavaOne 2017
Best Practices for Managing Docker Versions as presented at JavaOne 2017
 
Troubleshooting & Debugging Production Microservices in Kubernetes as present...
Troubleshooting & Debugging Production Microservices in Kubernetes as present...Troubleshooting & Debugging Production Microservices in Kubernetes as present...
Troubleshooting & Debugging Production Microservices in Kubernetes as present...
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
 
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
 
Let’s Wing It: A Study in DevRel Strategy
 Let’s Wing It: A Study in DevRel Strategy Let’s Wing It: A Study in DevRel Strategy
Let’s Wing It: A Study in DevRel Strategy
 
Log Driven First Class Customer Support at Scale
Log Driven First Class Customer Support at ScaleLog Driven First Class Customer Support at Scale
Log Driven First Class Customer Support at Scale
 
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
 
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
 
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Gr8Conf 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Gr8Conf 2017DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Gr8Conf 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Gr8Conf 2017
 

Recently uploaded

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Recently uploaded (20)

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Java Puzzlers NG S02: Down the Rabbit Hole as it was presented at The Pittsburgh Java Meetup Group

  • 1.
  • 2.
  • 3. Developer Advocate @JFrog @jbaruch on the internetz Solution Architect @Confluent @gAmUssA on the internetz
  • 4.
  • 9. 1. Two entertaining guys on the stage 2. Funny puzzling questions 3. You think and vote 4.T-shirts are airborne 5. Official twitter hashtag: #javapuzzlersng
  • 10.
  • 11. Which Java version are you on? A. Java 7 B. Java 8 C. Java 9 D. Java 6 E. Java 5 F. Java 2 @jbaruch http://jfrog.com/shownotes @gamussa
  • 12. Watching the puzzlers like… #dafaq @jbaruch http://jfrog.com/shownotes @gamussa
  • 13. Everything works (or doesn't) in the latest Java 8 and/or 9 update @jbaruch http://jfrog.com/shownotes @gamussa
  • 14.
  • 15.
  • 16. public class PerfectRobbery { private Semaphore bankAccount = new Semaphore(-42); public static void main(String[] args) { PerfectRobbery perfectRobbery = new PerfectRobbery(); perfectRobbery.takeAllMoney(); perfectRobbery.checkBalance(); } public void takeAllMoney(){ bankAccount.drainPermits(); } public void checkBalance(){ System.out.println(bankAccount.availablePermits()); } } A. IllegalArgumentException –can’t create semaphore with negative B. UnsupportedOperationException –can’t drain when negative C. 0 D. -42
  • 18. A. IllegalArgumentException –can’t create semaphore with negative B. UnsupportedOperationException –can’t drain when negative C. 0 D. -42 public class PerfectRobbery { private Semaphore bankAccount = new Semaphore(-42); public static void main(String[] args) { PerfectRobbery perfectRobbery = new PerfectRobbery(); perfectRobbery.takeAllMoney(); perfectRobbery.checkBalance(); } public void takeAllMoney(){ bankAccount.drainPermits(); } public void checkBalance(){ System.out.println(bankAccount.availablePermits()); } }
  • 22. A. true/true B. true/false C. false/true D. false/false Collections.emptyList() == Collections.emptyList(); Collections.emptyIterator() == Collections.emptyIterator(); @jbaruch http://jfrog.com/shownotes @gamussa
  • 24. A. true/true B. true/false C. false/true D. false/false Spliterators.emptySpliterator() == Spliterators.emptySpliterator(); Stream.empty() == Stream.empty();
  • 25. Singleton Strikes Back! @jbaruch http://jfrog.com/shownotes @gamussa
  • 26. A. true/true B. true/false C. false/true D. false/false Spliterators.emptySpliterator() == Spliterators.emptySpliterator(); Stream.empty() == Stream.empty(); @jbaruch http://jfrog.com/shownotes @gamussa
  • 27. Even empty Stream has state! @jbaruch http://jfrog.com/shownotes @gamussa
  • 28.
  • 29. ”Identical” 1. Has the same state 2. Not related to “equals and hashcode”contract 3. Not related to references to objects in memory @jbaruch http://jfrog.com/shownotes @gamussa
  • 30. List[] twins = new List[2]; Arrays.setAll(twins, ArrayList::new); A. Absolutely identical empty lists B. Absolutely identical non-empty lists C. Non-identical empty lists D. Non-identical non-empty lists @jbaruch http://jfrog.com/shownotes @gamussa
  • 32. List[] twins = new List[2]; Arrays.setAll(twins, ArrayList::new); A. Absolutely identical empty lists B. Absolutely identical non-empty lists C. Non-identical empty lists D. Non-identical non-empty lists @jbaruch http://jfrog.com/shownotes @gamussa
  • 34. How single is a Single Abstract Method Interface? @jbaruch http://jfrog.com/shownotes @gamussa
  • 35. A. WTF?! ’Single’means one,not three! B. Problem is with partyHard(T),remove it and it will work C. Problem is the drinkIn methods,removing one of them and it will work D. It will work fine! Both partyHard() and drinkIn() are merged in SingleAndHappy,leaving one abstract method public interface Single<T> { default void partyHard(String songName) { System.out.println(songName); } void partyHard(T songName); void drinkIn(T drinkName); void drinkIn(String dringName); } @FunctionalInterface public interface SingleAndHappy extends Single<String> { } @jbaruch http://jfrog.com/shownotes @gamussa
  • 36.
  • 37. A. WTF?! ’Single’means one,not three! B. Problem is with partyHard(T),remove it and it will work C. Problem are the drinkIn methods,removing it will leave one abstract method D. Yes! Both partyHard() and drinkIn() are merged in SingleAndHappy, leaving one abstract method public interface Single<T> { default void partyHard(String songName) { System.out.println(songName); } void partyHard(T songName); void drinkIn(T drinkName); void drinkIn(String dringName); } @FunctionalInterface public interface SingleAndHappy extends Single<String> { } @jbaruch http://jfrog.com/shownotes @gamussa
  • 39.
  • 40. Hacking the bank ☑Bank software written in Java ☑Hack into it ☑Analyze the accounts @jbaruch http://jfrog.com/shownotes @gamussa
  • 41. Given the code above,which statement is wrong: A. The Set is ordered by hashcode B. The order is predictable across multiple runs of the JVM on the same machine C. The order of elements in Set is not predictable D. Statements A & B are correct Set<String> accounts= new HashSet<>(Arrays.asList("Gates", "Buffett", "Bezos", "Zuckerberg")); System.out.println(”accounts= " + accounts); @jbaruch http://jfrog.com/shownotes @gamussa
  • 42.
  • 43. Given the code above,which statement is wrong: A. The Set is ordered B. The order is predictable across multiple runs of the JVM on the same machine C. The order of elements in Set is not predictable D. Statements A & B are correct Set<String> accounts= new HashSet<>(Arrays.asList("Gates", "Buffett", "Bezos", "Zuckerberg")); System.out.println(”accounts= " + accounts); @jbaruch http://jfrog.com/shownotes @gamussa
  • 44. public boolean add(E e) { return map.put(e, PRESENT)==null; } @jbaruch http://jfrog.com/shownotes @gamussa
  • 46.
  • 47. Given the code above,which statement is wrong: A. The Set is ordered B. The order is predictable across multiple runs of the JVM on the same machine C. The order of elements in Set is not predictable D. Statements A & B are correct Set<String> accounts = Set.of("Gates", "Buffett", "Bezos", "Zuckerberg"); System.out.println(”accounts= " + accounts); @jbaruch http://jfrog.com/shownotes @gamussa
  • 50. Given the code above,which statement is wrong: A. The Set is ordered B. The order is predictable across multiple runs of the JVM on the same machine C. The order of elements in Set is not predictable D. Statements A & B are correct Set<String> accounts = Set.of("Gates", "Buffett", "Bezos", "Zuckerberg"); System.out.println(”accounts= " + accounts); @jbaruch http://jfrog.com/shownotes @gamussa
  • 51. private int probe(Object pe) { int idx = Math.floorMod(pe.hashCode() ^ SALT, elements.length); while (true) { E ee = elements[idx]; if (ee == null) { return -idx - 1; } else if (pe.equals(ee)) { return idx; } else if (++idx == elements.length) { idx = 0; } } } @jbaruch http://jfrog.com/shownotes @gamussa
  • 53. What’s correct? A. If you convert your application to module,classpath dependencies will still be resolved correctly B. If one of the dependencies was converted to a module,you have to declare it in module-info in order to use C. Once you added the module-info to your project you have to declare the dependencies twice,in classpath and in module- info D. None of the above @jbaruch http://jfrog.com/shownotes @gamussa
  • 54.
  • 55. What’s correct? A. If you convert your application to module,classpath dependencies will still be resolved correctly B. If one of the dependencies was converted to a module,you have to declare it in module-info in order to use C. Once you added the module-info to your project you have to declare the dependencies twice,in classpath and in module- info D. None of the above @jbaruch http://jfrog.com/shownotes @gamussa
  • 57.
  • 58. A. You killed them all B. You killed only even ones C. They all survived D. You killed only odd ones E. All answers are correct static void killThemAll(Collection<Hero> expendables) { Iterator<Hero> heroes = expendables.iterator(); heroes.forEachRemaining(e -> { if (heroes.hasNext()) { heroes.next(); heroes.remove(); } }); System.out.println(expendables); }
  • 60. A. You killed them all B. You killed only even ones C. They all survived D. You killed only odd ones E. All answers are correct static void killThemAll(Collection<Hero> expendables) { Iterator<Hero> heroes = expendables.iterator(); heroes.forEachRemaining(e -> { if (heroes.hasNext()) { heroes.next(); heroes.remove(); } }); System.out.println(expendables); }
  • 61. Don’t do that.Really,don’t. killThemAll(new ArrayList<String>(Arrays.asList("N","S","W","S","L","S","L","V"))); [] killThemAll(new LinkedList<String>(Arrays.asList("N","S","W","S","L","S","L","V"))); [S,S,S,V] killThemAll(new ArrayDeque<String>(Arrays.asList("N","S","W","S","L","S","L","V"))); [N,S,W,S,L,S,L,V] killThemAll(new TreeSet<String>(Arrays.asList("N","S","W","S","L","S","L","V"))); [N,W,L,L] @jbaruch http://jfrog.com/shownotes @gamussa
  • 63. A. Both work just fine B. Lambda works,method ref fails C. Method ref works,lambda fails D. Won’t compile @FunctionalInterface public interface OriginalPredicate<T> { boolean test(T t); } OriginalPredicate<Object> lambda = (Object obj) -> ”adidas".equals(obj); OriginalPredicate<Object> methodRef = ”adidas"::equals;
  • 64.
  • 65. A. Both work just fine B. Lambda works,method ref fails C. Method ref works,lambda fails D. Not a functional interface,will fail on annotation processing @FunctionalInterface Public interface CopyCatPredicate { <T> boolean test(T t); } CopyCatPredicate lambda = (Object obj) -> " adadas".equals(obj); CopyCatPredicate methodRef = " adadas"::equals;
  • 66.
  • 67. A. Both work just fine B. Lambda works,method ref fails C. Method ref works,lambda fails D. Not a functional interface,will fail on annotation processing @FunctionalInterface Public interface CopyCatPredicate { <T> boolean test(T t); } CopyCatPredicate lambda = (Object obj) -> " adadas".equals(obj); CopyCatPredicate methodRef = " adadas"::equals;
  • 70.
  • 71. A.[Data, Kirk, Spock] B.[Spock, Kirk, Data, Data, Kirk, Spock] C.[Spock, Kirk, Data] D.[Data, Data, Kirk, Kirk, Spock, Spock] E.Are you nuts? Won’t compile! Data with Kirk?! List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk", "Spock").sequential() .filter(new TreeSet<>()::add).collect(Collectors.toList()); System.out.println(list); @jbaruch http://jfrog.com/shownotes @gamussa
  • 72.
  • 73. A.[Data, Kirk, Spock] B.[Spock, Kirk, Data, Data, Kirk, Spock] C.[Spock, Kirk, Data] D.[Data, Data, Kirk, Kirk, Spock, Spock] E.Are you nuts? Won’t compile! Data with Kirk?! List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk", "Spock").sequential() .filter(new TreeSet<>()::add).collect(Collectors.toList()); System.out.println(list); @jbaruch http://jfrog.com/shownotes @gamussa
  • 74.
  • 75. A.[Data, Kirk, Spock] B.[Spock, Kirk, Data, Data, Kirk, Spock] C.[Spock, Kirk, Data] D.[Data, Data, Kirk, Kirk, Spock, Spock] E.Are you nuts? Won’t compile! Data with Kirk?! List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk", "Spock").sequential() .filter(new TreeSet<>()::add).collect(Collectors.toList()); System.out.println(list); @jbaruch http://jfrog.com/shownotes @gamussa
  • 76. filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))!= New instance is created every time! Instance method is created once! @jbaruch http://jfrog.com/shownotes @gamussa
  • 78. A. obvious / obvious B. obvious / NullPointerException C. NullPointerException / obvious D. NullPointerException / NullPointerException Optional.of("obvious").orElseGet(null); Optional.empty().map(null).orElse("obvious"); @jbaruch http://jfrog.com/shownotes @gamussa
  • 80. A. obvious / obvious B. obvious / NullPointerException C. NullPointerException / obvious D. NullPointerException / NullPointerException Optional.of("obvious").orElseGet(null); Optional.empty().map(null).orElse("obvious"); Will never happen Will never happen @jbaruch http://jfrog.com/shownotes @gamussa
  • 82. A. obvious / obvious B. obvious / NullPointerException C. NullPointerException / obvious D. NullPointerException / NullPointerException Optional.of("obvious").orElseGet(null); Optional.empty().map(null).orElse("obvious"); @jbaruch http://jfrog.com/shownotes @gamussa
  • 85. A. All B. 3 and 4 C. Only 3 D. Other 1. Consumer<String> agentA = s -> System.out.println(s); Consumer<String> agentB = s -> System.out.println(s); 2. Consumer<String> agentA = System.out::println; Consumer<String> agentB = System.out::println; 3. Supplier<Consumer<String>> supplier = () -> s -> System.out.println(s); Consumer<String> agentA = supplier.get(); Consumer<String> agentB = supplier.get(); 4. Supplier<Consumer<String>> supplier = () -> System.out::println; Consumer<String> agentA = supplier.get(); Consumer<String> agentB = supplier.get(); When agentA == agentB?
  • 87. A. All B. 3 and 4 C. Only 3 D. Other 1. Consumer<String> agentA = s -> System.out.println(s); Consumer<String> agentB = s -> System.out.println(s); 2. Consumer<String> agentA = System.out::println; Consumer<String> agentB = System.out::println; 3. Supplier<Consumer<String>> supplier = () -> s -> System.out.println(s); Consumer<String> agentA = supplier.get(); Consumer<String> agentB = supplier.get(); 4. Supplier<Consumer<String>> supplier = () -> System.out::println; Consumer<String> agentA = supplier.get(); Consumer<String> agentB = supplier.get(); When agentA == agentB?
  • 88. Reuse is only possible for pure functions Consumers accept parameters == have state Supplier in 4 has state –the resolved method reference @jbaruch http://jfrog.com/shownotes @gamussa
  • 90. -Write readable code! -Comment all the tricks -Sometimes it’s just a bug -Static code analysis FTW - IntelliJ IDEA! -RTFM! -Don’t abuse lambdas and streams!
  • 91. -Trust us, we have much more where those came from. -Puzzlers? Gotchas? Fetal position inducing behavior? -puzzlers@jfrog.com
  • 92. -Shownotes! -http://jfrog.com/shownotes -Slides -Video in 24 hours -Links -Ratings -Raffle! (come early)
  • 93. -Did you like it? -Praise us on twitter! -#javapuzzlersng -@gamussa -@jbaruch -Didn’t like it? -/dev/null