I've used JPype for a while. It also starts a JVM from python. Once set up, interoperating with Java is transparent. You can start the JVM in such a way that it can be debugged directly using remote debugging tools. Answer from belayon40 on reddit.com
I've used JPype for a while. It also starts a JVM from python. Once set up, interoperating with Java is transparent. You can start the JVM in such a way that it can be debugged directly using remote debugging tools. Answer from belayon40 on reddit.com
🌐
Reddit
reddit.com › r/java › best way to combine python and java?
r/java on Reddit: Best way to combine Python and Java?
October 29, 2022 -

My project uses some packages that are available only in Python and heavily rely on C libraries. The project also greatly benefits from Java libraries and the JVM. What's the optimal way to call Python functions from Java?

I tried:

  1. Small web-services: overhead to serialize data, start and stop the services. Also debugging is harder and implementing each new function is now double the effort.

  2. Jpy: a library that runs an interpreter in the JVM. Spare the service start/stop, but: isn't really feasible for more than a single-liner, data translation between Java and Python is cumbersome, and I also encountered runtime segmentation fault errors.

Any other options?

The project is in the machine-learning domain, so involves exchanging large numeric arrays and text. In some cases the execution switches back and forth between the platforms.

🌐
Jython
jython.org
Home | Jython
The Jython project provides implementations of Python in Java, providing to Python the benefits of running on the JVM and access to classes written in Java. The current release (a Jython 2.7.x) only supports Python 2 (sorry).
Discussions

Using Python from within Java - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Closed 16 years ago. ... I have a large existing codebase written in 100% Java, but I would like to use Python for some new sections of it. More on stackoverflow.com
🌐 stackoverflow.com
can both Java and Python be used at the same time on App Engine? - Stack Overflow
For the same registered application on App Engine, is it possible to have both Java and Python "applications"? More on stackoverflow.com
🌐 stackoverflow.com
Best way to combine Python and Java?
I've used JPype for a while. It also starts a JVM from python. Once set up, interoperating with Java is transparent. You can start the JVM in such a way that it can be debugged directly using remote debugging tools. More on reddit.com
🌐 r/java
82
60
October 29, 2022
How to merge two Queues?
I am not sure where your "queueTail" variable is coming from. But where your writing into queueData seems all wrong. In the first for loop, you likely want to be setting at index "i". In the second loop you likely want to be setting at index "j". Though your second for loop is not starting j at the right position. "j" should be based off the length of q.length (no +1 needed). The greater question is why are you not using a queue which is built into java? Look into ArrayDeque for example. More on reddit.com
🌐 r/javahelp
4
3
October 2, 2014
Top answer
1 of 12
38

Why not use Jython? The only downside I can immediately think of is if your library uses CPython native extensions.

EDIT: If you can use Jython now but think you may have problems with a later version of the library, I suggest you try to isolate the library from your app (e.g. some sort of adapter interface). Go with the simplest thing that works for the moment, then consider JNI/CPython/etc if and when you ever need to. There's little to be gained by going the (painful) JNI route unless you really have to.

2 of 12
21

Frankly most ways to somehow run Python directly from within JVM don't work. They are either not-quite-compatible (new release of your third party library can use python 2.6 features and will not work with Jython 2.5) or hacky (it will break with cryptic JVM stacktrace not really leading to solution).

My preferred way to integrate the two would use RPC. XML RPC is not a bad choice here, if you have moderate amounts of data. It is pretty well supported — Python has it in its standard library. Java libraries are also easy to find. Now depending on your setup either Java or Python part would be a server accepting connection from other language.

A less popular but worth considering alternative way to do RPCs is Google protobuffers, which have 2/3 of support for nice rpc. You just need to provide your transport layer. Not that much work and the convenience of writing is reasonable.

Another option is to write a C wrapper around that pieces of Python functionality that you need to expose to Java and use it via JVM native plugins. You can ease the pain by going with SWIG SWIG.

Essentially in your case it works like that:

  1. Create a SWIG interface for all method calls from Java to C++.
  2. Create C/C++ code that will receive your calls and internally call python interpreter with right params.
  3. Convert response you get from python and send it via swig back to your Java code.

This solution is fairly complex, a bit of an overkill in most cases. Still it is worth doing if you (for some reason) cannot afford RPCs. RPC still would be my preferred choice, though.

