Porting from C# to Java


Recently I was involved in a project for translating C# to java. I know most programmer's are probably
assigned the reverse task of translating java to C#, but this was a situation of porting to a Linux client
and java was the language of choice. In doing the migration, you could hear me audibly groan while coding.
We use JetBrain's IntelliJ with the Maven plugin, which is an excellent IDE for doing java development
(created by the same people who wrote Resharper). I could not imagine having to do java coding without this IDE,
because compared to C#, java is a verboses language.

When I started the migration project I thought, how hard could it be? Both java and C# look similar and have similar
libraries. They both have generics. This should be a piece of cake. Not so. Java does not have LINQ. Java does not
distinguish between generics with the same template type. Java doesn't really have event, it has listeners. Java
represents properties as a set of two different methods. Java doesn't have delegates. Java doesn't allow you to extend classes.
The list goes on and on. Thank goodness it wasn't a GUI port, otherwise you would really hear me rant.

If you do a side by side comparison of just the languages (not even the libraries), you'll find that java simply lacks many, many
features a .NET developer just takes for granted. And as I find myself using the functional components of C# more and more,
LINQ and Lambda's are a major part of my programs.  In order to make the port easier, we overcame some of the shortcomings
th static imports. We created functions like is and as. We utilized some of the apache libraries. We created some things to mimic
anonymous methods (by using java's anonymous classes). We took advantage of Observers and Listeners and used them to
replace events. Even with all of the functions we needed to create to bring us closer to C#, the coding still ends up more verbose.

I can only hope the java community and Oracle can put aside their differences with the Microsoft community and take advantage of
some of the awesome features inherent in C# and the .NET Framework.
Ebook Download
View all
Learn
View all