This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean login(User user) { | |
// Check if we have a valid user/pass pair | |
String hashedPassword = hash(user.getPassword()); | |
String jpql = "SELECT u FROM User u WHERE u.username=:userName AND u.password=:password"; | |
TypedQuery<User> query = entityManager.createQuery(jpql, User.class); | |
query.setParameter("userName", user.getUsername()); | |
query.setParameter("password", hash); | |
List<User> users = query.getResultList(); | |
return !users.isEmpty(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
bar.libraryCall("hello", 1); | |
int i = 1; | |
if (i < 0) { | |
throw new NoSuchMethodError(); | |
} | |
} | |
catch (NoSuchMethodError e) { | |
bar.libraryCall("hello"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.foo; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.concurrent.CountDownLatch; | |
public class SynchronizedCollectionIteration { | |
public static void main(String[] args) { | |
final CountDownLatch latch = new CountDownLatch(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.foo; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.CountDownLatch; | |
public class UnsynchronizedCollectionAccess { | |
public static void main(String[] args) throws InterruptedException { | |
final CountDownLatch latch = new CountDownLatch(1); | |
final List<Integer> list = new ArrayList<Integer>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CyclicBarrierTest { | |
public static void main(String[] args) { | |
final CyclicBarrier barrier = new CyclicBarrier(2); | |
Runnable r = new Runnable() { | |
@Override | |
public void run() { | |
try { | |
for (int i = 0; i < 5; i++) { | |
System.out.println(Thread.currentThread().getName() + " waits for the other ones"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExceptionRethrow { | |
void foo() throws IOException { | |
try { | |
bar(); | |
} | |
catch (Exception e) { | |
throw e; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class VerticalTabDemo { | |
public static String buildMessage() { | |
StringBuilder message = new StringBuilder(); | |
message.append('\u000b'); | |
message.append('H'); | |
char[] characters = message.toString().toCharArray(); // returns length 2 | |
System.out.println("characters.length in buildMessage = " + characters.length); | |
dumpString(message.toString()); | |
return message.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Bar { | |
} | |
public class Foo { | |
@Autowired | |
public void setBar(Bar bar) { | |
System.out.println("setBar() was called"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocalDateExample { | |
public static void main(String[] args) { | |
LocalDate ld1 = LocalDate.now(); | |
LocalDate ld2 = LocalDate.now().plusDays(2); | |
System.out.println("comparison = " + compare(ld1, ld2)); | |
} | |
private static <T extends Temporal> int compare(T t1, T t2) { | |
Comparable<T> c1 = (Comparable<T>) t1; | |
return c1.compareTo(t2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
public class LockFileTest { | |
public static void main(String[] args) throws IOException { | |
File lockFile = File.createTempFile("foo", ".lock"); | |
int read; |
OlderNewer