When using JDBC, I often come across constructs like I asked myself (and authors of code too) why not to use labels for retrieving column values: The best explanation I’ve heard is something concerning performance. But actually, does it make processing extremely fast? I don’t believe so, though I …
Tag: java
Dynamically find the class that represents a primitive Java type
I need to make some reflective method calls in Java. Those calls will include methods that have arguments that are primitive types (int, double, etc.). The way to specify such types when looking up the method reflectively is int.class, double.class, etc. The challenge is that I am accepting input from an outs…
The encoding ‘UTF-8’ is not supported by the Java runtime
Whenever I start our Apache Felix (OSGi) based application under SUN Java ( build 1.6.0_10-rc2-b32 and other 1.6.x builds) I see the following message output on the console (usually under Ubuntu 8.4): Warning: The encoding ‘UTF-8’ is not supported by the Java runtime. I’ve seen this message …
How to upgrade JRE
Is there anyway to upgrade the installed JRE in the system? We are having 1.5.0_08 installed in out HP Unix system.We have to upgrade this to 1.5.0_15.Is there a way to patch up the existing JRE and upgrade to a newer version.Or can this only be achieved by installing the newer JRE and set this in the system …
How do I add a shortcut key to Eclipse 3.2 Java plug-in to build the current project?
One of the few annoying things about the Eclipse Java plug-in is the absence of a keyboard shortcut to build the project associated with the current resource. Anyone know how to go about it? Answer In the Preferences dialog box, under the General section is a dialog box called “Keys”. This lets yo…
Regular expression to match URLs in Java
I use RegexBuddy while working with regular expressions. From its library I copied the regular expression to match URLs. I tested successfully within RegexBuddy. However, when I copied it as Java String flavor and pasted it into Java code, it does not work. The following class prints false: Does anyone know w…
How do you assert that a certain exception is thrown in JUnit tests?
How can I use JUnit idiomatically to test that some code throws an exception? While I can certainly do something like this: I recall that there is an annotation or an Assert.xyz or something that is far less kludgy and far more in-the-spirit of JUnit for these sorts of situations. Answer It depends on the JUn…
Equivalent of PHP’s print_r in Java?
last time I asked how to populate a data structure here. Now I would like to know if there’s something in Java, like the print_r I use in PHP, to represent what I have populated in the Maps and lists without having to do my own algorithm. Any ideas? Answer Calling toString on the collection should retur…
Exception thrown inside catch block – will it be caught again?
This may seem like a programming 101 question and I had thought I knew the answer but now find myself needing to double check. In this piece of code below, will the exception thrown in the first catch block then be caught by the general Exception catch block below? I always thought the answer would be no, but…
How to pretty print XML from Java?
I have a Java String that contains XML, with no line feeds or indentations. I would like to turn it into a String with nicely formatted XML. How do I do this? Note: My input is a String. My output is a String. (Basic) mock result: Answer Now it’s 2012 and Java can do more than it used to with