Split Pascalcase String

Do you ever need to split a camel case or pascal case string to a set of words? This can be achieved simply by regular expressions in Java as well as C#. The following code is for Java: String camelCase = “StructuralDesignPattern”; StringBuffer label = new StringBuffer(camelCase + 10); java.util.regex.Pattern p = java.util.regex.Pattern.compile(“[A-Z][a-z]+”); java.util.regex.Matcher m = p.matcher(camelCase); while ( m.find() ) { label.append( m.group() + ” “); } System.out.println(camelCase + ” >> ” + label.toString()); [ Note: this does not work for all test cases. You may also want to try regexp as “[A-Z][a-z]+”, for matching any continues uppercase letters…

Read more

Unreachable code Error or Warning?

In Java, unreachable code is treated as compilation error. What do you think? Isn’t making it warning would have made developers’ life simpler? Of course you can write – if( true )    return; What if you could simply write return. This helps in testing a function quickly. As a good programming practice we always remove all warnings from code, and such unconditional return statements can be rectified later.

Read more

Setting up SDB for MySQL

Jena is a semantic web framework implemented in Java. It allows you to store/query/inference RDF/RDSF/OWL triples. In Jena a set of triples (in RDF) are called Model or stored within Model object. By default Jena creates in-memory models, but this is not suitable if you have pretty large set of triples to process. Here comes SDB to rescue you. It’s a component of Jena that allows you to store these models in relational databases like MySQL, MSSQL, PostgreSQL, Oracle, etc; This post describes my experience while setting up SDB on Ubuntu. Download SDB. Extract it into some folder. SDB works…

Read more

Setting Default JVM on Ubuntu

Heard of ‘update-alternatives’ on Linux? It’s a smart utility to find various versions of one software and set default. For example, you may have GNU Java as well as Sun Java. (frankly saying, I hate GNU Java, aka gcj) sudo update-alternatives –config java [ Where can I see all installed JVM? On Ubuntu, Java Virtual Machines are installed in /usr/lib/jvm. You can see java-gcj here which comes by default with Ubuntu. ] – ankit

Read more