convert java to C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have to convert a Java app to .NET, i found and used the conversion tool
which converts java to C#, but it only converted about 10% of it, how hard
would it be to re-write the java app and keep most of the same logic and
could I use alot of the same code? I noticed in the conversion that alot of
the java code remained the same, so how close is Java to C#?

is there another tool to do this conversion much cleaner and easier to fix
when something doesn't convert correctly?
 
Barney,

There might be some commercially available tools out there, but in the
end, it's something I think you will have to do by hand. While you might be
able to convert language constructs easily, the libraries in Java and in
..NET do not have a 1:1 mapping, and the usages are quite different. It is
because of this that you will have to do most of the work by hand.

You can definitely keep a lot of the architecture (depending on how tied
it is into the technology, and whether or not you can find suitable
replacement technologies), and the design, but some of it will have to
change, most likely.

Hope this helps.
 
Barney said:
I have to convert a Java app to .NET, i found and used the conversion tool
which converts java to C#, but it only converted about 10% of it, how hard
would it be to re-write the java app and keep most of the same logic and
could I use alot of the same code? I noticed in the conversion that alot of
the java code remained the same, so how close is Java to C#?

is there another tool to do this conversion much cleaner and easier to fix
when something doesn't convert correctly?

Microsoft's product to help migrate Java apps to .NET is JUMP, in beta:

http://msdn.microsoft.com/vjsharp/jump/default.aspx

Translating Java code to C# code is not especially difficult, provided
you have a managed library which implements all the Java API calls you
use; then simply translating the syntax suffices, with special
provisions for some features found in Java but not C#. Octopus, one of
the best commercial translation products, does something like this:

http://www.remotesoft.com/octopus/

However, translating Java in this manner yields, essentially, a Java
program written in C#, which frankly hardly seems worthwhile.
Translating Java code to idiomatic, typical C# code is a much more
difficult process, because a real C# program would use .NET library
calls, which, as Nicholas explained, have no useful general mapping to
Java API calls, and also has a number of stylistic and algorithmic
differences that are difficult or even unfeasible to map.

Rather than translate Java to C#, a better approach may be to
use a tool such as IKVM to allow your Java classes to be accessed
directly from other C# code through the .NET Framework:

http://www.ikvm.net/index.html

Don't worry about the license, this one's pretty tame, and despite its
alpha version number, it's fairly mature. If you need stronger .NET
integration for your Java program, for example to inherit from classes
in your Java application, you can take an alternate approach: translate
your projects to J#.NET, which is much, much closer to Java than C#, and
then use IKVM to carry out modern Java API calls, as this page describes:

http://www.ikvm.net/devguide/net2java.html

This is necessary because Microsoft does not have a license to support
newer versions of the Java API.

Finally, here's a good previous discussions on the topic:

comp.lang.java.programmer: Java to C# translator, 23 Jun 2003 12:28:46
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e10b063a45047301/

I hope this helps.
 
Back
Top