All posts tagged with 'Code Snippets'

On my way to Java 8


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 […]

Read the complete article »

Get the uptime of your Java VM


You don’t need JConsole or similar for just displaying the approximate uptime of your application respectively your Java Virtual Machine: import;   public class Demo { public static void main(String… args) { final long uptime = ManagementFactory.getRuntimeMXBean().getUptime(); System.out.println(String.format("Up for %dms", uptime)); } } If you use Joda-Time (and you should if you have anything […]

Read the complete article »

Creating a better PathMatcher for Spring 3


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,, etc. This is […]

Read the complete article »

Oracle “sleep” procedure: DBMS_LOCK.SLEEP


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); but not in another stored procedure or function like so CREATE OR REPLACE PROCEDURE FOOBAR AS BEGIN DBMS_LOCK.SLEEP(1); END; / To use […]

Read the complete article »

How to get UIDefaults in Java


If you’re loocking for Javas UIDefaults, use the UIManager class. This snippet gives you all installed UIDefaults: UIDefaults defaults = UIManager.getDefaults(); for(Enumeration e = defaults.keys(); e.hasMoreElements(); ){ String key = e.nextElement().toString(); System.out.println(key + " = " + defaults.get(key)); }

Read the complete article »