Six C# features Java developers will kill for...


Last year, Java celebrated its 10th birthday. During those 10 years Java was known for its powerful yet simple syntax, allowing developers to accomplish any task with ease and grace. But, this simple syntax is also a limitation, since many developers are now professionals with years of experience and are not afraid of complex syntax and rich feature lists.

Here are 6 features that are available in C# (and other .NET languages), but are missing from the Java language. These are features that can make a developer happy, and his code shine. I must mention that you can accomplish everything without using any of those features - but why??

So, here they are:

1.      The @ symbol for strings - so simple, so useful. Instead of dealing with all kind of annoying escaping, just mark the string literal with a @ symbol and it tells the string constructor to ignore escape characters and line breaks.

2.      Operator overloading - This features is missing from Java with the excuse of simplicity. It can make your code look so nice and useful, that we do not want any excuses!

3.      Indexers - They seem strange at first sight, but when you check their use with the String class for example, you can really understand their power. "Access string characters with the [ ] operator? I thought strings are objects..." (Overwhelmed Java developer).

4.      Conditional compilation - Tell the compiler what to compile and what to ignore. How come no one thought of that before? (Actually they did). How hard it is with Java to add trace statements to your code, when you want those statements to just disappear from the final product and have no performance influence!

5.      Partial classes - same class, two source files. Can be very useful for automatic code generation engines and just general code organization. Brilliant.

6.      Extern aliases - This feature really overcomes a Java problem, that make developers sometimes lose their hair. In Java, if you have two versions of the same class library (same qualified names for different classes) you are in trouble. The way the Java class loader works, applications can fail with strange errors, and there is almost nothing you can do to solve it. Using external aliases for assemblies (or in Java - jar files) really solve this gracefully.

There are more features that I have not included: different useful operators, properties, structures and more. Being a Java developer that moved to C#, I can tell you that I was amazed to discover this world. I just hope the guys at the JCP (Java Community Process - responsible for the Java specs) will add some of those features to their next versions.

For the sake of Java developers around the world...

Up Next
    Ebook Download
    View all
    Learn
    View all