How to program in java and python together

Asked

Viewed 561 times

1

I see various programs and systems that are programmed in various languages, such as android. I’m trying to program in java along with python, but I can’t find anything about it. I’ve tried to gather the information in json to work, but it doesn’t seem like a very good thing to use. Someone can help me

  • What exactly you need to do in Java and what you need to do in Python?

  • As java has several features I thought it best to put it as input manager, and python as it is good for AI I’m using for output. 'Cause I find it hard to do java AI

  • Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English (short version). If the help is very simple it is still possible to do in the comments.

  • Python is not good at AI, nothing. Python got a reputation for being good at AI, it’s different. Java can do anything Python can do in AI. Finding difficult is another question. Everything is harder to do in Java. It’s a language that pushes away amateurs, requires a little bit more that the person really learn to program.

  • It’s just that I’m familiar with AI in python other than java

  • 4

    Maniero: "Python is good at AI" - when 90% of AI frameworks make their Apis and documentation available primarily in Python. The premise of Python has always been to facilitate the interface, and let what is computationalemtne intensive run in native code.

  • 3

    If it’s useful to you, I voted to close because I think a "how I use X and Y together" question is too vague. Depending on the objective, the response will vary or even the recommendation will be "do not use". Addressing all possible contexts in the answer is usually unfeasible and there is a good chance the answer is a "kick" over the context of the question. If the kick is wrong, it will be an invalid answer, which only the questioner can evaluate. That is why I commented questioning what the objectives were and if the question is edited complementing this I will reevaluate my closing vote.

  • 3

    I consider it to be a completely valid question, but not in the current format. I disagree with her receiving three negative votes, because she is not all bad; but I also disagree with her receiving three positive votes, because in her current form the question is not enough.

  • 1

    For example, an improved form could be "I would like to do ... in Java because ..., but I would like to do ... in Python because ..., how can I integrate these two languages so that this is possible?"

  • 1

    @Woss as you may know people vote to be funny, curious, also wanted the opinion, usually biased, of someone on the subject because I want to do the same since I have no ability to make their own decisions. So the question is out of scope, it’s opinion-based, not clear and broad. And in fact the answer given does not answer the question, even if curious, give what people want to hear. In general just thinks good this tip ode question who only answers and does not participate in the community and does not see the lot of problem that this usually generates , even if some case does not generate.

  • Ok - just help me understand how this answer "doesn’t answer the question"? Her first two lines already answer the question. The rest goes further, including other use cases, including market use, on a large scale. AP approved as answered. What could be more objective than "the Jython project (included link) allows the use of Python and Java in the same program." ?

  • 1

    "How to program in java and python together?" the question is this and he wants you to help him do something not described. You can’t even answer that, you need at least one chapter of a book. Saying you have a tool that can be used does not answer the question asked. Even more that later the answer says "for your case you can not use what I said that can be used in the beginning". That’s a good comment, not an answer. We have a definition of what is an answer and what is a comment, so a question like that is closed, it is not suitable for an answer, for a comment is.

  • 1

    Accepting an answer is just what I said, the person heard what she wanted to hear, even if it hurts her, even if it leads her down a bad path. That’s why these answers aren’t good. I am not getting into the merits of the specific answer because I am judging the question, and it gives a lot of room for an answer that leads the person down the wrong path, the path that is in someone’s interest. Many times a person accepts because it is what he has, or even to throw a tantrum, happens a lot when someone says the opposite of what he wants to hear.

  • 1

    Responding or accepting something bad happens when the person does not know how the site works. The question is one of the worst ever posted on the site, it’s not a question of being on a thin line. Of course it can be remade and have a purpose, of course, objective, that leads somewhere, and then deserves an answer. This case does not deserve, and the fact that the reply has been posted bypassing the closure does not collaborate. It was a "go in Main".

  • 3

    It is quite simple to understand the problem even. The way it was done can arise numerous answers using Java and Python, all with scenarios, assumptions and purposes completely unrelated to each other.

Show 10 more comments

1 answer

10


There is a Python 2 implementation called "Jython" - it allows you to execute Python code within the JVM environment, importing and instantiating Java classes normally.

This is what is usually meant by "programming Python and Java together".

Now there is the distributed systems approach - in which independent systems share data and events by media such as web requests, queue managers (redis, Amazon SQS, etc...) to work together. The use of "JSON" would go there: it is a common serialization protocol for data exchange between systems in these cases. Usually these applications that work together are what companies do to accomplish their business - it’s common for a company to have an eco-system with applications in several different languages.

There is much more information and details of these approaches in this response: It is possible to merge Java with Javascript?

Now, given your clarification:

As java has several features I thought it best to put it as input manager, and python as it is good for AI I am using for output. Because I find it difficult to do java AI

It is clear that your premise on the advantages of Java in this case is incorrect. What would be "multiple features"? You can seamlessly ensure that any "multiple features" for interface, and data input and output, whether on a Web system, terminal, and even a desktop application, are easier in Python (and this can even be demonstrated objectively: the number of language details, classes, interfaces you’ll have to know to create your Python app, relative to Java, will be almost an order of magnitude smaller).

If your interest is to reach an application for Android systems, the obvious choice is to make use of Pyqt5, with pyqtdeploy to create APK. I’m not sure how well the AI libraries themselves will work on Android, and whether pyqtdeploy will be able to package them properly. An alternative is to have the AI part on a remote server, such as backend, and then you create the Android or iOS App on the technology you think best (this is already a distributed system case, as above)

On the other hand, its premise regarding the Python language - that at this point in time, most of the tools and frameworks for AI development have interfaces, examples, and documentation in Python is correct.

The solution for you then is: forget Java for now. If at some point you have an objective reason for using Java (for example, integrating a portion of AI into an existing large system), you come back with this.

And finally, Jython doesn’t have an eco-system where Python’s AI tools are replicated - some probably might work, but will lose efficiency - and it will have little documentation. In addition to what it uses Python 2. The approach to this case would be distributed systems even.

  • Thank you for answering my question. Unlike some people who just criticized. Thank you very much. I probably won’t get over that remark.

  • 3

    They criticized to improve the content of the question and understand what it wants, there is no problem in receiving criticism, the problem is not improve with them

  • 2

    The first comment to his question, was not a criticism. Already the closing of the question by the moderator, I already tried to talk to him - no use. It’s either an example code question and only a point question, or it’s closed. Stackeschange’s English-language network has sites other than stackoverflow, which allow for more general questions about t.i. and learning - the only way this question is 100% aligned is to find the exact site here (https://stackexchange.com/sites), and I can’t even tell you which one - I prefer to be a little more tolerant in what are valid doubts.

  • 2

    Read the manual they put in the comments, it is very important to understand how the site works to get along here

  • 3

    @Denis: no - according to the rigid interpretation that has been given the guidelines for questions here by the moderator (and according to him, it is the will of the "most effective participants"), this question would not be made here, no matter how much was improved - unless AP brought several examples already almost working, of systems in Python and Java communicating.

  • 3

    @jsbueno I do not know if you did not understand even when you say certain things of the other moderator, that do not proceed on what the author would have to do to reopen the post (I will presume good faith, as an obligation of moderator). The blue board is very clear, an invitation to improve the post. The closure for questions that can not be recovered is another.

  • 3

    @jsbueno "this question would not have been asked here, no matter how much improved - unless AP brought several examples already almost working, of systems in Python and Java communicating" - this is not true. But the question needs to be improved to be reopened. Why don’t you collaborate and edit it yourself? Your answer has already been half way in the salvation of the question.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.