What major advantages does C# have over Java?

Matt Davey just posted about a presentation to management types where they asked the question (among others)

What major advantage does the C# language have over and above the Java language?“

My first thought was “attributes“ which allow developers to tag code with metadata that can be programmed against but I was sure there was more. Since I’m not a C# guru I did a quick web search and found a great essay entitled "A comparison of Microsoft’s C# Programming Language to Sun Microsystem’s Java Programming Language" by Dare Obasanjo.

Dare listed the following things C# has that Java does not:

  1. Deterministic Object Cleanup
  2. Delegates
  3. Enumerations
  4. Value Types (Structs)
  5. Boxing
  6. Run Time Type Identification (as operator)
  7. foreach Statement
  8. Properties
  9. Multidimensional Arrays
  10. Attributes
  11. Indexers
  12. Preprocessor Directives
  13. Aliases
  14. Runtime Code Generation
  15. Pointers and Unsafe Code
  16. Pass by Reference
  17. Variable Length Parameter Lists
  18. Verbatim Strings
  19. Overflow Detection
  20. Explicit Interface Implementation

That’s a lot!  Though that list is great, it was written as a list for developers, not managers. The question then would be, which of these differences could actually translate into a benefit a manager could appreciate?

I’ll take a stab at this, but would love comments from others on how to best present C# as having values business people can appreciate. I can’t find a direct business benefit for some of these features:

  • Without Deterministic Object Cleanup Java apps could create unacceptable performance bottlenecks after deployment, which could cost a lot of time and money to fix.
  • Delegates allows a more flexible implementation of callbacks, which reduces the complexity of code and reduces the likelyhood of logic errors.
  • Enumerations increase robustness by providing type checking and reduces “copy&paste“ errors because enumerations can be converted to their string equivalent. Java developers will need to spend more time testing and debugging. 
  • Properties allow more natural syntax. If Java programmers “get lazy“, write directly to fields, and later need to trigger code on a field assignment, they have to modify a lot of client code.  If they get lazy in .NET, they can just change the field to a property w/o affecting client code. However it does take a recompile (I’ve always hated that about .NET)
  • Attributes allow developers to embed metadata and program against that metadata. This increases the power and flexibility available to a software architect designing an application framework. .NET modules are discoverable which greatly reduces the need to distribute related information across multiple source files. This reduces potential errors and hence testing and development time as well as increases reliability and robustness. In my mind this is probably one of the strongest benefits of using C# over Java.
  • Runtime Code Generation allows an application to implement its own extensions based on user imput. Most developers will never attempt this, but when it is useful there really isn’t an alternative.
  • Overflow Detection increases robustness and reliabiliy because potentially critical errors that might go unnoticed in Java will be caught by the .NET runtime.
  • Explicit Interface Implementation can offer significant cost savings when naming conflict occur during code integration, especially if those conflicts are in 3rd party components.

That’s my list. BTW, I think VB.NET offers all the same benefits.  Do you have more?

7 Replies to “What major advantages does C# have over Java?”

  1. i want to know the platform on which c# operates .and its relationship to database and networking.

  2. c# operates on windows platform, it has the capabilities to work with all the major RDBMS, like oracle, MS SQL, and many others

  3. what is core(fundamental) advantage of c#?
    d.none of the above

Leave a Reply

Your email address will not be published. Required fields are marked *