🌐
DEV Community
dev.to › alli › what-happened-when-i-learned-java-and-python-at-the-same-time-1haa
What Happened When I Learned Java and Python at the Same Time - DEV Community
August 13, 2019 - This is a story of how I learned Python and Java at the same time, and while doing that, learned a fe... Tagged with python, java, books.
🌐
LinkedIn
linkedin.com › pulse › integrating-python-java-guide-developers-myexamcloud-7g5bc
Integrating Python and Java: A Guide for Developers
December 26, 2023 - It provides a bridge between the two languages by allowing developers to call Java classes and methods from Python scripts. To use Pyjnius, you first need to install it on your system, along with Kivy.
🌐
GeeksforGeeks
geeksforgeeks.org › java › integrating-java-with-python
Integrating Java with Python - GeeksforGeeks
July 23, 2025 - Packages like Py4j, Pyjnius, Jpype, javabridge, and JCC help invoke Java programs from Python. Also, since Java provides a wide variety of collections, we can directly use them in a Python program by including their java packages in the program.
Find elsewhere
🌐
Programmers Branch
vmnotescom.wordpress.com › 2021 › 02 › 07 › the-perfect-language-is-a-combination-of-java-and-python
The Perfect Language is a Combination of Java and Python – Programmers Branch
January 7, 2022 - I don’t want to move to Python completely. Overall, I don’t want to switch languages for working with different domains. Perhaps I can build my own from scratch, including whatever I want. But it’s not the point. I’d like to have a generic template and pick and choose different features easily. Without further ado, below are some of the things I’d like my perfect language to have. Inspired by Java and Python.
🌐
Quora
quora.com › What-is-the-best-way-to-use-Python-and-Java-together
What is the best way to use Python and Java together? - Quora
Answer (1 of 6): I like to keep projects to a single language per execution environment to avoid the cost of context switching. Java, as a JVM language, can call code written in other languages; the bulk of my experience with this is calling Scala code from Java while working on a big Play! frame...
🌐
O'Reilly
oreilly.com › library › view › beginning-python-r-using › 9780470414637 › ch21.html
21. Integrating Java with Python - Beginning Python®: Using Python 2.6 and Python 3.1 [Book]
With Python, you can run scripts directly from the source code. Compiling is optional. If you don't compile your Python code in advance, the python command will take care of this for you.
🌐
Devmio
devm.io › python › integrating-python-with-java-170663
Integrating Python with Java
April 21, 2020 - Python is an object-oriented scripting language, which automatically makes it a good pair for Java. But when combined with a Python interpreter written entirely in Java, like Jython, you could do things like write entire applets in Python.
🌐
Quora
quora.com › Is-it-possible-to-be-good-at-both-Python-and-Java-even-though-theyre-very-different-from-each-other-if-you-know-them-both-pretty-well
Is it possible to be good at both Python and Java, even though they're very different from each other, if you know them both pretty well? - Quora
Answer (1 of 2): Yes. Actually, it’s probably easier to get good at one if you know the other, especially since they are both Object Oriented (OO) languages. They have different design philosophies, notably Python being dynamically typed and focused on simplicity and explicitness, and Java being ...
🌐
Quora
quora.com › Can-you-use-Java-and-Python-for-the-same-projects
Can you use Java and Python for the same projects? - Quora
Yes — Java and Python can be used together in the same project in multiple practical ways. Choice of integration pattern depends on goals (performance, libraries, developer velocity), system boundaries, and deployment constraints.
🌐
Baeldung
baeldung.com › home › java › how to call python from java
How to Call Python From Java | Baeldung
August 27, 2025 - We can use the pluggable script engine architecture for any dynamic language provided it has a JVM implementation, of course. Jython is the Java platform implementation of Python which runs on the JVM.
🌐
Sails Software Inc
sailssoftware.com › how-to-call-python-code-from-java-and-vice-versa
How to Call Python Code from Java and Vice Versa - Sails Software Inc
July 18, 2023 - We can leverage the “numpy” library’s efficient matrix multiplication capabilities in Python. Integrating Java and Python allows us to harness the capabilities of both languages, enabling powerful and flexible solutions.
🌐
Quora
quora.com › Can-Java-and-Python-be-used-together-in-any-interesting-projects-other-than-web-development-or-server-side-programming
Can Java and Python be used together in any interesting projects other than web development or server side programming? - Quora
Answer: Yes! The majority of the software that runs the primary computer/communications system of the United States’ National Weather Service was written in Java. Some of the components have Python APIs. When I still worked for the NWS, I wrote, among many other things, a Python program that ...
🌐
Medium
medium.com › graalvm › supercharge-your-java-apps-with-python-ec5d30634d18
Supercharge Your Java Apps with Python | by Tim Felgentreff | graalvm
May 5, 2023 - Learn how you can use Python and Python libraries in your Java applications based on the example app with data visualization libraries!
🌐
Readthedocs
jython.readthedocs.io › en › latest › JythonAndJavaIntegration
Chapter 10: Jython and Java Integration — Definitive Guide to Jython latest documentation
Forget about coding those programs in Java, why not use Jython so that the Java implementations in the libraries are behind the scenes, this chapter will show how to write in Python and use the libraries directly.
🌐
Medium
medium.com › @chamlinid › integrate-java-and-python-code-bases-1c4819fe19da
Integrate Java and Python code bases | by Chamlini Dayathilake | Medium
February 14, 2025 - This story is about a super easy way to integrate Python code into a Java program. The method used for integration: Using ProcessBuilder in Java. (java.lang.ProcessBuilder) One thing that you need to do when using this method is, simplify parameter values and returns as much as you can.