The Reflection API is a fairly shocking example of the needless verbosity of Java. And I would consider the official API to be part of Java.
Here's a simplistic example in Java and Ruby, replacing characters in a string ("putty" => "puppy") first directly and then via reflective invocation:
// Java
String s = "putty";
System.out.println(s.replace('t', 'p'));
try {
Class c = s.getClass();
Method m = c.getMethod("replace", char.class, char.class);
System.out.println(m.invoke(s, 't', 'p'));
} catch (Exception e) {
e.printStackTrace();
}
# Ruby
s = "putty"
puts s.gsub("t", "p")
puts s.send("gsub", "t", "p")
This kind of verbosity is prevalent in Java's standard libraries, particularly when (anonymous) inner classes are involved. At the moment I'm struggling with "doPrivileged" blocks in some Java code which deals with sandboxing, and it is syntactically very unpleasant.
Ok, we could chain the Java calls together and knock some lines off, but it's still not nice:
try {
System.out.println(s.getClass().getMethod("replace", char.class, char.class).invoke(s, 't', 'p'));
} catch (Exception e) {
e.printStackTrace();
}