SlideShare a Scribd company logo
This slide is intentionally left
blank
JAVA PUZZLERS NG
DOWN THE RABBIT HOLEhttp://www.davidfloresmedia.com/philly-rocky-statue/
@gAmUssA @hazelcast #jbreak #hazelcastjet
> whoami
@gAmUssA @hazelcast #jbreak #hazelcastjet
Solutions Architect
> whoami
@gAmUssA @hazelcast #jbreak #hazelcastjet
Solutions Architect
Developer Advocate
> whoami
@gAmUssA @hazelcast #jbreak #hazelcastjet
Solutions Architect
Developer Advocate
@gamussa in internetz
> whoami
@gAmUssA @hazelcast #jbreak #hazelcastjet
Solutions Architect
Developer Advocate
@gamussa in internetz
Please, follow me on Twitter
> whoami
@gAmUssA @hazelcast #jbreak #hazelcastjet
Solutions Architect
Developer Advocate
@gamussa in internetz
Please, follow me on Twitter
I’m very interesting ©
> whoami
Developer Advocate @JFrog
on the internetz
Developer Advocate @Hazelcast
@gAmUssA on the internetz
CLICK AND HACK
THE TYPE-IT BROTHERS
@tagir_valeev
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
1. Two One entertaining guy on
the stage
1. Two One entertaining guy on
the stage
2. Funny puzzling questions
1. Two One entertaining guy on
the stage
2. Funny puzzling questions
3. You think and vote
1. Two One entertaining guy on
the stage
2. Funny puzzling questions
3. You think and vote
4.Official twitter hashtags
#javapuzzlersng #PhillyETE
FIRST RULE OF THE PUZZLERS:
NO CHEATING!
Which Java version are you on?
										@gamussa										#PhillyETE
Which Java version are you on?
A. Java 7
										@gamussa										#PhillyETE
Which Java version are you on?
A. Java 7
B. Java 8
										@gamussa										#PhillyETE
Which Java version are you on?
A. Java 7
B. Java 8
C. Java 9
										@gamussa										#PhillyETE
Which Java version are you on?
A. Java 7
B. Java 8
C. Java 9
D. Java 6
										@gamussa										#PhillyETE
Which Java version are you on?
A. Java 7
B. Java 8
C. Java 9
D. Java 6
E. Java 5
										@gamussa										#PhillyETE
Which Java version are you on?
A. Java 7
B. Java 8
C. Java 9
D. Java 6
E. Java 5
F. Java 2
										@gamussa										#PhillyETE
Which Java version are you on?
A. Java 7
B. Java 8
C. Java 9
D. Java 6
E. Java 5
F. Java 2
										@gamussa										#PhillyETE
Watching the puzzlers like… #dafaq
										@gamussa										#PhillyETE
Watching the puzzlers like… #dafaq
										@gamussa										#PhillyETE
Everything works (or doesn't) 

in the latest Java 8 and/or 9 update
										@gamussa										#PhillyETE
RUSSIAN HACKERS
HACKING THE BANK
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());

}

}

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
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
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
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
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
@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
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());

}

}

@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
Available
-42?!
										@gamussa										#PhillyETE
Available
-42?!
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
Collections.emptyList() == Collections.emptyList();

Collections.emptyIterator() == Collections.emptyIterator();

										@gamussa										#PhillyETE
A. true/true
Collections.emptyList() == Collections.emptyList();

Collections.emptyIterator() == Collections.emptyIterator();

										@gamussa										#PhillyETE
A. true/true
B. true/false
Collections.emptyList() == Collections.emptyList();

Collections.emptyIterator() == Collections.emptyIterator();

										@gamussa										#PhillyETE
A. true/true
B. true/false
C. false/true
Collections.emptyList() == Collections.emptyList();

Collections.emptyIterator() == Collections.emptyIterator();

										@gamussa										#PhillyETE
A. true/true
B. true/false
C. false/true
D. false/false
Collections.emptyList() == Collections.emptyList();

Collections.emptyIterator() == Collections.emptyIterator();

										@gamussa										#PhillyETE
A. true/true
B. true/false
C. false/true
D. false/false
Collections.emptyList() == Collections.emptyList();

Collections.emptyIterator() == Collections.emptyIterator();

										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();

Stream.empty() == Stream.empty();

A. true/true
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();

Stream.empty() == Stream.empty();

A. true/true
B. true/false
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();

Stream.empty() == Stream.empty();

A. true/true
B. true/false
C. false/true
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();

Stream.empty() == Stream.empty();

A. true/true
B. true/false
C. false/true
D. false/false
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();

Stream.empty() == Stream.empty();

A. true/true
B. true/false
C. false/true
D. false/false
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();

Stream.empty() == Stream.empty();

Singleton Strikes Back!
										@gamussa										#PhillyETE
Singleton Strikes Back!
										@gamussa										#PhillyETE
A. true/true
B. true/false
C. false/true
D. false/false
Spliterators.emptySpliterator() == Spliterators.emptySpliterator();

Stream.empty() == Stream.empty();

										@gamussa										#PhillyETE
Even empty Stream has state!
										@gamussa										#PhillyETE
Even empty Stream has state!
										@gamussa										#PhillyETE
Even empty Stream has state!
										@gamussa										#PhillyETE
”Identical”
1. Has the same state
2. Not related to “equals and hashcode” contract
3. Not related to references to objects in
memory
										@gamussa										#PhillyETE
List[] twins = new List[2];

Arrays.setAll(twins, ArrayList::new);

										@gamussa										#PhillyETE
List[] twins = new List[2];

Arrays.setAll(twins, ArrayList::new);

A. Absolutely identical empty lists
										@gamussa										#PhillyETE
