Almost four years ago I wrote an article entitled C# from a Java Developer's Perspective which is still one of the most popular comparisons of C# and Java on the Web. The article gets a couple thousand hits a month and I still get email about it from developers thanking me for writing it. Given the amount of changes in Java 1.5 5.0 and C# 2.0 I think the time has come to update this article. Below is my proposed table of contents for the new version. I'd appreciate comments on anything people thing is either missing or placed incorrectly.

  1. The More Things Change The More They Stay The Same
    This section describes concepts and language features that are almost exactly the same in C# and Java.
    1. We Are All Objects
    2. Keyword Jumble
    3. Of Virtual Machines and Language Runtimes
    4. Heap Based Classes and Garbage Collection
    5. Arrays Can Be Jagged
    6. No Global Methods
    7. Interfaces, Yes. Multiple Inheritance, No.
    8. Strings Are Immutable
    9. Unextendable Classes
    10. Throwing and Catching Exceptions
    11. Member Initialization at Definition and Static Constructors
    12. Generics - new!!!
    13. Boxing - new!!!
    14. Variable Length Parameter Lists - new!!!

  2. The Same But Different
    This section describes concepts and language features that differ either only in syntax or in some similarly minor manner between C# and Java.
    1. Main Method
    2. Inheritance Syntax
    3. Run Time Type Identification (is operator)
    4. Namespaces
    5. Constructors, Destructors and Finalizers
    6. Synchronizing Methods and Code Blocks
    7. Access Modifiers
    8. Reflection
    9. Declaring Constants
    10. Primitive Types
    11. Array Declarations
    12. Calling Base Class Constructors and Constructor Chaining
    13. For or is that foreach loops? - new!!!
    14. Metadata Annotations - new!!!
    15. Enumerations - new!!!

  3. An Ever So Slight Feeling of Dj Vu
    This section describes concepts and language features that exist in C# that are similar to those that exist in Java but with a significant difference.
    1. Nested classes
    2. Threads and Volatile Members
    3. Operator Overloading
    4. switch Statement
    5. Assemblies
    6. Collections
    7. goto (no longer considered harmful)
    8. Virtual Methods (and final ones too)
    9. File I/O
    10. Object Serialization
    11. Documentation Generation from Source Code Comments
    12. Multiple Classes in a Single File
    13. Importing Libraries
    14. Events
    15. Cross Language Interoperability

  4. Now For Something Completely Different
    This section describes language features and concepts that exist in C# and have no Java counterpart.
    1. Deterministic Object Cleanup
    2. Delegates - changed!!!
    3. Value Types (Structs)
    4. Run Time Type Identification (as operator)
    5. Properties - changed!!!
    6. Multidimensional Arrays
    7. Indexers
    8. Preprocessor Directives - changed!!!
    9. Aliases
    10. Runtime Code Generation
    11. Pointers and Unsafe Code
    12. Pass by Reference
    13. Verbatim Strings
    14. Overflow Detection
    15. Explicit Interface Implementation
    16. Friend Assemblies - new!!!
    17. The Global Namespace Qualifier - new!!!
    18. Continuations (Iterators) - new!!!
    19. Partial Classes - new!!!
    20. Anonymous Methods - new!!!

  5. Wish You Were Here
    This section describes language features and concepts that exist in Java and have no C# counterpart.
    1. Checked Exceptions
    2. Cross Platform Portability (Write Once, Run Anywhere)
    3. Extensions
    4. strictfp
    5. Dynamic Class Loading
    6. Interfaces That Contain Fields
    7. Anonymous Inner Classes
    8. Static Imports - new!!!

 

Tuesday, 26 April 2005 16:26:46 (GMT Daylight Time, UTC+01:00)
Looking forward to the new article. I have some feedback. I would place Generics in the "same but different" or deja vu categories if only for the implement differences that drastically affect areas like reflection, code sharing and dynamic invocation. It depends on your focus of course. To a developer not dealing with those issues they are the same functionality.
Tuesday, 26 April 2005 17:02:30 (GMT Daylight Time, UTC+01:00)
Static Classes in C# and don't forget to discus the @overidde annotation in Java.
Tuesday, 26 April 2005 17:19:12 (GMT Daylight Time, UTC+01:00)
It's been a while since I read anything on the Java 5 implementation of Generics, but I *seem* [insert disclaimer here about fallibility and often not knowing what I'm talking about] to recall that Generic instances are not strongly typed at the Java bytecode level (unlike the way in which for example a C# 2.0 generic List instanced as "int" (I couldn't write that directly 'cos of the angle bracket police) really, really, *really* IS a list of ints at MSIL level)...if that's true then the difference is one that developers should know about, since I'd expect it to affect performance, and potentially the choice of whether to use Generics in a given case in Java.
That said, I'd like to comment on how the two languages have if anything grown closer together since C# appeared, where they might have been expected to diverge further. Rather than make cheap and childish shots about copying and so forth, I think it's an excellent example of how good ideas in programming cross-fertilise, percolate around and even arise independently because Their Time Has Come (ahem). The end result is that both C# and Java are continuing to evolve in directions that reflect some of the best thinking of some very bright people. Which is nice.

Oh, and here's one to ponder when there's absolutely nothing better to do: Is there a relationship between a language supporting properties and being associated closely with a decent visual IDE?
Tuesday, 26 April 2005 18:38:09 (GMT Daylight Time, UTC+01:00)
I agree with moving generics to the "same but different" category.

Also, what about nullable types ( see http://msdn.microsoft.com/vcsharp/programming/language/ ) ?
Tuesday, 26 April 2005 19:53:37 (GMT Daylight Time, UTC+01:00)
Luke,
Agreed on both counts. I'll move the section on generics and add a section on nullable types.
Thursday, 28 April 2005 16:54:58 (GMT Daylight Time, UTC+01:00)
If only Microsoft had put more into making C# a patent-unencumbered open standard, you might have x-platform capabilities.

Hmm then you might actually have a reason to write something in C# so it could run on a decent server OS
bobdole
Tuesday, 10 May 2005 00:13:34 (GMT Daylight Time, UTC+01:00)
A.10: there's a new feature called lightweight reflection emit that allows you to emit just method bodies, which is cool and avoids the overhead of emiting full assembly/module/class/method for each runtime-codegen'ed feature you emit for perf. reasons.

D. default values. The new default keyword allows you to assign either a null to ref. types or the sensible default for a value type. This comes in handy when combined with generics, where you need to initialize generic output method parameter, for example.
Comments are closed.