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
- Default access in C# is "private" (in Java, it's package private)
- 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
- C# provides three kinds of constraints (see http://www.25hoursaday.com/CsharpVsJava.html#generics).
- C# includes "default" operator, returning the default value for a type (null for objects, 0 for scalars, e.g.)
- 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
Questions
- What's up with loading classes from assemblies (see notes at http://www.25hoursaday.com/CsharpVsJava.html#reflection about not being able to create types with the Type class)?
page revision: 0, last edited: 30 Nov 2010 22:38