List[] twins = new List[2];

Arrays.setAll(twins, ArrayList::new);

A. Absolutely identical empty lists
B. Absolutely identical non-empty lists
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
How single is a Single Abstract Method
Interface?
										@gamussa										#PhillyETE
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> { }
										@gamussa										#PhillyETE
A. WTF?! ’Single’ means one, not three!
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> { }
										@gamussa										#PhillyETE
A. WTF?! ’Single’ means one, not three!
B. Problem is with partyHard(T), remove it and it will work
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> { }
										@gamussa										#PhillyETE
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
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> { }
										@gamussa										#PhillyETE
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> { }
										@gamussa										#PhillyETE
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> { }
										@gamussa										#PhillyETE
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> { }
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
RUSSIAN HACKERS
STILL TRYING TO HACK THE BANK
Hacking the bank
☑Bank software written in Java
☑Hack into it
☑Analyze the accounts
										@gamussa										#PhillyETE
Given the code above, which statement is wrong:
Set<String>	accounts=	new	HashSet<>(Arrays.asList("Gates",	"Buffett",	"Bezos",	"Zuckerberg"));

	System.out.println(”accounts=	"	+	accounts);

										@gamussa										#PhillyETE
Given the code above, which statement is wrong:
A. The Set is ordered by hashcode
Set<String>	accounts=	new	HashSet<>(Arrays.asList("Gates",	"Buffett",	"Bezos",	"Zuckerberg"));

	System.out.println(”accounts=	"	+	accounts);

										@gamussa										#PhillyETE
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
Set<String>	accounts=	new	HashSet<>(Arrays.asList("Gates",	"Buffett",	"Bezos",	"Zuckerberg"));

	System.out.println(”accounts=	"	+	accounts);

										@gamussa										#PhillyETE
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
Set<String>	accounts=	new	HashSet<>(Arrays.asList("Gates",	"Buffett",	"Bezos",	"Zuckerberg"));

	System.out.println(”accounts=	"	+	accounts);

										@gamussa										#PhillyETE
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);

										@gamussa										#PhillyETE
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);

										@gamussa										#PhillyETE
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);

										@gamussa										#PhillyETE
public boolean add(E e) {

return map.put(e, PRESENT)==null;

}
										@gamussa										#PhillyETE
Your turn, FBI
										@gamussa										#PhillyETE
Given the code above, which statement is wrong:
Set<String>	accounts	=	Set.of("Gates",	"Buffett",	"Bezos",	"Zuckerberg");

	System.out.println(”accounts=	"	+	accounts);
										@gamussa										#PhillyETE
Given the code above, which statement is wrong:
A. The Set is ordered
Set<String>	accounts	=	Set.of("Gates",	"Buffett",	"Bezos",	"Zuckerberg");

	System.out.println(”accounts=	"	+	accounts);
										@gamussa										#PhillyETE
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
Set<String>	accounts	=	Set.of("Gates",	"Buffett",	"Bezos",	"Zuckerberg");

	System.out.println(”accounts=	"	+	accounts);
										@gamussa										#PhillyETE
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
Set<String>	accounts	=	Set.of("Gates",	"Buffett",	"Bezos",	"Zuckerberg");

	System.out.println(”accounts=	"	+	accounts);
										@gamussa										#PhillyETE
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);
										@gamussa										#PhillyETE
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);
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
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);
										@gamussa										#PhillyETE
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;

}

}

}
										@gamussa										#PhillyETE
Juggling Accident
Juggling Accident
What’s correct?
										@gamussa										#PhillyETE
What’s correct?
A. If you convert your application to module, classpath
dependencies will still be resolved correctly
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
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);

}

A. You killed them all
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);

}

A. You killed them all
B. You killed only even ones
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);

}

A. You killed them all
B. You killed only even ones
C. They all survived
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);

}

A. You killed them all
B. You killed only even ones
C. They all survived
D. You killed only odd ones
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);

}

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);

}

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);

}

@gamussa										#PhillyETE
@gamussa										#PhillyETE
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.
										@gamussa										#PhillyETE
Don’t do that. Really, don’t.
killThemAll(new ArrayList<String>(Arrays.asList("N","S","W","S","L","S","L","V")));

[]
										@gamussa										#PhillyETE
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")));
										@gamussa										#PhillyETE
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]
										@gamussa										#PhillyETE
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]
										@gamussa										#PhillyETE
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]
										@gamussa										#PhillyETE
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")));
										@gamussa										#PhillyETE
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]
										@gamussa										#PhillyETE
Subtle Difference
										@gamussa										#PhillyETE
@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
@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
@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
@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. 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. 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;

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;

@gamussa										#PhillyETE
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.	
“
										@gamussa										#PhillyETE
List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk",
"Spock").sequential()

.filter(new TreeSet<>()::add).collect(Collectors.toList());

System.out.println(list);

										@gamussa										#PhillyETE
A.[Data, Kirk, Spock]
List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk",
"Spock").sequential()

.filter(new TreeSet<>()::add).collect(Collectors.toList());

System.out.println(list);

										@gamussa										#PhillyETE
A.[Data, Kirk, Spock]
B.[Spock, Kirk, Data, Data, Kirk, Spock]
List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk",
"Spock").sequential()

.filter(new TreeSet<>()::add).collect(Collectors.toList());

System.out.println(list);

										@gamussa										#PhillyETE
A.[Data, Kirk, Spock]
B.[Spock, Kirk, Data, Data, Kirk, Spock]
C.[Spock, Kirk, Data]
List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk",
"Spock").sequential()

.filter(new TreeSet<>()::add).collect(Collectors.toList());

System.out.println(list);

										@gamussa										#PhillyETE
