There are many substantial differences between .NET and Java. Each has advantages and disadvantages. Here I would like to highlight a few striking features which are uniquely powerful in each.
All software should be this easy to use.
As more and more applications run in these environments, it will become increasingly important to enable true shared libraries to reduce memory usage on the machine. ngen allows this because multiple applications can each map and use a common version of the precompiled version of an assembly.
// java collection nastiness Hashtable t = new Hashtable(); // HashtableHashtable t_int = new Hashtable(); // Hashtable t.put("foo", new MyObject()); MyObject o = (MyObject) t.get("foo"); t_int.put("bar",new Integer(3)); int val = ((Integer) t_int.get("bar")).intValue(); Iterator itr = t.keys(); while (itr.hasNext()) { String n = (String) itr.next(); // ... } Enumerator e = t.elements(); while (e.hasMoreElements()) { MyObject o = (MyObject) itr.nextElement(); // .. }
The first version of .NET took two steps. The first one with it's unified type system, solving the manual "int"<->"Integer" conversions which must be done in Java. The second one with the foreach() loop construct to make iterating collections easier.
The next version of C#/.NET will solve the type-coercion and weak-compile-time-checking of untyped collections by adding Generics support. Generics also allows important performance speedups on value-type collections, such as integer keyed hashtables. Current Java and C# implementations of integer keyed hashtables are slowed than script languages like Perl and Python because of the overheard of creating "boxed Integer objects" when interacting with these collections. Generics allows type-specific versions of this code to be compiled, eliminating the "boxed Integer object" creation.
// C# with new Generics support HashtableThe next version of Java is rumored to be including Generics support as well. The Java implementation of Generics will not solve the manual boxing required for Java's basic datatypes or the performance problems which result. However, it does have some unique features, including paramaterized types at the method level, type inference for generic methods, and somewhat transparent interfacing with unparamaterized types in Legacy code. [more]t = new Hashtable (); Hashtable t_int = new Hashtable (); t.put("foo", new MyObject()); MyObject o = t.get("foo"); t_int.put("bar",3); int val = t_int.get("bar"); foreach (String n in t.keys()) { // ... } foreach (MyObject o in t.elements()) { // ... }