How to Convert Java to Python

"Don't reinvent the wheel" is one of the first lessons learned by an aspiring programmer; don't spend time recoding something that has already been done. If the code doesn't match your desired language, however, it may be difficult to convert. Converting code from Java to Python is made possible, however, by a utility that will automatically convert much of Java to Python. By using this application, you can save massive amounts of time using the Java wheel in a Python program.

...
Converting code by hand from one language to another is difficult.

Step

Download and extract java2python. The file you download is a gzip file, and it contains within it a tarball file; both are compression schemes, and both can be decompressed with 7zip, an open-source program.

Step

Place the contents of the java2python folder on the root of your C:\ drive.

Step

Open a command prompt and navigate to "C:\java2python\" before typing in "python setup.py install" without quotes. This will tell the Python interpreter to run the setup script and prepare your computer. Change directories to "C:\java2python\bin\" and keep the window open.

Step

Copy the Java file to be converted into your bin subfolder, under java2python. In the command line, run "j2py -i input_file.java -o output_file.py," replacing the input_file and output_file with your filenames.

Step

Open the new Python folder and read the code. It probably won't be perfect, so you'll need to go over it to make sure it makes sense from a Python point of view. Even spending time manually checking, however, you will have saved large amounts of time from hand-converting.