A.[Data, Kirk, Spock]
B.[Spock, Kirk, Data, Data, Kirk, Spock]
C.[Spock, Kirk, Data]
D.[Data, Data, Kirk, Kirk, Spock, Spock]
List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk",
"Spock").sequential()

.filter(new TreeSet<>()::add).collect(Collectors.toList());

System.out.println(list);

										@gamussa										#PhillyETE
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);

										@gamussa										#PhillyETE
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);

										@gamussa										#PhillyETE
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);

										@gamussa										#PhillyETE
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);

										@gamussa										#PhillyETE
@gamussa										#PhillyETE
filter(new TreeSet<>()::add)
										@gamussa										#PhillyETE
filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))
										@gamussa										#PhillyETE
filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))!=
										@gamussa										#PhillyETE
filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))!=
New	instance	is	
created	every	time!
										@gamussa										#PhillyETE
filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))!=
New	instance	is	
created	every	time!
Instance	method	is	
created	once!
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
Optional.of("obvious").orElseGet(null);

Optional.empty().map(null).orElse("obvious");
										@gamussa										#PhillyETE
A. obvious / obvious
Optional.of("obvious").orElseGet(null);

Optional.empty().map(null).orElse("obvious");
										@gamussa										#PhillyETE
A. obvious / obvious
B. obvious / NullPointerException
Optional.of("obvious").orElseGet(null);

Optional.empty().map(null).orElse("obvious");
										@gamussa										#PhillyETE
A. obvious / obvious
B. obvious / NullPointerException
C. NullPointerException / obvious
Optional.of("obvious").orElseGet(null);

Optional.empty().map(null).orElse("obvious");
										@gamussa										#PhillyETE
A. obvious / obvious
B. obvious / NullPointerException
C. NullPointerException / obvious
D. NullPointerException / NullPointerException
Optional.of("obvious").orElseGet(null);

Optional.empty().map(null).orElse("obvious");
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
A. obvious / obvious
B. obvious / NullPointerException
C. NullPointerException / obvious
D. NullPointerException / NullPointerException
Optional.of("obvious").orElseGet(null);

Optional.empty().map(null).orElse("obvious");
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
A. obvious / obvious
B. obvious / NullPointerException
C. NullPointerException / obvious
D. NullPointerException / NullPointerException
Optional.of("obvious").orElseGet(null);

Optional.empty().map(null).orElse("obvious");
										@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
@gamussa										#PhillyETE
Identical?
										@gamussa										#PhillyETE
When agentA == agentB?
1. Consumer<String> agentA = s -> System.out.println(s);

Consumer<String> agentB = s -> System.out.println(s);
When agentA == agentB?
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;
When agentA == agentB?
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();
When agentA == agentB?
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?
A.All
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?
A.All
B.3 and 4
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?
A.All
B.3 and 4
C.Only 3
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?
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?
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?
@gamussa										#PhillyETE
@gamussa										#PhillyETE
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
										@gamussa										#PhillyETE
Reuse is only possible for pure functions
Consumers accept parameters ==
have state
										@gamussa										#PhillyETE
Reuse is only possible for pure functions
Consumers accept parameters ==
have state
Supplier in 4 has state – the
resolved method reference
										@gamussa										#PhillyETE
Conclusions
										@gamussa										#PhillyETE
-Write readable code!
-Write readable code!
-Comment all the tricks
-Write readable code!
-Comment all the tricks
-Sometimes it’s just a bug
-Write readable code!
-Comment all the tricks
-Sometimes it’s just a bug
-Static code analysis FTW -
IntelliJ IDEA!
-Write readable code!
-Comment all the tricks
-Sometimes it’s just a bug
-Static code analysis FTW -
IntelliJ IDEA!
-RTFM!
-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.
-Trust us, we have much
more where those came
from.
-Puzzlers? Gotchas? Fetal
position inducing behavior?
-Trust us, we have much
more where those came
from.
-Puzzlers? Gotchas? Fetal
position inducing behavior?
-puzzlers@jfrog.com
-Did you like it?
-Did you like it?
-Praise me on twitter!
-Did you like it?
-Praise me on twitter!
-#javapuzzlersng #PhillyETE
-Did you like it?
-Praise me on twitter!
-#javapuzzlersng #PhillyETE
-@gamussa
-Did you like it?
-Praise me on twitter!
-#javapuzzlersng #PhillyETE
-@gamussa
-Didn’t like it?
-Did you like it?
-Praise me on twitter!
-#javapuzzlersng #PhillyETE
-@gamussa
-Didn’t like it?
-/dev/null

More Related Content

Similar to [Philly ETE] Java Puzzlers NG

Testing ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using RubyTesting ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using Ruby
Ben Hall
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fabio Akita
 
Sass maps, my precious! 2.0
Sass maps, my precious! 2.0Sass maps, my precious! 2.0
Sass maps, my precious! 2.0
Andréa Zambrana
 
GCRC 2014 - The Dark Side of Ruby
GCRC 2014 - The Dark Side of RubyGCRC 2014 - The Dark Side of Ruby
GCRC 2014 - The Dark Side of Ruby
Gautam Rege
 
Hack the Future
Hack the FutureHack the Future
Hack the Future
Jason McCreary
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
Michelangelo van Dam
 
Metrics on the front, data in the back
Metrics on the front, data in the backMetrics on the front, data in the back
Metrics on the front, data in the back
DiUS
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confoo
Damien Seguy
 
Crush Candy with DukeScript
Crush Candy with DukeScriptCrush Candy with DukeScript
Crush Candy with DukeScript
Anton Epple
 
Developer Tests - Things to Know
Developer Tests - Things to KnowDeveloper Tests - Things to Know
Developer Tests - Things to Know
Vaidas Pilkauskas
 
