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
// From http://www.gsis.gr/gsis/info/gsis_site/Services/Polites/sources.html | |
// gr.gsis.e7.E7File class | |
// Apache 2.0 license | |
public static boolean afmIsValid(String afm) { | |
int sum = 0; | |
if (afm.length() != 9) | |
return false; | |
for (int i = 0; i < 8; i++) |
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.*; | |
public class JavaChampionTest { | |
public static void main(String... args) { | |
Map<JavaChampion, String> urls = new HashMap<>(); | |
urls.put(new JavaChampion("Jack"), "fasterj.com"); | |
urls.put(new JavaChampion("Kirk"), "kodewerk.com"); | |
urls.put(new JavaChampion("Heinz"), "javaspecialists.eu"); | |
urls.forEach((p,u) -> System.out.println(u)); // Java 8 |
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.lang.reflect.*; | |
public class SillyPuzzle { | |
public static void main(String... args) { | |
prepareForSillyPuzzle(); | |
show(6 + 4); | |
show(9 + 2); | |
show(8 + 5); | |
show(5 + 2); | |
show(9 + 8); |
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.*; | |
import java.nio.file.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.stream.*; | |
public class LuckyDraw { | |
public static void main(String... args) throws IOException { | |
List<Entry> list = Files.lines(Paths.get("luckydraw.csv")) | |
.map(Entry::new) |
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.math.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.function.*; | |
/** | |
* Seems to cause livelock in Java 8 ConcurrentHashMap transfer() | |
* method and ConcurrentModificationException in Java 9 HashMap. | |
*/ | |
public class WeirdComputeIfAbsentBehaviour { |
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.lang.management.ManagementFactory; | |
import java.lang.management.ThreadMXBean; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.InvocationTargetException; | |
import java.lang.reflect.Method; | |
import java.util.Arrays; | |
import java.util.Set; | |
import java.util.Timer; | |
import java.util.TimerTask; |
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
/* | |
Algorithm is exponential - very bad. It is just meant to exercise the CPU a bit and | |
to see what happens with different languages. Not representative of real code. | |
Interesting that Java beats C, thanks to HotSpot. I expected Swift to be as fast as C | |
at least. I also expected the compiled Swift to be faster than when run as a script. | |
A bit disappointed, but more time needed to see where the bottlenecks are. Plus I | |
need to run some real code for benchmarking. | |
Update: swiftc -O improved the speed quite a bit to be about the same speed as Java | |
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
abstract class Brick { | |
public Brick() { | |
greet(); | |
} | |
public abstract void greet(); | |
} | |
public class HardPlace { | |
public class Between extends Brick { |
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
/* | |
All it takes is the "lazy" keyword in front of the var definition and the object is instantiated when it is first used. Brilliant. | |
*/ | |
class MoralFibre { | |
init() { | |
print("***Creating MoralFibre***") | |
} | |
func actSociallyResponsibly() -> Int { | |
print("supporting local soup kitchen") |
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
/** | |
* As seen on https://javaspecialists.slack.com/messages/general | |
* | |
* This class fails to compile with JDK 1.6, 1.7 and 1.8: | |
* | |
* class Two extends Observable { // Nothing special about the choice of Observable here | |
* ^ | |
* symbol: class Observable | |
* 1 error | |
* |
OlderNewer