Looking for the Code Converter which converts C# to Java [closed]
Asked Answered
P

2

20

Can anybody help me by suggesting the name of an converter which converts C# code to Java code. Actually, I have a tool which is written in C# code and I am trying to modify it. As I have no idea about C# and .NET framework, it seems difficult to me to convert the large code by my own. I found from some web information that there exist some tools which can convert C# to Java (may not be properly, however they can). Can anybody help me by suggesting some name of those tools.

Pruitt answered 11/8, 2011 at 16:58 Comment(9)
IMO such tools are only useful if you then have enough knowledge of both source and target language to fix the mess it makes...Useless
I have some knowledge of Java and about the functionality of above mentioned tool. However, no knowledge of C#. Will those tools help me ? What do you think ?Pruitt
@Pruitt - if you don't understand the C# code then you probably don't know, if the translated Java does the same - unless you have test cases for both c# and java...Lucky
Just to cite a few things that won't translate well... structs, nullables, iterator-blocks, anon-methods, lambdas (differed capture rules), string-equality, LINQ, most of the BCL, dynamic, operators, delegates, events, generics-without-type-erasure...Useless
possible duplicate of is there an effective tool to convert c# to java?Singularity
Christopher, I am agree with your answer.However, I started to learn C# thus I can convert by my own. But, I think Marc is right on that "they actually are pretty different" . I also feel the gap while studying c# (it became more tough because the complete tool is on c#).That's why I am searching for a converter .Pruitt
I found by searching the web that (kevingao.net/csharp-java-conversion) this gives reasonable conversion (however, I have not yet tested with my code). I know it is impossible to convert properly because of the syntactic and semantic gap of them. Actually I thought like that, convert the C# code by using a commercial converter and then modify it by your own .Pruitt
All, let's just provide him a converter, not a lecture.Singularity
Code Monkey, thanks for making my question more clearer.Pruitt
S
19

Disclaimer: No tool is perfect.

However, if you still want to try then there are these converters available:

Not a converter but a bridge between .NET and the JVM:

Singularity answered 11/8, 2011 at 17:53 Comment(7)
I am searching for a tool which converts C# code to Java code. Is these tools can convert (I am not caring about perfectness)?Pruitt
@Arpssss: Yes, only exception is JCLA which is the opposite: Java to C#.Singularity
The Grasshopper link does not work. The dev.mainsoft.com site throws an error and mainsoft.com redirects to harmon.ie.Redon
The CSharpJavaMerger page looks like it has been hacked (title says "Nothing found for Csharp-java-conversion" but page is selling HYDROXYCITRIC ACID). Also, there is not a link on kevingao.net to the page.Redon
@Redon There's nothing wrong with the CSharpJavaMerger link. It points to the correct page now.Orlena
@AndersonGreen Yeah, looks like user195488 fixed it right after I put up the comment.Redon
Most links are deadGoldenrod
A
8

You are better off doing it by hand. I've used code conversion software before, and it just mucks everything up. Sure, it corrects a few syntax differences, but largely what you'll get is just a mess of code that doesn't compile right away anyway.

With a converter you'll have to do a lot of corrections anyway. Why not take the small amount of extra time it will take to convert it by hand and end up with better code?

Even if you don't know C#, it will be better to learn it and do the conversion by hand, as I said before you will have to do it anyway. C# and Java are not too different syntactically, but as @Marc pointed out above, there are certainly gaps in the language. Simple C# is easily translated to Java, of course having to use the Java BCL instead of the .NET, which certainly have their differences. As you get into more complicated C#, there are things that have no direct equivalent.

Keep in mind, that conversion projects can be extremely time-consuming and are extremely effective at swallowing money in a business environment.


A google search will yield you some commercial options, but I'm not going to post them here, simply because I'm against that sort of thing. There are some things you just can't automatically translate.

Affirmative answered 11/8, 2011 at 17:2 Comment(10)
I added a brief list of things that will make conversion tricky (comment on the question) - it makes me think that the "not too different" is generous - they actually are pretty differentUseless
I was being generous, I think because I was speaking from my experience of going from Java to C#, which is admittedly easier, though still not without its own share of difficulties. I've updated the answer to reflect your insight. Thanks.Affirmative
Microsoft provides a tool to go from Java to C# so if Microsoft supports it, I don't see why you can't do it. Understandably that you want to make sure the code still works when you convert it.Singularity
He's asking for code that goes from C# to Java, not the other way around. There's a large difference, as it is somewhat easier to convert Java to C#. I'm not saying he can't use a tool, but I can say from experience he is better off writing it by hand. If the project is so large that he can't do it by hand quickly, try a tool, but he will have to make so many changes it may not be worth it.Affirmative
@Chris: I know. I really don't think he wanted a lecture, just a tool. You ask a question, get an answer. I'm sure if he wanted an opinion on tools then this all would be appropriate but everyone slammed him which is not the right way to treat someone asking a simple question for a list of converters. That's as simple as this question really was and everyone just blew up on him. I flagged all the above comments as not constructive.Singularity
I think everyone was trying to save him the headache. I guess some people have to learn the hard way.Affirmative
Christopher, I understood what you are talking about. I have started to learn C# thus I can convert by my own (I know this is the best soln.). But the problem is that as Marc says " they actually are pretty different" and I feel it also while learning C#. Now as my code is too large, I thought like that, first convert it by any commercial tool and then fix the bugs, performance issues. What your experience says, is it a bad idea ?Pruitt
@Arpssss, There's not an easy answer to that question. If you need the code quickly, it's a fine idea, but do not go into it thinking the tool will make it easy for you. Regarding the differences Marc pointed out, the tool will not know what to do with those pieces of code, leaving them unconverted. You will have to convert those things that don't have a direct translation by hand anyway. At the very least, the tool will convert the syntax and some common calls to the base libraries. However, it will not account for the differences between the two languages "best practices".Affirmative
Thanks Christopher, I think I got your point.Pruitt
You've clearly had one or more unsatisfactory experiences with one or more tools at some time in the past, converting from some language to another. Describing those experiences, naming the tools and the times and languages, and quantifying even a little bit what kind of code you fed in, and the amount and kind of deficiencies you found in the translated code - would make this a better answer for SO.Ekaterinoslav

© 2022 - 2024 — McMap. All rights reserved.