Friday, November 4, 2011

More C# and Java Differences

Features of C# Absent in Java

  • C# includes more primitive types and the functionality to catch arithmetic exceptions.
  • Includes a large number of notational conveniences over Java, many of which, such as operator overloading and user-defined casts, are already familiar to the large community of C++ programmers.
  • Event handling is a "first class citizen"—it is part of the language itself.
  • Allows the definition of "structs", which are similar to classes but may be allocated on the stack (unlike instances of classes in C# and Java).
  • C# implements properties as part of the language syntax.
  • C# allows switch statements to operate on strings.
  • C# allows anonymous methods providing closure functionality.
  • C# allows iterator that employs co-routines via a functional-style yield keyword.
  • C# has support for output parameters, aiding in the return of multiple values, a feature shared by C++ and SQL.

Difference between C# and Java

Following are some important and key difference in the language C# and Java!!!

#10 – Give me my standard output!

This may not seem like a big deal, but when I’m first getting my head in a language, I want to be able to debug. With everything so new and shiny, I don’t want to hear about the debugger yet, I don’t care about the fancy message boxes, just tell me how to get something on standard output!
In C#, the code looks like this:
Console.WriteLine("your string here");

#9 – Namespaces == Freedom

In Java, the package hierarchical structure mirrored the directory hierarchical structure. This made sense to a degree, but then why didn’t Sun just auto-derive the package structure? Anyway, Microsoft has freed us from this constraint. The C# package structure is defined using namespaces (just like Java), but the namespaces do NOT have to reflect the directory structure.

#8 – What happened to super?

Slight renaming of keywords drives me bonkers! Substitute Java’s super keyword with base.