Groovy Basics
Groovy BasicsGroovy Basics
Groovy Basics
Wes Williams
 

Similar to [Philly ETE] Java Puzzlers NG (11)

Testing ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using RubyTesting ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using Ruby
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
Sass maps, my precious! 2.0
Sass maps, my precious! 2.0Sass maps, my precious! 2.0
Sass maps, my precious! 2.0
 
GCRC 2014 - The Dark Side of Ruby
GCRC 2014 - The Dark Side of RubyGCRC 2014 - The Dark Side of Ruby
GCRC 2014 - The Dark Side of Ruby
 
Hack the Future
Hack the FutureHack the Future
Hack the Future
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Metrics on the front, data in the back
Metrics on the front, data in the backMetrics on the front, data in the back
Metrics on the front, data in the back
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confoo
 
Crush Candy with DukeScript
Crush Candy with DukeScriptCrush Candy with DukeScript
Crush Candy with DukeScript
 
Developer Tests - Things to Know
Developer Tests - Things to KnowDeveloper Tests - Things to Know
Developer Tests - Things to Know
 
Groovy Basics
Groovy BasicsGroovy Basics
Groovy Basics
 

More from Viktor Gamov

[DataSciCon] Divide, distribute and conquer stream v. batch
[DataSciCon] Divide, distribute and conquer  stream v. batch[DataSciCon] Divide, distribute and conquer  stream v. batch
[DataSciCon] Divide, distribute and conquer stream v. batch
Viktor Gamov
 
[Philly JUG] Divide, Distribute and Conquer: Stream v. Batch
[Philly JUG] Divide, Distribute and Conquer: Stream v. Batch[Philly JUG] Divide, Distribute and Conquer: Stream v. Batch
[Philly JUG] Divide, Distribute and Conquer: Stream v. Batch
Viktor Gamov
 
Distributed caching for your next node.js project cf summit - 06-15-2017
Distributed caching for your next node.js project   cf summit - 06-15-2017Distributed caching for your next node.js project   cf summit - 06-15-2017
Distributed caching for your next node.js project cf summit - 06-15-2017
Viktor Gamov
 
Распределяй и властвуй — 2: Потоки данных наносят ответный удар
Распределяй и властвуй — 2: Потоки данных наносят ответный ударРаспределяй и властвуй — 2: Потоки данных наносят ответный удар
Распределяй и властвуй — 2: Потоки данных наносят ответный удар
Viktor Gamov
 
[JBreak] Блеск И Нищета Распределенных Стримов - 04-04-2017
[JBreak] Блеск И Нищета Распределенных Стримов - 04-04-2017[JBreak] Блеск И Нищета Распределенных Стримов - 04-04-2017
[JBreak] Блеск И Нищета Распределенных Стримов - 04-04-2017
Viktor Gamov
 
[OracleCode - SF] Distributed caching for your next node.js project
[OracleCode - SF] Distributed caching for your next node.js project[OracleCode - SF] Distributed caching for your next node.js project
[OracleCode - SF] Distributed caching for your next node.js project
Viktor Gamov
 
[OracleCode SF] In memory analytics with apache spark and hazelcast
[OracleCode SF] In memory analytics with apache spark and hazelcast[OracleCode SF] In memory analytics with apache spark and hazelcast
[OracleCode SF] In memory analytics with apache spark and hazelcast
Viktor Gamov
 
[Jfokus] Riding the Jet Streams
[Jfokus] Riding the Jet Streams[Jfokus] Riding the Jet Streams
[Jfokus] Riding the Jet Streams
Viktor Gamov
 
[NYJavaSig] Riding the Distributed Streams - Feb 2nd, 2017
[NYJavaSig] Riding the Distributed Streams - Feb 2nd, 2017[NYJavaSig] Riding the Distributed Streams - Feb 2nd, 2017
[NYJavaSig] Riding the Distributed Streams - Feb 2nd, 2017
Viktor Gamov
 
[Codemash] Caching Made "Bootiful"!
[Codemash] Caching Made "Bootiful"![Codemash] Caching Made "Bootiful"!
[Codemash] Caching Made "Bootiful"!
Viktor Gamov
 
[JokerConf] Верхом на реактивных стримах, 10/13/2016
[JokerConf] Верхом на реактивных стримах, 10/13/2016[JokerConf] Верхом на реактивных стримах, 10/13/2016
[JokerConf] Верхом на реактивных стримах, 10/13/2016
Viktor Gamov
 
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
Viktor Gamov
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
Viktor Gamov
 
Functional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAFunctional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIA
Viktor Gamov
 
Testing Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user groupTesting Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user group
Viktor Gamov
 

More from Viktor Gamov (15)

[DataSciCon] Divide, distribute and conquer stream v. batch
[DataSciCon] Divide, distribute and conquer  stream v. batch[DataSciCon] Divide, distribute and conquer  stream v. batch
[DataSciCon] Divide, distribute and conquer stream v. batch
 
[Philly JUG] Divide, Distribute and Conquer: Stream v. Batch
[Philly JUG] Divide, Distribute and Conquer: Stream v. Batch[Philly JUG] Divide, Distribute and Conquer: Stream v. Batch
[Philly JUG] Divide, Distribute and Conquer: Stream v. Batch
 
Distributed caching for your next node.js project cf summit - 06-15-2017
Distributed caching for your next node.js project   cf summit - 06-15-2017Distributed caching for your next node.js project   cf summit - 06-15-2017
Distributed caching for your next node.js project cf summit - 06-15-2017
 
