[ACCEPTED]-Where can I find a Java to C# converter?-java

Accepted answer
Score: 29

Even if there is such a tool, I'd highly 8 recommend you to do the conversion by hand. Automatic 7 converters will often faithfully reproduce 6 the code, but ignore idioms - because they'd 5 be really, really hard to get right.

Furthermore, the 4 differences between generics in .NET and 3 Java could lead to some very different decisions 2 in the two codebases.

Really, you'll be better 1 off doing it by hand.

Score: 27

A good tool to use is called Sharpen, which 4 is open source.

This tool has been forked 3 and updated by the Xamarin team and they 2 used it to translate the Android APIs into 1 C#. Their copy can be found here:

Score: 16

Java Language Conversion Assistant. Optionally installed with (at least) Visual 4 Studio 2005 Standard Edition.

Select File/Open/Convert/Java 3 Language Conversion Assistant.

Remember to 2 manually go over the code afterwards. It 1 will have lots of issues.

Score: 13

ikvm exposes java classes in .NET. Its not a 3 converter, but based on my experience I'd 2 recommend it to anyone making the transition 1 from java to .NET

Score: 7

While the syntax of the two languages seems 7 alike, the semantics are far different. To 6 mention a few places the two languages go 5 astray

  • Generics, Java compiles everything to objects, C# retains the generic types
  • Exceptions, Java has checked exceptions, C# doesn't
  • Anonymous classes and inner classes, Java has anonymous classes and nested classes, C# has neither. Instead C# has delegates and events. The programming model is thus very different
  • delegates, C# has the notion of function pointers which leads to a different way of programming.
  • events, C# has the notion of events and components which leads to a different way of programming.
  • API, setting all the semantical differences aside, both langauges has acompanied huge API's, neither of which are trivially converted.

In other words, you won't be able 4 to make such a transition automatically. If 3 the reason for changing to C# is to be able 2 to translate your code into an .exe file, there 1 are various options also in the Java market.

Score: 6

Right now, i am testing Tangible Solution 7 (that is not for free)

Tangible Source Converter

And it add a Class 6 Helper. But outside it,the result looks 5 fine.

Java: (original)

public class PackVariableArrays {


private ClassError myerror=new ClassError();


public VariableArrays unpack(String txt) {
    VariableArrays pc = new VariableArrays();
    Variable lc;
    txt=txt.replace("\r\n","\n");
    setMyerror(new ClassError());
    if (txt==null) {
        lc=new Variable();
        lc.name="ERV-5: Empty values";
        pc.addItem(lc);

        return pc;
    }
    String[] linecode = txt.split(ClassUtil.SEPARATOR2);
    int blen = 0;
    int tmpint = 0;

    int numelement = 9999;

C# (conversion)

public class PackVariableArrays {


    private ClassError myerror =new ClassError();


    public virtual VariableArrays unpack(string txt) {
        VariableArrays pc = new VariableArrays();
        Variable lc;
        txt=txt.Replace("\r\n","\n");
        Myerror = new ClassError();
        if (txt==null) {
            lc=new Variable();
            lc.name="ERV-5: Empty values";
            pc.addItem(lc);

            return pc;
        }
        string[] linecode = StringHelperClass.StringSplit(txt, ClassUtil.SEPARATOR2, true);
        int blen = 0;
        int tmpint = 0;

        int numelement = 9999;

It 4 is a easy case but it works fine. However, as 3 i said early, it uses a Class Helper ( StringHelperClass.StringSplit) that 2 is fine but it is unneeding. Outside it, the 1 result code is pretty clear.

Score: 3

Microsoft used to have their own Java to 1 C# Converter - Microsoft Java Language Conversion Assistant 3.0

Score: 2

Have you tried XMLVM ? It has an option to automatically 1 convert to C# like this:

xmlvm --in=myjar.jar --out=output_dir --target=csharp
Score: 1

Recently Xamarin have ported android to 1 mono using sharpen. Check out this link.

More Related questions