views:

217

answers:

7

Theoretically this seems possible to me. So can Any one confirm this to me, if it's possible? and if there is such a software that does this?(like Java to C++ or C#)

And in general would it be possible to transfer languages like Java to server-side programing language like PHP?

+5  A: 

It is possible, but the major problem is that Java has a very large runtime library which needs to be made available in the target language in order to be able to do a fully automatic conversion.

For the special case of Java -> .NET, you can use J# from Microsoft to compile it into a .NET assembly which can then be used. Also ikvm.net allows for running a JVM inside .NET.

For PHP I do not believe such a solution exist. You MAY be able to use gcj to create a native library which can be linked in, but I do not believe it is a feasible soultion.

What functionality do you need in PHP?

Thorbjørn Ravn Andersen
Nothing specific actually! Just wondering if it would be possible to transfer already made code in Java to other languages in which you are not that experienced with.
MAK
Since most modern languages are Turing-complete, it is possible. Unfortunately it most likely requires more work than just porting the code in the first place.
Thorbjørn Ravn Andersen
If you have to translate a large system, building a translator (and doing any manual post-cleanup) is far easier and more reliable than porting the code manually. Gartner Group thinks you can translate ~~140 lines of code a day between similar languages (you can claim otherwise but smart people shouldn't believe you) and it gets worse if the languages differ much. If you have to move a million lines of code, that requires ~~7100 man-days or 32 man-years. We build translators (using sophisticated tools) in about 1-2 man-years. (See http://www.semanticdesigns.com/Products/DMS/DMSToolkit.html)
Ira Baxter
@Ira, and how much is the price for your general Java -> .NET solution?
Thorbjørn Ravn Andersen
We don't do general translations, because then you'd have to map every library you could ever conceive of in Java, to every library that MS might conceive for C#. What you can reasonably do is a translation of the code you *have*, which is a much more limited problem. You've noted there are engineering costs involved. True. What's the cost of hand-translating a million lines of code at 32 man-years?
Ira Baxter
... as an example of a focused translation, see the overview of the migration of the B-2 Stealth Bomber mission software: http://www.semanticdesigns.com/Products/Services/NorthropGrummanB2.html. That was 100% automatically translated using our tools, and we didn't ever get to see the code.
Ira Baxter
The ikvm project does a general translation from Java to .NET. The Grasshopper product runs .NET programs on a JEE server. The price of both is very low.
Thorbjørn Ravn Andersen
... Er, ikvm says (on its web page) that it is a JVM implemented in .NET. OK, its a JVM. Where's the relevance to the OP's apparant question of translating (source) code?
Ira Baxter
+5  A: 

Translating the syntactical elements of one language and producing another is not trivial but it's not impossible. A good parser can build syntax trees in one language and then emit another. The difficulty of porting code outside the context of simple "Hello World" type applications is twofold:

  1. The libraries of one language will probably differ (e.g. WinForms vs Swing)
  2. Some language features will have to be catered for: (lambda expressions, anonymous methods, different inheritance implementations etc).
David in Dakota
+5  A: 

Visual Studio ships with a Java to C# translator, and even tough it does a pretty decent job, there's still a lot to clean up afterwards.

In my experience you really have to ask yourself if it makes sense to translate code from one language to another. What is the gain? Will the translated code be maintainable? If the answers to these questions point in the wrong direction, translating is probably not the right approach.

Brian Rasmussen
+2  A: 

Google Web Toolkit does conversion from Java to JavaScript:

http://code.google.com/webtoolkit/overview.html

Anon
Interesting :) Would they transfer the interface you do with Swing to HTML design too?
MAK
No, you have to design your interfaces with a GWT compatible toolkit, such as GWT itself or EXT-GWT, etc.
Matthew Blackford
+1  A: 

Hi,

to answer your question, yup, theoretically this is indeed possible and practically such technology is used every day :)

The interesting thing, in my opinion, is that the Java converters typically convert by taking the bytecode, not the source code. Then it's, say, bytecode-to-ObjectiveC source code. For some converters (at least one opensource one) it's bytecode-to-XML then XML-to-target-language.

For example, the Uniwar application for the iPhone, which has been acclaimed by all and made its way to the appStore's top ten, as been written in Java (JME) and automatically converted from the Java bytecode. Reaching the top ten, even for a few days, means that this is deployed on a lot of machines ;)

In the Real-World [TM], Cobol-Java and, weirdly, Java-Cobol are not unheard of.

For all this to work that said you need a really good converter :)

AlexPat
If your aim is to get maintainable code, I would steer clear of bytecode based converters. For a start, you will lose all comments in the original sourcecode.
Stephen C
But "unknown (yahoo)" isn't it better to minimize the number of translations...since each time we do that we would somehow lose some thing of the accuracy..."Stephen C" I agree with what you say...you have a good point....specially my main propose is to make programmers from different worlds of languages to understand each other easier...So Programmer Mr. X who know Java can understand the logic behind the software of which is made by programmer Mr. Y using C++ without the need to learn that language...
MAK
+1  A: 

Theoretically it is possible. But as others pointed out the main problem is to translate libraries.

Some time ago I made Java to Tcl(XOTcl) and Java to Python translators to evaluate the translation posibility. Search by java2tcl and yava2python.

They convert syntax but do not make relevant constructions translations (e.g. Java file operations to Python ones). That would require more development time.

In general my opinion is what such a translation may be possible. But only if your translator covers classes/libraries of the converted project.

msorc
A: 

Yes, it's called assistant scholar, it's the most powerful device ever made to accomplish dull and repetitive tasks. It can even undertake tasks that require some kind ingenuity, but it might like it and even demand more kind of those tasks, so don't submit them.

fortran