Java Myths and Legends.

Overview.

There are a lot of Java documentation which has not been update in more than 10 years. Additionally there is a lot of documentation which was never correct.

Things you can't do in Java.

You cannot write a max of two values which returns the same type.

Alex Stepanov in 2001, before generics in Java

Max of two values with Java 5
public static <T extends Comparable> T max(T a, T b) {
   return a.compareTo(b) > 0 ? a : b;
}

You cannot write a swap or linear search of two values.

Alex Stepanov in 2001

Collections and Arrays both have binary search implementations. I think its reasonable assume a linear search is simpler than these.
Collections and Arrays both have sorting routines which use swap() methods. This is not the purist implementation Alex meant, however here is a real use case were swap is used.

C++ is faster than Java.

In practice, many C++ libraries are single threaded and cannot take advantage of multiple threads. These single threaded libraries were often written that way on the basis that single threaded code is faster (on one CPU) However it doesn't scale.
A multi-threaded Java application will typically run faster than a single threaded C++ application on a multi-core system.

To make use of all the cores on a server you need as many active threads as CPUs. However having more active threads than cores actually hurts performance.

Java Legends.

See also

http://www.cs.umd.edu/users/jmanson/java/presentations/sdwest2008.ppt

For historical comparison.

http://norvig.com/java-iaq.html
http://www.codeguru.com/java/tij/tij0203.shtml

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.