Is there an effective tool to convert C# code to Java code?

JavaC#Code Translation

Java Problem Overview


Is there an effective tool to convert C# code to Java code?

Java Solutions


Solution 1 - Java

I have never encountered a C#->Java conversion tool. The syntax would be easy enough, but the frameworks are dramatically different. Even if there were a tool, I would strongly advise against it. I have worked on several "migration" projects, and can't say emphatically enough that while conversion seems like a good choice, conversion projects always always always turn in to money pits. It's not a shortcut, what you end up with is code that is not readable, and doesn't take advantage of the target language. speaking from personal experience, assume that a rewrite is the cheaper option.

Solution 2 - Java

We have an application that we need to maintain in both C# and Java. Since we actively maintain this product, a one-time port wasn't an option. We investigated Net2Java and the Mainsoft tools, but neither met our requirements (Net2Java for lack of robustness and Mainsoft for cost and lack of source code conversion). We created our own tool called CS2J that runs as part of our nightly build script and does a very effective port of our C# code to Java. Right now it is precisely good enough to translate our application, but would have a long way to go before being considered a comprehensive tool. We've licensed the technology to a few parties with similar needs and we're toying with the idea of releasing it publicly, but our core business just keeps us too busy these days.

Solution 3 - Java

This blog post suggests useful results from Tangible.

Solution 4 - Java

There is a tool from Microsoft to convert java to C#. For the opposite direction take a look here and here. If this doesn't work out, it should not take too long to convert the source manually because C# and java are very similar,

Solution 5 - Java

These guys seem to have a solution for this, but I haven't tried yet. They also have a demo version of the converter.

Solution 6 - Java

Although this is an old-ish question, take a look at xmlVM http://www.xmlvm.org/clr2jvm, I'm not sure if it's mature enough yet, although it has been around for several years now. XMLvm was made, I believe, primarily for translating Android Java apps to the iPhone, however, its XML-code-translation-based framework is flexible enough to do other combinations (see the diagrams on the site).

As for a reason to do this conversion, maybe there is a need to 'hijack' some of the highly abundant oss code out there and use it within his/their own [Java] project.

Cheers

Rich

Solution 7 - Java

Try to look at Net2Java It seems to me the best option for automatic (or semi-automatic at least) conversion from C# to Java

Solution 8 - Java

They don't convert directly, but it allows for interoperability between .NET and J2EE.

http://www.mainsoft.com/products/index.aspx

Solution 9 - Java

C# has a few more features than Java. Take delegates for example: Many very simple C# applications use delegates, while the Java folks figures that the observer pattern was sufficient. So, in order for a tool to convert a C# application which uses delegates it would have to translate the structure from using delegates to an implementation of the observer pattern. Another problem is the fact that C# methods are not virtual by default while Java methods are. Additionally, Java doesn't have a way to make methods non virtual. This creates another problem: an application in C# could leverage non virtual method behavior through polymorphism in a way the does not translate directly to Java. If you look around you will probably find that there are lots of tools to convert Java to C# since it is a simpler language (please don't flame me I didn't say worse I said simpler); however, you will find very few if any decent tools that convert C# to Java.

I would recommend changing your approach to converting from Java to C# as it will create fewer headaches in the long run. Db4Objects recently released their internal tool which they use to convert Db4o into C# to the public. It is called Sharpen. If you register with their site you can view this link with instructions on how to use Sharpen: http://developer.db4o.com/Resources/view.aspx/Reference/Sharpen/How_To_Setup_Sharpen

(I've been registered with them for a while and they're good about not spamming)

Solution 10 - Java

I'm not sure what you are trying to do by wishing to convert C# to java, but if it is .net interoperability that you need, you might want to check out Mono

Solution 11 - Java

This is off the cuff, but isn't that what Grasshopper was for?

Solution 12 - Java

Well the syntax is almost the same but they rely on different frameworks so the only way to convert is by getting someone who knows both languages and convert the code :) the answer to your question is no there is no "effective" tool to convert c# to java

Solution 13 - Java

Possibly you could use jni4net - opensource bridge instead ? Or list of other options I know.

Solution 14 - Java

Why not write it in Haxe (http://haxe.org/) and convert it to whatever you want it to be?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjoshjdevlView Question on Stackoverflow
Solution 1 - JavaMichael MeadowsView Answer on Stackoverflow
Solution 2 - JavaMike RusticiView Answer on Stackoverflow
Solution 3 - JavaNick WestgateView Answer on Stackoverflow
Solution 4 - JavaRoger WeenView Answer on Stackoverflow
Solution 5 - JavaGuven DemirView Answer on Stackoverflow
Solution 6 - JavaBig RichView Answer on Stackoverflow
Solution 7 - JavaPedro CView Answer on Stackoverflow
Solution 8 - JavascubabblView Answer on Stackoverflow
Solution 9 - JavaLorentzView Answer on Stackoverflow
Solution 10 - JavaGadView Answer on Stackoverflow
Solution 11 - JavaIan Patrick HughesView Answer on Stackoverflow
Solution 12 - JavaHannoun YassirView Answer on Stackoverflow
Solution 13 - JavaPavel SavaraView Answer on Stackoverflow
Solution 14 - JavaRohitdevView Answer on Stackoverflow