Blue Theme Orange Theme Green Theme Red Theme
 
Discover the top 5 tips for understanding .NET Interop
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » Java and .NET » Six C# features Java developers will kill for...

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

C# is called Java on steroids, and everyone agrees that it is based on some long-time Java ideas and concepts. But, there are differences, and some of them make C# very powerful compared to Java. Here are six of them.

Page Views : 25300
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
DevExpress Free UI Controls
Become a Sponsor
Team Foundation Server Hosting
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

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...

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Ran Kornfeld
Ran Kornfeld is an expert Java and J2EE devloper , architect, consultant and trainer who has moved to exploring and using the .NET world and especially the C# development language. Contact email: rankorn at gmail dot com.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
Some I can live with or without by rwoodruf On June 27, 2006

@ - This would definitely be nice

Operator Overloading - not sure that I care. The semantics of adding complex object A to another Complex Object B is nice but hardly necessary.

Indexers - these are your friends. I do wish they existed in Java.

Conditional Compilation - Switch to AOP and DI for the tracing and stuff and you can turn them off at run time :)

Partial Classes - Some good, some bad. Could be implemented in other ways as well. Not certain that I really miss it. Although, I am not a tool vendor.

Extern Aliases - ok, that is a problem. But jar files do help you get around the problem in some cases and you can control classloading at the command line or using your own classloader.

Reply | Email | Modify 
Re: Some I can live with or without by Mahesh On July 6, 2006

I think partial classes plays a major role when building comlext UI applications. I have designed Windows Forms applications that had ton of controls and now having prartial classes gives me flexibility to keep my resources, events, and logic in three seperate files with same name. 

Reply | Email | Modify 
I have some additions... by Pietro On July 16, 2006

I am a Java developer as well as a C# developer, so I have some wonderful things to add to this list. I'll start at 7:

7) Properties - You gotta know when all these calls to setXXX() becomes a tiresome task; properties make our lives easier

8) Delegates - The ability to assign a function to the value of a variable would help us eliminate all that Listener code

9) Value Types - While these were added to the J# language in J# 2.0 (J# code required: public final class XXX extends System.ValueType), classic Java still does not have this wonderful way of organizing values.

One thing that another programmer who wants to add something should not add to the list: Generics - added in Java 2 Version 5.
Java:

class A {}
class C<T extends A> {}

C#:
class A {}
class B<T> where T : A {}

Another thing that another programmer who wants to add something should not add to the list: Enumerations - added in Java 2 Version 5.

Reply | Email | Modify 
Re: I have some additions... by Muhammad On July 22, 2006
What about nullable value types and anonymous methods, are they available in Java?
Reply | Email | Modify 
Discover the top 5 tips for understanding .NET Interop
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.