I was thinking about the following scenario the other day: Give an experienced cook a dull knife. The blade slips and he cuts himself. Give an inexperienced cook a sharp knife. He doesn’t hold it right and he cuts himself.
Author Archives: Joni
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 …
Runtime.exec with Unix console programs
Ever wanted to launch less or vi from a console Java program to show or edit a file, only to find that they won’t work like when you launch them from the terminal?
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 …