Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated Python to Java translation [closed]

Is there a tool out there that can automatically convert Python to Java? Can Jython do this?

like image 996
Victor Noagbodji Avatar asked Sep 30 '08 15:09

Victor Noagbodji


People also ask

Can Python be translate to Java?

There is a translator called P2J that can convert a subset of Python into Java. My universal-transpiler project was written for the same purpose, but it also translates Python into C#, Java, JavaScript, and several other languages.

What is Jython used for?

Jython is a version of the Python programming language that runs on the Java platform. It allows users to write programs in Python and compile them to Java bytecodes that run directly on a Java Virtual Machine, or JVM.


2 Answers

Actually, this may or may not be much help but you could write a script which created a Java class for each Python class, including method stubs, placing the Python implementation of the method inside the Javadoc

In fact, this is probably pretty easy to knock up in Python.

I worked for a company which undertook a port to Java of a huge Smalltalk (similar-ish to Python) system and this is exactly what they did. Filling in the methods was manual but invaluable, because it got you to really think about what was going on. I doubt that a brute-force method would result in nice code.

Here's another possibility: can you convert your Python to Jython more easily? Jython is just Python for the JVM. It may be possible to use a Java decompiler (e.g. JAD) to then convert the bytecode back into Java code (or you may just wish to run on a JVM). I'm not sure about this however, perhaps someone else would have a better idea.

like image 82
oxbow_lakes Avatar answered Oct 08 '22 16:10

oxbow_lakes


It may not be an easy problem. Determining how to map classes defined in Python into types in Java will be a big challange because of differences in each of type binding time. (duck typing vs. compile time binding).

like image 36
user20149 Avatar answered Oct 08 '22 15:10

user20149