Differences between C-sharp and Java
  • C# namespaces do not dictate directory structure; in Java package names do
    • C#'s "is" == Java's "instanceof"
    • C#'s destructors (which use C++ notation) automatically call their super-class' destructor; in Java this is not guaranteed.
    • In C# it's "lock", in Java it's "synchronized"
      • in C#, method synchronization is done with an annotation ([MethodImpl(MethodImplOptions.Synchronized)])
  • Access Modifiers:
    • Default access in C# is "private" (in Java, it's package private)
      • In C#, "internal" means visible only within the same assembly
      • In C#, "internal protected" means same as internal AND derived classes in other assemblies
  • In C#, constants are implicitly static
    • C# supports "decimals" as a primitive type
    • Constructors:
      • In Java, it's "super", in C# it's "base"
  • Generics
  • In Java, it's "for( Type var : collection)" in C# it's "foreach(Type var in collection)
  • In C# enumerations are syntactical sugar over an int type; In Java, they are full-fledged classes


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License