Talk:Comparison of C Sharp and Java

This is an old revision of this page, as edited by Tbjablin (talk | contribs) at 02:08, 24 April 2005 (Virtual machine?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

How does Java have a simpler language? The CLR has some JIT time optimizations as well as runtiem optimizations. Java and C# run at about the same speed really. It might not be true that Java is faster.

The article needs to be cleaned a bit... Some entries are listed as both advantages for one language and disadvantages for the other, which is at best redundant. Otherwise, it's not bad; quite complete now. GregorB 22:49, Jan 31, 2005 (UTC)

I think there is good reason for pointers to be listed as both an advantage and a disadvantage for C#. I don't think there exists enough consensus about whether pointers should be used in managed languages. It might be appropriate to go into more detail about how pointers are implemented with relative safety in C# on another page and then link it. Tbjablin 05:36, 8 Feb 2005 (UTC)

I've decided it belongs in differences after all. Tbjablin 05:44, 8 Feb 2005 (UTC)

  • Both languages allow the use of enumerations, via the enum keyword.

As far as I recall, this is false. C# uses the enum keyword, whereas Java uses a Class (link java.lang.Enum) introduced in Java 1.5. I haven't edited the page to reflect this, as I am unsure and would like confirmation first.

In Java 5.0 enums are lower case, like types, and have their own syntax.

 private enum Coin {
   penny(1), nickel(5), dime(10), quarter(25);
   Coin(int value) { this.value = value; }
   private final int value;
   public int value() { return value; }
 }

Also enums can be used in switches. Classes cannot be used this way.

 switch(menu) {
   case FILE:
     System.out.println("FILE Menu");
     break;
   case EDIT:
     System.out.println("EDIT Menu");
     break;
   case FORMAT:
     System.out.println("FORMAT Menu");
     break;
   case VIEW:
     System.out.println("VIEW Menu");
     break;

}

Check out http://java.sun.com/developer/technicalArticles/releases/j2se15langfeat/ http://zamples.com/JspExplorer/samples/jdk1_5.jsp http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html

In Java even arrays are technically classes ie

   Object o = new int[10];

Further compiling:

   public class Test {
       private int enum = 10;
   }

Yields the error:

   Test.java:2: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
   (try -source 1.4 or lower to use 'enum' as an identifier)
       private int enum = 10;
                   ^
   1 error

My inclination is to call it a keyword, because of the new syntax, and the compiler error. Tbjablin 04:34, 9 Mar 2005 (UTC)

Yeah, it seems pretty clear that enum is a keyword in Java. Neilc 01:08, 10 Mar 2005 (UTC)

Virtual machine?

C# is compiled to MSIL which is compiled into native machine code; Java is compiled into .class files which are interpreted by the JVM. The article says they both run on a virtual machine, but C# does not. I ran a series of benchmarks which I posted here and am quite sure that C# is appreciably faster than Java.

Both C# and Java use JIT compilation. Java can run in interpretted mode and even has a flag for it java -Xint, but java -Xmixed (interpretted mode mixed with compilation) is the default. You might want to try rerunning your benchmark with java -server -Xincgc -Xmx512M and Java 1.5 Tbjablin 01:25, 24 Apr 2005 (UTC)

Also, looking at your benchmarks they are quite clearly dominated by Java's slow startup time. You might consider benchmarks that run for atleast a minute. Compare your results with [[1]] at that time Java was outprerforming C# in every area except trig performance, but things may have changed since then. Tbjablin 01:33, 24 Apr 2005 (UTC)