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
// Annotation1.java | |
package bar.baz; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
@Retention(RetentionPolicy.RUNTIME) |
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 bar.baz; | |
import java.awt.BorderLayout; | |
import java.awt.Color; | |
import java.awt.Dimension; | |
import javax.swing.BorderFactory; | |
import javax.swing.Box; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; |
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 ButtonTest { | |
public static void main(String[] args) { | |
SwingUtilities.invokeLater(new Runnable() { | |
@Override | |
public void run() { | |
showGUI(); | |
} | |
} | |
); | |
} |
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 static BigInteger fact(int a) { | |
if (a == 0) { | |
return BigInteger.ONE; | |
} | |
return BigInteger.valueOf(a).multiply(fact(a - 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
import java.util.ArrayList; | |
import java.util.List; | |
public class GenericsFun { | |
public static void main(String[] args) { | |
List<B> bs = new ArrayList<>(); | |
bs.add(new B()); | |
List<? extends A> mix = bs; | |
appendFirstElementToList(mix); | |
System.out.println("mix.size() = " + mix.size()); |
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.util.Arrays; | |
public class ArrayTest { | |
public static void main(String[] args) { | |
int[] array = new int[] {1, 2, 3, 4}; | |
foo(array); | |
System.out.println("array in main : " + Arrays.toString(array)); | |
} | |
private static void foo(int[] array) { |
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>(); |
OlderNewer