Распределяй и властвуй — 2: Потоки данных наносят ответный удар
Распределяй и властвуй — 2: Потоки данных наносят ответный ударРаспределяй и властвуй — 2: Потоки данных наносят ответный удар
Распределяй и властвуй — 2: Потоки данных наносят ответный удар
 
[JBreak] Блеск И Нищета Распределенных Стримов - 04-04-2017
[JBreak] Блеск И Нищета Распределенных Стримов - 04-04-2017[JBreak] Блеск И Нищета Распределенных Стримов - 04-04-2017
[JBreak] Блеск И Нищета Распределенных Стримов - 04-04-2017
 
[OracleCode - SF] Distributed caching for your next node.js project
[OracleCode - SF] Distributed caching for your next node.js project[OracleCode - SF] Distributed caching for your next node.js project
[OracleCode - SF] Distributed caching for your next node.js project
 
[OracleCode SF] In memory analytics with apache spark and hazelcast
[OracleCode SF] In memory analytics with apache spark and hazelcast[OracleCode SF] In memory analytics with apache spark and hazelcast
[OracleCode SF] In memory analytics with apache spark and hazelcast
 
[Jfokus] Riding the Jet Streams
[Jfokus] Riding the Jet Streams[Jfokus] Riding the Jet Streams
[Jfokus] Riding the Jet Streams
 
[NYJavaSig] Riding the Distributed Streams - Feb 2nd, 2017
[NYJavaSig] Riding the Distributed Streams - Feb 2nd, 2017[NYJavaSig] Riding the Distributed Streams - Feb 2nd, 2017
[NYJavaSig] Riding the Distributed Streams - Feb 2nd, 2017
 
[Codemash] Caching Made "Bootiful"!
[Codemash] Caching Made "Bootiful"![Codemash] Caching Made "Bootiful"!
[Codemash] Caching Made "Bootiful"!
 
[JokerConf] Верхом на реактивных стримах, 10/13/2016
[JokerConf] Верхом на реактивных стримах, 10/13/2016[JokerConf] Верхом на реактивных стримах, 10/13/2016
[JokerConf] Верхом на реактивных стримах, 10/13/2016
 
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
 
Functional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAFunctional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIA
 
Testing Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user groupTesting Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user group
 

Recently uploaded

The Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdfThe Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdf
mohitd6
 
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
manji sharman06
 
Photoshop Tutorial for Beginners (2024 Edition)
Photoshop Tutorial for Beginners (2024 Edition)Photoshop Tutorial for Beginners (2024 Edition)
Photoshop Tutorial for Beginners (2024 Edition)
alowpalsadig
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
confluent
 
What’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 UpdateWhat’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 Update
VictoriaMetrics
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Vince Scalabrino
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
ICS
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
michniczscribd
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
sandeepmenon62
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio, Inc.
 
Hands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion StepsHands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion Steps
servicesNitor
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Best Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP ImplementationBest Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP Implementation
Envertis Software Solutions
 
Hyperledger Besu 빨리 따라하기 (Private Networks)
Hyperledger Besu 빨리 따라하기 (Private Networks)Hyperledger Besu 빨리 따라하기 (Private Networks)
Hyperledger Besu 빨리 따라하기 (Private Networks)
wonyong hwang
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
Paul Brebner
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
Boost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management AppsBoost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management Apps
Jhone kinadey
 

Recently uploaded (20)

The Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdfThe Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdf
 
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
 
Photoshop Tutorial for Beginners (2024 Edition)
Photoshop Tutorial for Beginners (2024 Edition)Photoshop Tutorial for Beginners (2024 Edition)
Photoshop Tutorial for Beginners (2024 Edition)
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
 
What’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 UpdateWhat’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 Update
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
 
Hands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion StepsHands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion Steps
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Best Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP ImplementationBest Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP Implementation
 
Hyperledger Besu 빨리 따라하기 (Private Networks)
Hyperledger Besu 빨리 따라하기 (Private Networks)Hyperledger Besu 빨리 따라하기 (Private Networks)
Hyperledger Besu 빨리 따라하기 (Private Networks)
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
Boost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management AppsBoost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management Apps
 

