Calling C From Java Is Easy

Sometimes we need to access operating system functions that the standard Java API doesn’t expose, or use non-Java libraries. Although it’s well known that you can call this “native code” from Java using JNI, there is not so much entry-level material on how it’s actually done. It is often left out of introductory material–including the official …

The JVM ate my variable!

Consider this code: Object obj = new Object(); WeakReference<Object> ref = new WeakReference<Object>(obj); List<byte[]> filler = new LinkedList<byte[]>(); while (ref.get() != null) { filler.add(new byte[1000]); } System.out.println(“Filler size ” + filler.size()); When executed it should always run out of memory: ref.get() will not return null because the referenced object cannot be garbage collected. The local …

MySQL Collations in practice

Collations are important for how text is ordered by indices and ORDER BY clauses; in fact a collation defines the order. Sadly developers seem to often ignore collations in data models, and the database default settings are used. If you are using MySQL and haven’t configured any particular collation, your database is probably sorted according to …