Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Java to C# with a tool, or manually? [duplicate]

I have a Java project which I'd like to convert to C#, and after looking here and elsewhere found out about a tool, Sharpen.

However, in order to get it up and running (I'm new to Java) the site linked above describes grabbing the source and building it as a plugin to the Eclipse IDE, which I'd rather not do since I don't ordinarily do Java.

Does anyone know whether a standalone EXE exists which can simply utilize Sharpen to take a given Java project and run it through the wringer to convert it to C#? Or are Java and C# similar enough that it should be pretty straightforward to just port the code over to .NET manually?

like image 314
Darth Continent Avatar asked Jan 21 '11 22:01

Darth Continent


People also ask

Can you convert Java to C?

Can you convert Java to C? Yes, there's a Java to C source converter: a human programmer. (Reliability may be an issue, though.) If you really want to compile Java to C, you might try compiling Java to machine code with GCJ, then disassembling the machine code, then (somehow?)

Can Java compiler be used as C compiler?

The JVM (Java Virtual Machine) may be an interpreter or a JIT (Just In Time) compiler or both. If it is a compiler then it is writing machine code directly. It does not write C code first. The JVM might be written in C or C++ or in Java.

Is C or Java faster?

Java is compiled into a lower language, then interpreted. It also has automatic garbage collection, and it's farther from machine code in the first place. Because of this C code tends to run faster than Java, but difference depends on what's being done and how well the code has been optimized.

Is there any link between C and Java?

C is more procedure-oriented. Java is more data-oriented. C is a middle-level language because binding of the gaps takes place between machine level language and high-level languages. Java is a high-level language because translation of code takes place into machine language using compiler or interpreter.


2 Answers

I would personally do it manually. You can reflect on where the Java design choices simply aren't appropriate for .NET, and end up with idiomatic C# code instead of code which looks very much like C# with a Java accent.

It also means you're more likely to understand the code at the end :)

like image 86
Jon Skeet Avatar answered Oct 11 '22 05:10

Jon Skeet


There's no one-to-one conversion (or even close), so you should really do it manually. However, if you need a decent, automated piece of software, either as a starting point or as a rough converter, see this link.

like image 39
user541686 Avatar answered Oct 11 '22 06:10

user541686