Available since Java 1.5 is the nice helper class EnumSet and I still find code like this way to often: public class Foo { enum Thing { A, B, C } public static final Set<Thing> THINGS = new HashSet<>(); static { THINGS.add(Thing.A); THINGS.add(Thing.B); THINGS.add(Thing.C); } }public class Foo { enum Thing { A, B, […]
This is a post where i want to collect some new expressions i’m learning on my way to Java 8. Hopefully i’ll keep updating it… Use an IntStream to generate an Array with constant default values // The "() -> 23" is a lambda that matches the functional interface of a Supplier // The the […]
You don’t need JConsole or similar for just displaying the approximate uptime of your application respectively your Java Virtual Machine: import java.lang.management.ManagementFactory; public class Demo { public static void main(String… args) { final long uptime = ManagementFactory.getRuntimeMXBean().getUptime(); System.out.println(String.format("Up for %dms", uptime)); } }import java.lang.management.ManagementFactory; public class Demo { public static void main(String… args) { […]
Spring 3 has excellent support for mapping URLs to @Controller methods through the @RequestMapping annotation. This works quite well and i especially like the fact having the mapping right next to the method and not in some other config file like routes.rb. My goal was to have urls like http://foobar.com/resource, http://foobar.com/resource.html, http://foobar.com/resource.zip etc. This is […]
There’s a nice little “sleep” procedure in Oracle: A procedure that stops the execution of the current thread for n seconds. Strangely, this method can be called in SQL*Plus like so: EXEC dbms_lock.sleep(10);exec dbms_lock.sleep(10); but not in another stored procedure or function like so CREATE OR REPLACE PROCEDURE FOOBAR AS BEGIN DBMS_LOCK.SLEEP(1); END; /CREATE OR […]