This file contains hidden or 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 com.sun.org.apache.xml.internal.security.utils.Base64; | |
import javax.crypto.*; | |
import javax.crypto.spec.IvParameterSpec; | |
import javax.crypto.spec.PBEKeySpec; | |
import javax.crypto.spec.SecretKeySpec; | |
import java.io.UnsupportedEncodingException; | |
import java.security.*; | |
import java.security.spec.InvalidKeySpecException; | |
import java.security.spec.InvalidParameterSpecException; |
This file contains hidden or 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.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
import java.lang.reflect.Method; | |
public class TestRunner { | |
public static void main(String[] args) { | |
System.out.println("Testing..."); |
This file contains hidden or 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 Java8ParallelStream { | |
public static void main(String[] args) { | |
List<String> values = new ArrayList<>(); | |
int max = 1000000; | |
for (int i = 0; i < max; i++) { | |
UUID id = UUID.randomUUID(); | |
values.add(id.toString()); | |
} | |
NoArgsFunction sequential = () -> values.stream().sorted().count(); |
This file contains hidden or 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
class OldStyle(): | |
def __init__(self): | |
print "Init old style" | |
def func(self, arg): | |
print "Invoked old func with: {}".format(arg) | |
class NewStyle(object): |
This file contains hidden or 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.BufferedWriter; | |
import java.io.IOException; | |
import java.nio.charset.Charset; | |
import java.nio.file.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
import static java.nio.file.StandardOpenOption.*; | |
import static java.nio.file.StandardCopyOption.*; |
This file contains hidden or 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.*; | |
/** | |
* Serialize and deserialize an object. Also demonstrates how constructors are invoked on deserialization. | |
*/ | |
public class SerializeDeserialize { | |
public static void main(String[] args) throws IOException, ClassNotFoundException { | |
Bar myBar = new Bar(); |
This file contains hidden or 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.concurrent.ForkJoinPool; | |
import java.util.concurrent.RecursiveTask; | |
/** | |
* Solve a computing task with the ForkJoin framework. | |
*/ | |
public class MyForkJoinPool { | |
private static final int NTHREADS = 10; |
This file contains hidden or 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.concurrent.*; | |
/** | |
* Use a callable to retrieve values from tasks executed in a thread pool. | |
*/ | |
public class CallableFuture { | |
public static void main(String[] args) { | |
Callable<Long> task = new Factorial(20); |
This file contains hidden or 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.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* A thread pool with the executor framework to execute tasks. Also demonstrates a simple timeout mechanism. | |
*/ | |
public class ThreadPool { | |
private static final int NTHREADS = Runtime.getRuntime().availableProcessors(); |
This file contains hidden or 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.IOException; | |
import java.nio.file.*; | |
import static java.nio.file.StandardWatchEventKinds.*; | |
/** | |
* Watch a directory for changes using a WatchService. | |
*/ | |
public class DirWatcher { |