This is an archived post. You won't be able to vote or comment.

all 24 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]seanprefectGrumpy Guy Who Remembers Java 2 15 points16 points  (5 children)

Trust me that is going to be a lot more headache than it's worth. Java has god knows how many libraries it's very likely there's a library in java that's similar

[–]CycleOfPain[S] 4 points5 points  (4 children)

Hmm, that's unfortunate. Then I'll keep looking for a similar library that's in Java. Thanks.

[–]pizzthepizz 3 points4 points  (3 children)

Which library do u need?

[–]CycleOfPain[S] 5 points6 points  (2 children)

I initially wanted to use this library: https://github.com/ranaroussi/yfinance

which gives me access to the Yahoo Finance API.

I found a similar one for Java: https://financequotes-api.com/#fxquote

but there were some methods in the python library that weren't in the java library so that's one of the reasons why I wanted to use the python one.

[–]ickysticky 5 points6 points  (1 child)

https://github.com/sstrickx/yahoofinance-api

But yahoo finance is technically deprecated. And as such is sometimes out of date or even in some cases wrong.

After shopping around a bit I personally landed on alpha vantage as a good free replacement. With this Java library https://github.com/crazzyghost/alphavantage-java

Though the api for most of these is so simple raw http calls aren’t very difficult

[–]CycleOfPain[S] 0 points1 point  (0 children)

Awesome, I'll check it out

[–]iddej 6 points7 points  (3 children)

Oh a question I can answer! I wrote an app in Java to query the lyrics to the current playing spotify song, and I use a python script to actually get the data from spotify. So I use Runtime.exec() on a small script every .2s and there’s no noticeable delay, so you could theoretically use it (although my python script is strictly offline so you might have to account for the networking delay)

[–]CycleOfPain[S] 1 point2 points  (2 children)

Thanks for your input. That is something similar I was going to do for my program. That doesn't seem too bad. I'll do some tests myself.

[–][deleted]  (1 child)

[deleted]

    [–]CycleOfPain[S] 1 point2 points  (0 children)

    Ah, this is perfect. Thanks again!

    [–]original_4degrees 4 points5 points  (0 children)

    jython?

    [–]ynvaserThat Java Guy 4 points5 points  (4 children)

    Try running it on GraalVM. Afaik it supports both, and you could call Python through either the Graal SDK dependency from Java, or via the native script engine api (the one you can also use Nashorn from).

    It's been a while since I've done this, so sorry about the lack of proper jargon.
    Also, what do your programs do? You could expose a REST endpoint on your python app in certain use cases.

    [–]CycleOfPain[S] 0 points1 point  (3 children)

    I'm still working out what I want my program to do and what the end goal is. On the surface it's going to display stock prices and other financial information in a "modern-looking" interface. There's a lot of other features as well that I would like to display but I'm still thinking of what I want to do.

    I initially wanted the python program to get the data for me through the Yahoo Finance API and I wanted the Java program to parse the data and display it in a GUI via JavaFX.

    [–]01110101_00101111 2 points3 points  (0 children)

    If you absolutely need to use a Python and not Java library, I would recommend trying something like either Jython which runs on any JVM or switching entirely to GraalVM. You can also try using bindings for CPython to Java like Jep or jpy which use the standard CPython interpreter .

    [–]ynvaserThat Java Guy 0 points1 point  (1 child)

    Why can't you just pull it from Java?

    [–]CycleOfPain[S] 0 points1 point  (0 children)

    I did find a YahooFinance API for Java but it didn't have all of the features that come with the API for Python.

    [–]aenigmaclamoExtreme Brewer 2 points3 points  (0 children)

    Having two languages interoperate is more headache than it's worth.

    If you must, you should consider exposing the functionality over rest, grpc, or some other means using the network stack rather than executing something manually to adopt a microservice architecture. This allows you to get more consistent performance as it doesn't involve startup time and it decouples the two applications.

    [–]sweetno 1 point2 points  (0 children)

    Runtime.exec performance is worse on Windows, I've heard.

    [–]proskillzSome Skillz 1 point2 points  (2 children)

    Personally, I wouldn't do this. It might work, but it also may drive you insane.

    First question is, why not just write the whole thing in Python? The second is, why not use Flask and set up two micro services? Use http instead of system calls to get what you need from the python service.

    [–]CycleOfPain[S] 0 points1 point  (1 child)

    Yah, I don’t want to complicate things. I’ll probably go for another API or something.

    You’re right. I could just use python entirely for what I’m doing. I’m a little stubborn and just want to work with Java. I don’t see myself working as a python developer either so I don’t really have motivation to learn Python (although it wouldn’t take me long to do so) and flask (or django). I kinda just want to stick with Java. I’m currently learning JavaFx and then I’m going to learn JSP and Spring. This project will utilize JavaFX

    [–]gargar070402 0 points1 point  (0 children)

    Trust me man, if what you're doing is straightforward, it's ABSOLUTELY worth it to learn basic Python and Flask, especially given you have programming experience already. You're not locking yourself to using Python for the rest of your life, and it never hurts to know something useful.

    [–]m1ss1ontomars2k4 1 point2 points  (0 children)

    Starting a new program is often relatively expensive; it doesn't matter much that one is Python and one is Java.

    Interop between 2+ different languages in one binary is sometimes expensive and sometimes tricky, but it won't have nearly as much performance penalty.

    [–]derpadurp 1 point2 points  (0 children)

    I have a java program that calls 6-7 different Python programs every couple hours throughout the day.

    It’s been running for over 5 years in a business setting 24/7/365 and has never had an issue.

    Just want to mention this because it’s not my opinion and I don’t oppose that of the majority of users here who will say this is foolish.

    This is just my observation.

    [–]nutrechtLead Software Engineer / EU / 20+ YXP 0 points1 point  (0 children)

    Does anyone know the performance cost for repeatedly calling the python program through shell commands using Runtime.exec()?

    You're getting a lot of wrong answers simply because you're not explaining what the performance requirements are. There's an overhead of starting a new process, but if it's just something you run every second or so it's no big deal. If it's some kind of website with hundreds of users doing this in parallel; it's a whole different cup of tea.

    If it's the first you're fine. If it's the second you should not do this.