I needed to convert a Java 1.5se app to C# 2.0.
Does anyone know of a tool (preferably free/open source) to do this?
I needed to convert a Java 1.5se app to C# 2.0.
Does anyone know of a tool (preferably free/open source) to do this?
Even if there is such a tool, I'd highly recommend you to do the conversion by hand. Automatic converters will often faithfully reproduce the code, but ignore idioms - because they'd be really, really hard to get right.
Furthermore, the differences between generics in .NET and Java could lead to some very different decisions in the two codebases.
Really, you'll be better off doing it by hand.
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 the Android APIs into C#. Their copy can be found here:
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 over the code afterwards. It will have lots of issues.
Right now, i am testing Tangible Solution (that is not for free)
And it add a Class Helper. But outside it,the result looks 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 is a easy case but it works fine. However, as i said early, it uses a Class Helper ( StringHelperClass.StringSplit) that is fine but it is unneeding. Outside it, the result code is pretty clear.
While the syntax of the two languages seems alike, the semantics are far different. To mention a few places the two languages go astray
In other words, you won't be able to make such a transition automatically. If the reason for changing to C# is to be able to translate your code into an .exe file, there are various options also in the Java market.
Microsoft used to have their own Java to C# Converter - Microsoft Java Language Conversion Assistant 3.0
Recently Xamarin have ported android to mono using sharpen. Check out this link.