Converting String to UTF8?

Lets see what happens when trying to convert random string into UTF8 using different methods. [code lang=”java”] package org.kari.test.string; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.Charset; import org.apache.log4j.Logger; import org.kari.log.LogUtil; import org.kari.util.DirectByteArrayOutputStream; /** * Test UTF8 conversion * * @author kari */ public class UTF8Test { public static final Logger LOG = LogUtil.getLogger(”utf8”); private static final…

Read more

Interactive javascript shell

Naive, but functional interactive javascript shell with Java 6. [code lang=”java”] package org.kari.test.script; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; import org.apache.log4j.Logger; import org.kari.log.LogUtil; /** * Test interactive javascript shell * * @author kari */ public class ScriptShell { public static final Logger LOG = LogUtil.getLogger(”script.shell”); private final…

Read more

Git Book

Quite usefull reference: Pro Git Update: 7.10.2010 What you need to know about your version control system

Read more

”Must have” utility

Java Decompiler Best part is that there is also Eclipse plugin in addition to standalone utility, which seems to also work reasonably well with Eclipse 3.5.1.

Read more

Oops, I did it again….

Compressed oops in the Hotspot JVM Big Question is why to bother? And the answer is Cache. In other words, using shorter pointers allows fitting more data into processor caches, which improves performance considerably. References: 32-bit or 64-bit JVM? How about a Hybrid? <a href=”http://blog.juma.me.uk/2009/04/03/load-unsigned-and-better-compressed-oops/”>Load unsigned and better Compressed Oops

Read more

Reducing memory usage

Example 31-2. Setting fetch size to turn cursors on and off. PostgreSql, JDBC and large result sets Large ResultSet on postgresql query Is JDBC a big memory hog? Setting some reasonable fetch size might be meaningfull when working with results sets consisting from thousands of elements. Appearent difference is that with default fetch size, all…

Read more

Compact String Dictionary

If system needs to process lots of short strings, which actually quite often are same, then using some dictionary to map strings into compact unique identifiers can improve memory usage and performance quite a bit. [code lang=”java”] package org.kari.test.string; import gnu.trove.TObjectIntHashMap; import java.util.ArrayList; import java.util.List; /** * Dictionary mapping strings int compact identifiers * *…

Read more

Going to DB…

Open Source Database Engines in Java Hmm…. H2? When developing software with Java, why anyone would bother with non-Java DB, i.e. all the problems with native library compatibility and such (32bit/64bit, Linux/Windows/etc., M$XP/M$Vista/M$7/…)? Especially interesting sounds the possibility to embed DB into java process, thus avoiding having separate process and socket (or such) communication with…

Read more

Comments…

every line of code should be commented Easy. 10 lines, no comments. After writing a couple of million lines of code, the more code I write, the more I unwind it. Somewhere along the line, adolescent programmers got the idea that jamming all your logic into as few unreadable lines as possible is the fastest…

Read more

Use only max 8KB IO buffer?!?

When wondering strange performance issues in socket IO, I peeked into native code in input stream, and noticed that logic is following: 1) If buffer is smaller (or equal) to 8KB then use stack 2) If not then malloc() Since memory allocation is not ever free, it sounds possible that such memory allocation can cause…

Read more