It's because browsers do not have interpreters for java. They interpret javascript. The DOM is a model that can be used anywhere, but it used mostly in the browser environment, and browsers have optimized DOM parsing over the years... for javascript.
The reason browsers have optimized DOM parsing is due to the fact that DOM parsing is a cornerstone of dynamic web development. Consider the normal way to make a page more dynamic:
1.) Listen for some events fired on the page.
2.) When those events are fired, modify some number of DOM objects,
e.g., by changing their visibility, geometry, or actually moving
them to other portions of the DOM.
The reason the DOM is important here is because it provides a specification for storing a document in browser memory so that an entire page doesn't have to be re-rendered by changes to small portions of the markup. And these DOM objects stored in browser memory are structured just like native javascript objects; therefore, it's easier to optimize for javascript against them.
And ever since dynamic web pages have become essential, browsers have been fighting each other tooth and nail to have the fastest custom javascript interpreter, and in a dynamic web environment, the main place where you're going to be able to see the most rewards for optimizing is DOM parsing.
I can't see the pressing need in a java environment to use a DOM, but it's absolutely essential in a browser environment. That is the most likely reason you have seen better optimizations in javascript for DOM parsing than java. More people have a vested interest in making it work in the browser. However, for clarification, I'm not sure of the exact technical reasons at the code level why it's actually faster.
[citation-needed]