Where can I find Java converter in C #?

I needed to convert a Java 1.5se application to C # 2.0.

Does anyone know a tool (preferably free / open source) for this?

+39
java c #
Jan 14 '09 at 13:50
source share
9 answers

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

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

Remember to manually go through the code. He will have a lot of problems.

+15
Jan 14 '09 at 13:57
source share

Even if there is such a tool, I highly recommend that you do the conversion manually. Automated converters often accurately reproduce code, but ignore idioms - because it will really be very difficult for them to get the right one.

In addition, differences between generics in .NET and Java can lead to very different solutions in the two code files.

Indeed, you will be better off doing this manually.

+27
Jan 14 '09 at 13:54
source share

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

This tool has been forked and updated by the Xamarin team, and they used it to translate Android APIs into C #. A copy of them can be found here:

+23
Nov 02 '10 at 13:45
source share

ikvm provides Java classes in .NET. This is not a converter, but based on my experience, I would recommend it to anyone who switched from java to .NET.

+13
Jan 15 '09 at 20:08
source share

While the syntax of the two languages โ€‹โ€‹seems similar, the semantics are very different. To mention a few places, both languages โ€‹โ€‹went astray

  • Generics, Java compiles all objects, C # saves generic types
  • Exceptions, Java checks for exceptions, C # does not
  • Anonymous classes and inner classes, Java has anonymous classes and nested classes, C # has none. Instead, C # has delegates and events. Thus, the programming model is different from others.
  • delegates, C # has the concept of function pointers, which leads to another way of programming.
  • events, C # has an idea of โ€‹โ€‹events and components that lead to another way of programming.
  • API, setting all the semantic differences aside, both langauges have huge APIs, none of which are trivially converted.

In other words, you cannot make such a transition automatically. If the reason for switching to C # is the ability to translate code into an .exe file, there are various options on the Java market.

+7
Nov 02 '10 at 13:15
source share

I'm testing Tangible Solution now (it's not free)

Tangible Source Converter

And he will add a class helper. But outside his result looks great.

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; 

This is a simple case, but it works great. However, as I said before, it uses the class helper (StringHelperClass.StringSplit), which is good but not needed. Beyond this, the result code is pretty clear.

+5
Jan 29 '12 at 16:24
source share

Microsoft used its own Java to C # converter - Microsoft Java Language Conversion Assistant 3.0

+3
Jan 14 '09 at 2:00
source share

Have you tried XMLVM ? It has the ability to automatically convert to C #, like this:

 xmlvm --in=myjar.jar --out=output_dir --target=csharp 
+2
Oct 03 '13 at 23:18
source share

Xamarin recently ported android to mono using sharpen. Check out this link.

0
Dec 15 '13 at 18:01
source share



All Articles