Many HttpServletRequest properties can be confusing, so I decided to create this cheat sheet. (Properties can have similar names, some properties contain delimiters and some don’t, etc.) Let’s say your domain is domain.com, and it points to a router which forwards the request to port 8080 on a server called bob with a local IP [...]
Tag Archives: java
The Java DOM API sucks
Posted December 23, 2009 – 7:55 pmHow it sucks
I recently wrote some code to filter nodes from a DOM and had issues with NullPointerExceptions:
NodeList nl = doc.getElementsByTagName(“mytag”);
for(int i = 0, n = nl.getLength(); i < n; i++) {
Element elt = (Element) nl.item(i);
if(…) {
elt.getParentNode().removeChild(elt);
}
}
The problem was that NodeLists are live, and removing elements while iterating changes the indexes. When I tried to [...]
Double.equals pitfalls
Posted September 11, 2009 – 12:12 pmIt turns out that Double.equals is not always the same as == with two double primitives. Case in point:
double a = Double.NaN;
System.out.println(a == a);
Double b = new Double(a);
System.out.println(b.equals(b));
This code will print out false and true.
What’s going on? Basically, if you look at the Javadoc for the equals method, it says that “two double values are [...]
Using scripts to hide complexity and only making it worse
Posted August 25, 2009 – 9:29 pmI recently had to work with software that is customizable using Jython script. As much as I like both Java and Python, this environment was a nightmare.
The problem was the inability to write Python in the Python script. First off was the old version of Python. The script was limited to version 2.1 (8 [...]