New Apps

Articles

Tips

Events

Improve Soft Skills

/ / / / What does it exactly mean when people say that C# is better than Java?



C# learnt from many mistakes that Java had.

  • C# has decimal fixed point.
  • C# has var (local variable type inference) since 3.0.
  • C# has real generics ("reified generics") since 2.0. Java has fake generics ("erasure generics") since Java 5.
  • C# has real properties.
  • C# has value types.
  • C# has attributes since the very beginning. Java only has annotations (the Java equivalent to attributes) since Java 5.
  • Ditto for for-each loops.
  • Ditto for auto-boxing and auto-unboxing.
  • Ditto for varargs.
  • C# has using (and the dispose pattern, via IDisposable) since the very beginning. Java only has try-with-resources (the Java equivalent to using) since Java 7.
  • Ditto for string switches. Also note that C# switches are more versatile than Java's ones; you can use goto case and goto default to jump to other cases.
  • C# has lambdas since 3.0, long before Java did (Java 8).
  • Ditto for extension methods. (The closest thing Java has to extension methods are interface default methods, and those are introduced in Java 8.)
  • C# has static classes (non-instantiable classes where all methods have to be static) since 2.0. In Java, you can hack around it by making a class with only private constructors, but you can still define non-static methods in such a class.
  • C# methods are non-virtual by default. In Java you can only make a method non-virtual by making it private or final.
  • C# requires using override when overriding, and forbids using override when not overriding. This makes it easier to detect when a refactor is breaking other code.
  • C# has operator overloading.
  • C# has compile-time constants using const. In Java, you can only have compile-time constants for numbers, booleans, characters, and strings.
  • C# does not have checked exceptions. Many programmers consider checked exceptions a broken concept.
  • C# has named and optional arguments since 4.0.
  • C# has ref and out parameters. In Java, everything is pass-by-value; it's not possible to have pass-by-reference.
  • C# has enumerator generators via yield since 2.0.

Having said that, there are things that actually appeared in Java first, that C# either doesn't have or has caught up to later:

  • Covariant and contravariant generic type parameters have been around since Java 5, but were introduced in C# 4.0.
  • Java enumerations (which are full-fledged classes) are much more advanced than C# enumerations (which are basically just integers). For example, you can use it to implement a simple state machine.
  • Java has BigDecimal which provides decimal floating point, as opposed to C#'s builtin decimal fixed point.
Yes. C# lacks some stuff java has but events with deleagetes, async/await or LINQ have advantage over type variance (covariance and contravariance) in java.



«
Next

Newer Post

»
Previous

Older Post

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

No comments :

Leave a Reply

Thursday, September 8, 2016

What does it exactly mean when people say that C# is better than Java?



C# learnt from many mistakes that Java had.

  • C# has decimal fixed point.
  • C# has var (local variable type inference) since 3.0.
  • C# has real generics ("reified generics") since 2.0. Java has fake generics ("erasure generics") since Java 5.
  • C# has real properties.
  • C# has value types.
  • C# has attributes since the very beginning. Java only has annotations (the Java equivalent to attributes) since Java 5.
  • Ditto for for-each loops.
  • Ditto for auto-boxing and auto-unboxing.
  • Ditto for varargs.
  • C# has using (and the dispose pattern, via IDisposable) since the very beginning. Java only has try-with-resources (the Java equivalent to using) since Java 7.
  • Ditto for string switches. Also note that C# switches are more versatile than Java's ones; you can use goto case and goto default to jump to other cases.
  • C# has lambdas since 3.0, long before Java did (Java 8).
  • Ditto for extension methods. (The closest thing Java has to extension methods are interface default methods, and those are introduced in Java 8.)
  • C# has static classes (non-instantiable classes where all methods have to be static) since 2.0. In Java, you can hack around it by making a class with only private constructors, but you can still define non-static methods in such a class.
  • C# methods are non-virtual by default. In Java you can only make a method non-virtual by making it private or final.
  • C# requires using override when overriding, and forbids using override when not overriding. This makes it easier to detect when a refactor is breaking other code.
  • C# has operator overloading.
  • C# has compile-time constants using const. In Java, you can only have compile-time constants for numbers, booleans, characters, and strings.
  • C# does not have checked exceptions. Many programmers consider checked exceptions a broken concept.
  • C# has named and optional arguments since 4.0.
  • C# has ref and out parameters. In Java, everything is pass-by-value; it's not possible to have pass-by-reference.
  • C# has enumerator generators via yield since 2.0.

Having said that, there are things that actually appeared in Java first, that C# either doesn't have or has caught up to later:

  • Covariant and contravariant generic type parameters have been around since Java 5, but were introduced in C# 4.0.
  • Java enumerations (which are full-fledged classes) are much more advanced than C# enumerations (which are basically just integers). For example, you can use it to implement a simple state machine.
  • Java has BigDecimal which provides decimal floating point, as opposed to C#'s builtin decimal fixed point.
Yes. C# lacks some stuff java has but events with deleagetes, async/await or LINQ have advantage over type variance (covariance and contravariance) in java.


No comments:

Post a Comment

Social Impact