[Philly ETE] Java Puzzlers NG

  • 1. This slide is intentionally left blank
  • 2. JAVA PUZZLERS NG DOWN THE RABBIT HOLEhttp://www.davidfloresmedia.com/philly-rocky-statue/
  • 3. @gAmUssA @hazelcast #jbreak #hazelcastjet > whoami
  • 4. @gAmUssA @hazelcast #jbreak #hazelcastjet Solutions Architect > whoami
  • 5. @gAmUssA @hazelcast #jbreak #hazelcastjet Solutions Architect Developer Advocate > whoami
  • 6. @gAmUssA @hazelcast #jbreak #hazelcastjet Solutions Architect Developer Advocate @gamussa in internetz > whoami
  • 7. @gAmUssA @hazelcast #jbreak #hazelcastjet Solutions Architect Developer Advocate @gamussa in internetz Please, follow me on Twitter > whoami
  • 8. @gAmUssA @hazelcast #jbreak #hazelcastjet Solutions Architect Developer Advocate @gamussa in internetz Please, follow me on Twitter I’m very interesting © > whoami
  • 9.
  • 10.
  • 11. Developer Advocate @JFrog on the internetz Developer Advocate @Hazelcast @gAmUssA on the internetz
  • 12. CLICK AND HACK THE TYPE-IT BROTHERS
  • 17.
  • 18. 1. Two One entertaining guy on the stage
  • 19. 1. Two One entertaining guy on the stage 2. Funny puzzling questions
  • 20. 1. Two One entertaining guy on the stage 2. Funny puzzling questions 3. You think and vote
  • 21. 1. Two One entertaining guy on the stage 2. Funny puzzling questions 3. You think and vote 4.Official twitter hashtags #javapuzzlersng #PhillyETE
  • 22. FIRST RULE OF THE PUZZLERS: NO CHEATING!
  • 23. Which Java version are you on? @gamussa #PhillyETE
  • 24. Which Java version are you on? A. Java 7 @gamussa #PhillyETE
  • 25. Which Java version are you on? A. Java 7 B. Java 8 @gamussa #PhillyETE
  • 26. Which Java version are you on? A. Java 7 B. Java 8 C. Java 9 @gamussa #PhillyETE
  • 27. Which Java version are you on? A. Java 7 B. Java 8 C. Java 9 D. Java 6 @gamussa #PhillyETE
  • 28. Which Java version are you on? A. Java 7 B. Java 8 C. Java 9 D. Java 6 E. Java 5 @gamussa #PhillyETE
  • 29. Which Java version are you on? A. Java 7 B. Java 8 C. Java 9 D. Java 6 E. Java 5 F. Java 2 @gamussa #PhillyETE
  • 30. Which Java version are you on? A. Java 7 B. Java 8 C. Java 9 D. Java 6 E. Java 5 F. Java 2 @gamussa #PhillyETE
  • 31. Watching the puzzlers like… #dafaq @gamussa #PhillyETE
  • 32. Watching the puzzlers like… #dafaq @gamussa #PhillyETE
  • 33. Everything works (or doesn't) 
 in the latest Java 8 and/or 9 update @gamussa #PhillyETE
  • 34.
  • 36. 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());
 }
 }

  • 37. 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
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. 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
  • 45. 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());
 }
 }

  • 52. Collections.emptyList() == Collections.emptyList();
 Collections.emptyIterator() == Collections.emptyIterator();
 @gamussa #PhillyETE
  • 53. A. true/true Collections.emptyList() == Collections.emptyList();
 Collections.emptyIterator() == Collections.emptyIterator();
 @gamussa #PhillyETE
  • 54. A. true/true B. true/false Collections.emptyList() == Collections.emptyList();
 Collections.emptyIterator() == Collections.emptyIterator();
 @gamussa #PhillyETE
  • 55. A. true/true B. true/false C. false/true Collections.emptyList() == Collections.emptyList();
 Collections.emptyIterator() == Collections.emptyIterator();
 @gamussa #PhillyETE
  • 56. A. true/true B. true/false C. false/true D. false/false Collections.emptyList() == Collections.emptyList();
 Collections.emptyIterator() == Collections.emptyIterator();
 @gamussa #PhillyETE
  • 57. A. true/true B. true/false C. false/true D. false/false Collections.emptyList() == Collections.emptyList();
 Collections.emptyIterator() == Collections.emptyIterator();
 @gamussa #PhillyETE
  • 61. A. true/true Spliterators.emptySpliterator() == Spliterators.emptySpliterator();
 Stream.empty() == Stream.empty();

  • 62. A. true/true B. true/false Spliterators.emptySpliterator() == Spliterators.emptySpliterator();
 Stream.empty() == Stream.empty();

  • 63. A. true/true B. true/false C. false/true Spliterators.emptySpliterator() == Spliterators.emptySpliterator();
 Stream.empty() == Stream.empty();

  • 64. A. true/true B. true/false C. false/true D. false/false Spliterators.emptySpliterator() == Spliterators.emptySpliterator();
 Stream.empty() == Stream.empty();

  • 65. A. true/true B. true/false C. false/true D. false/false Spliterators.emptySpliterator() == Spliterators.emptySpliterator();
 Stream.empty() == Stream.empty();

  • 68. A. true/true B. true/false C. false/true D. false/false Spliterators.emptySpliterator() == Spliterators.emptySpliterator();
 Stream.empty() == Stream.empty();
 @gamussa #PhillyETE
  • 69. Even empty Stream has state! @gamussa #PhillyETE
  • 70. Even empty Stream has state! @gamussa #PhillyETE
  • 71. Even empty Stream has state! @gamussa #PhillyETE
  • 72.
  • 73. ”Identical” 1. Has the same state 2. Not related to “equals and hashcode” contract 3. Not related to references to objects in memory @gamussa #PhillyETE
  • 74. List[] twins = new List[2];
 Arrays.setAll(twins, ArrayList::new);
 @gamussa #PhillyETE
  • 75. List[] twins = new List[2];
 Arrays.setAll(twins, ArrayList::new);
 A. Absolutely identical empty lists @gamussa #PhillyETE
  • 76. List[] twins = new List[2];
 Arrays.setAll(twins, ArrayList::new);
 A. Absolutely identical empty lists B. Absolutely identical non-empty lists @gamussa #PhillyETE
  • 77. 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 @gamussa #PhillyETE
  • 78. 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 @gamussa #PhillyETE
  • 79. 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 @gamussa #PhillyETE
  • 82. 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 @gamussa #PhillyETE
  • 86. How single is a Single Abstract Method Interface? @gamussa #PhillyETE
  • 87. 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> { } @gamussa #PhillyETE
  • 88. A. WTF?! ’Single’ means one, not three! 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> { } @gamussa #PhillyETE
  • 89. A. WTF?! ’Single’ means one, not three! B. Problem is with partyHard(T), remove it and it will work 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> { } @gamussa #PhillyETE
  • 90. 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 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> { } @gamussa #PhillyETE
  • 91. 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> { } @gamussa #PhillyETE
  • 92. 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> { } @gamussa #PhillyETE
  • 93.
  • 94.
  • 95. 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> { } @gamussa #PhillyETE
  • 97. RUSSIAN HACKERS STILL TRYING TO HACK THE BANK
  • 98. Hacking the bank ☑Bank software written in Java ☑Hack into it ☑Analyze the accounts @gamussa #PhillyETE
  • 99. Given the code above, which statement is wrong: Set<String> accounts= new HashSet<>(Arrays.asList("Gates", "Buffett", "Bezos", "Zuckerberg"));
 System.out.println(”accounts= " + accounts);
 @gamussa #PhillyETE
  • 100. Given the code above, which statement is wrong: A. The Set is ordered by hashcode Set<String> accounts= new HashSet<>(Arrays.asList("Gates", "Buffett", "Bezos", "Zuckerberg"));
 System.out.println(”accounts= " + accounts);
 @gamussa #PhillyETE
  • 101. 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 Set<String> accounts= new HashSet<>(Arrays.asList("Gates", "Buffett", "Bezos", "Zuckerberg"));
 System.out.println(”accounts= " + accounts);
 @gamussa #PhillyETE
  • 102. 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 Set<String> accounts= new HashSet<>(Arrays.asList("Gates", "Buffett", "Bezos", "Zuckerberg"));
 System.out.println(”accounts= " + accounts);
 @gamussa #PhillyETE
  • 103. 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);
 @gamussa #PhillyETE
  • 104. 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);
 @gamussa #PhillyETE
  • 105.
  • 106.
  • 107. 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);
 @gamussa #PhillyETE
  • 108. public boolean add(E e) {
 return map.put(e, PRESENT)==null;
 } @gamussa #PhillyETE
  • 110.
  • 111. Given the code above, which statement is wrong: Set<String> accounts = Set.of("Gates", "Buffett", "Bezos", "Zuckerberg");
 System.out.println(”accounts= " + accounts); @gamussa #PhillyETE
  • 112. Given the code above, which statement is wrong: A. The Set is ordered Set<String> accounts = Set.of("Gates", "Buffett", "Bezos", "Zuckerberg");
 System.out.println(”accounts= " + accounts); @gamussa #PhillyETE
  • 113. 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 Set<String> accounts = Set.of("Gates", "Buffett", "Bezos", "Zuckerberg");
 System.out.println(”accounts= " + accounts); @gamussa #PhillyETE
  • 114. 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 Set<String> accounts = Set.of("Gates", "Buffett", "Bezos", "Zuckerberg");
 System.out.println(”accounts= " + accounts); @gamussa #PhillyETE
  • 115. 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); @gamussa #PhillyETE
  • 116. 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); @gamussa #PhillyETE
  • 120. 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); @gamussa #PhillyETE
  • 121. 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;
 }
 }
 } @gamussa #PhillyETE
  • 125. What’s correct? A. If you convert your application to module, classpath dependencies will still be resolved correctly @gamussa #PhillyETE
  • 126. 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 @gamussa #PhillyETE
  • 127. 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 @gamussa #PhillyETE
  • 128. 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 @gamussa #PhillyETE
  • 129. 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 @gamussa #PhillyETE
  • 130.
  • 131.
  • 132. 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 @gamussa #PhillyETE
  • 135.
  • 136. 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);
 }

  • 137. A. You killed them all 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);
 }

  • 138. A. You killed them all B. You killed only even ones 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);
 }

  • 139. A. You killed them all B. You killed only even ones C. They all survived 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);
 }

  • 140. A. You killed them all B. You killed only even ones C. They all survived D. You killed only odd ones 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);
 }

  • 141. 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);
 }

  • 142. 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);
 }

  • 145. 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);
 }

  • 146. Don’t do that. Really, don’t. @gamussa #PhillyETE
  • 147. Don’t do that. Really, don’t. killThemAll(new ArrayList<String>(Arrays.asList("N","S","W","S","L","S","L","V")));
 [] @gamussa #PhillyETE
  • 148. 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"))); @gamussa #PhillyETE
  • 149. 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] @gamussa #PhillyETE
  • 150. 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] @gamussa #PhillyETE
  • 151. 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] @gamussa #PhillyETE
  • 152. 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"))); @gamussa #PhillyETE
  • 153. 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] @gamussa #PhillyETE
  • 155. @FunctionalInterface
 public interface OriginalPredicate<T> {
 boolean test(T t);
 } OriginalPredicate<Object> lambda = (Object obj) -> "adidas".equals(obj);
 OriginalPredicate<Object> methodRef = "adidas"::equals;
  • 156. A. Both work just fine @FunctionalInterface
 public interface OriginalPredicate<T> {
 boolean test(T t);
 } OriginalPredicate<Object> lambda = (Object obj) -> "adidas".equals(obj);
 OriginalPredicate<Object> methodRef = "adidas"::equals;
  • 157. A. Both work just fine B. Lambda works, method ref fails @FunctionalInterface
 public interface OriginalPredicate<T> {
 boolean test(T t);
 } OriginalPredicate<Object> lambda = (Object obj) -> "adidas".equals(obj);
 OriginalPredicate<Object> methodRef = "adidas"::equals;
  • 158. A. Both work just fine B. Lambda works, method ref fails C. Method ref works, lambda fails @FunctionalInterface
 public interface OriginalPredicate<T> {
 boolean test(T t);
 } OriginalPredicate<Object> lambda = (Object obj) -> "adidas".equals(obj);
 OriginalPredicate<Object> methodRef = "adidas"::equals;
  • 159. 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;
  • 160. 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;
  • 161.
  • 162.
  • 163. 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;

  • 164. 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;

  • 165.
  • 166.
  • 167.
  • 168. 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;

  • 171.
  • 172. List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk", "Spock").sequential()
 .filter(new TreeSet<>()::add).collect(Collectors.toList());
 System.out.println(list);
 @gamussa #PhillyETE
  • 173. A.[Data, Kirk, Spock] List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk", "Spock").sequential()
 .filter(new TreeSet<>()::add).collect(Collectors.toList());
 System.out.println(list);
 @gamussa #PhillyETE
  • 174. A.[Data, Kirk, Spock] B.[Spock, Kirk, Data, Data, Kirk, Spock] List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk", "Spock").sequential()
 .filter(new TreeSet<>()::add).collect(Collectors.toList());
 System.out.println(list);
 @gamussa #PhillyETE
  • 175. A.[Data, Kirk, Spock] B.[Spock, Kirk, Data, Data, Kirk, Spock] C.[Spock, Kirk, Data] List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk", "Spock").sequential()
 .filter(new TreeSet<>()::add).collect(Collectors.toList());
 System.out.println(list);
 @gamussa #PhillyETE
  • 176. A.[Data, Kirk, Spock] B.[Spock, Kirk, Data, Data, Kirk, Spock] C.[Spock, Kirk, Data] D.[Data, Data, Kirk, Kirk, Spock, Spock] List<String> list = Stream.of("Spock", "Kirk", "Data", "Data", "Kirk", "Spock").sequential()
 .filter(new TreeSet<>()::add).collect(Collectors.toList());
 System.out.println(list);
 @gamussa #PhillyETE
  • 177. 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);
 @gamussa #PhillyETE
  • 178.
  • 179.
  • 180. 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);
 @gamussa #PhillyETE
  • 181. 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);
 @gamussa #PhillyETE
  • 182.
  • 183.
  • 184. 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);
 @gamussa #PhillyETE
  • 187. filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i)) @gamussa #PhillyETE
  • 188. filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))!= @gamussa #PhillyETE
  • 189. filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))!= New instance is created every time! @gamussa #PhillyETE
  • 190. filter(new TreeSet<>()::add) filter(i -> new TreeSet<>().add(i))!= New instance is created every time! Instance method is created once! @gamussa #PhillyETE
  • 193. A. obvious / obvious Optional.of("obvious").orElseGet(null);
 Optional.empty().map(null).orElse("obvious"); @gamussa #PhillyETE
  • 194. A. obvious / obvious B. obvious / NullPointerException Optional.of("obvious").orElseGet(null);
 Optional.empty().map(null).orElse("obvious"); @gamussa #PhillyETE
  • 195. A. obvious / obvious B. obvious / NullPointerException C. NullPointerException / obvious Optional.of("obvious").orElseGet(null);
 Optional.empty().map(null).orElse("obvious"); @gamussa #PhillyETE
  • 196. A. obvious / obvious B. obvious / NullPointerException C. NullPointerException / obvious D. NullPointerException / NullPointerException Optional.of("obvious").orElseGet(null);
 Optional.empty().map(null).orElse("obvious"); @gamussa #PhillyETE
  • 199. A. obvious / obvious B. obvious / NullPointerException C. NullPointerException / obvious D. NullPointerException / NullPointerException Optional.of("obvious").orElseGet(null);
 Optional.empty().map(null).orElse("obvious"); @gamussa #PhillyETE
  • 200. 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 @gamussa #PhillyETE
  • 201. 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 @gamussa #PhillyETE
  • 202. 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 @gamussa #PhillyETE
  • 205. A. obvious / obvious B. obvious / NullPointerException C. NullPointerException / obvious D. NullPointerException / NullPointerException Optional.of("obvious").orElseGet(null);
 Optional.empty().map(null).orElse("obvious"); @gamussa #PhillyETE
  • 211. When agentA == agentB?
  • 212. 1. Consumer<String> agentA = s -> System.out.println(s);
 Consumer<String> agentB = s -> System.out.println(s); When agentA == agentB?
  • 213. 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; When agentA == agentB?
  • 214. 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(); When agentA == agentB?
  • 215. 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?
  • 216. A.All 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?
  • 217. A.All B.3 and 4 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?
  • 218. A.All B.3 and 4 C.Only 3 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?
  • 219. 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?
  • 220. 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?
  • 223. 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?
  • 224. Reuse is only possible for pure functions @gamussa #PhillyETE
  • 225. Reuse is only possible for pure functions Consumers accept parameters == have state @gamussa #PhillyETE
  • 226. Reuse is only possible for pure functions Consumers accept parameters == have state Supplier in 4 has state – the resolved method reference @gamussa #PhillyETE
  • 228.
  • 231. -Write readable code! -Comment all the tricks -Sometimes it’s just a bug
  • 232. -Write readable code! -Comment all the tricks -Sometimes it’s just a bug -Static code analysis FTW - IntelliJ IDEA!
  • 233. -Write readable code! -Comment all the tricks -Sometimes it’s just a bug -Static code analysis FTW - IntelliJ IDEA! -RTFM!
  • 234. -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!
  • 235.
  • 236. -Trust us, we have much more where those came from.
  • 237. -Trust us, we have much more where those came from. -Puzzlers? Gotchas? Fetal position inducing behavior?
  • 238. -Trust us, we have much more where those came from. -Puzzlers? Gotchas? Fetal position inducing behavior? -puzzlers@jfrog.com
  • 239.
  • 241. -Did you like it? -Praise me on twitter!
  • 242. -Did you like it? -Praise me on twitter! -#javapuzzlersng #PhillyETE
  • 243. -Did you like it? -Praise me on twitter! -#javapuzzlersng #PhillyETE -@gamussa
  • 244. -Did you like it? -Praise me on twitter! -#javapuzzlersng #PhillyETE -@gamussa -Didn’t like it?
  • 245. -Did you like it? -Praise me on twitter! -#javapuzzlersng #PhillyETE -@gamussa -Didn’t like it? -/dev/null