r/learnjava • • Oct 23 '20

Is it possible to build a Reddit bot using java?

Hey everyone,

As the title states I want to build a Reddit bot using java. Unfortunately while searching for some learning materials and videos on YouTube I was only able to find stuff for python. So is it possible to build a Reddit bot or even a twitter bot using java? Thanks

59 Upvotes

20 comments sorted by

35

u/fluffytme Oct 23 '20

You can use Java to consume any API really. Give "Java reddit api" a google and you will see a few reddit api wrappers that people have made. Using a wrapper will remove a lot of the work you'd have to do to get up and running.

8

u/[deleted] Oct 23 '20

Thanks a lot, I’ll check it out. Appreciate your input.

6

u/WishfulLearning Oct 23 '20

Hi there, mind if I ask what you mean when you say consume? I'm just starting to learn about what APIs are. Are APIs language agnostic? Or are they written for specific languages? Or a mix?

14

u/fluffytme Oct 23 '20 edited Oct 23 '20

The most common form of API is a Rest (Restful) API and these are language agnostic.

An api is a way for programmers to obtain or send data from/to an application in a controlled manner.

For example, a reddit "endpoint" might look something like:

reddit.com/api/users/get/{USERID}

When your application calls this url (endpoint) it will most likely return some Json containing information about the user you requested. Your application can then do whatever it needs to do with the data reddit has returned in the Json.

Because of this, as long as your program, in whatever language, can parse the json then it can be used for any language, making it language agnostic.

Another form of API is a language API, eg Java or Python; having a list of commands (or classes in java's case) you can use to manipulate the language and build your program with.

Hope that clear it up, let me know if you need me to explain further.

Edit: re the example url above: you are consuming that endpoint, it's just a fancy way of saying calling the endpoint.

1

u/[deleted] Oct 23 '20

Is Java > Python for that kind of job?

5

u/fluffytme Oct 23 '20

Not necessarily. Both can call rest endpoints. It really depends on what you are building.

I've never been a fan of "x language is better than y language" because I believe every language has it's place. However, and I'm a bit biased here because I'm a Java dev, Java has a massive ecosystem with tons of 3rd party libraries that can make these sort of tasks a breeze, and Java's documentation quality is usually second to none. I can't really speak for Python because I've not touched it since uni. Performance wise Java wins because of it's JIT (just in time) compiler and optimizations - after JVM startup (quite slow) it continuously optimises itself, making it perform faster the longer the JVM is running.

3

u/[deleted] Oct 23 '20

Agreed. Really depends on the libraries, documentation, and ecosystem surrounding the language for whatever helps you and your specific problem the most

2

u/[deleted] Oct 23 '20

Nice, I'll start a programming college next year and they focus on Java there, so I already started to get a ballpark figure of it. Though, I've stopped studying Java and started Python because I really figured it's a lot easier to get stuff done without much bureaucracy and I wanted to be able to build some programs to maybe start working with programming by the end of the year. Do you think I'll have problems with Java in the long run if I go on with this strategy? I'm kinda postponing Java to learn during the course, with instructions, part of the logic is Python is easier to self-teach too.

1

u/fluffytme Oct 23 '20

Both Java and Python are extremely popular starter languages, and it varies from institution to institution on what is used; My uni CS course used Java as it's core language and then touched on other languages as seperate modules.

It really boils down to personal preference, but maybe since your course focuses on Java it might be worth studying Java until you start?

What do you want to do once you have finished your course? Java is THE language for massive enterprise backends, nothing really comes close to it's power as a backend language. If you arent interested in doing that as a job it might be worth focusing on another language and using Java on the side as a hobby.

Ignore people who say "Java sucks", "Python sucks", etc. Learn what you want to learn, both are incredible languages.

Edit: regarding the verbosity of Java, yes Python is a lot easier to get started with, but the extra boilerplate/verbose-ness of Java has it's advantages. Java is usually incredibly easy to debug because of how type safe and strict it is.

1

u/[deleted] Oct 23 '20

What do you want to do once you have finished your course?

I'm not sure about the options that are there, and I'll most probably only know for sure during the course, but I'd honestly prefer the most stable job possible at least for the first few years, since I'll be living abroad and will need a constant source of income. Then, eventually I'd like to work with scientific programming, but at first I'm mostly worried about getting any job, to develop that "real world" work experience in the field, since I'm not so young anymore and this will be my second degree.

1

u/hermitfist Oct 23 '20

Any ideas how and where I can start to learn to make a Python API that uses Pandas to manipulate CSV/Excel files then connects to a Java GUI like Swing/JavaFX? Or would I better off just doing everything in Python and Tkinter? I mean I saw a stackoverflow post where they mention use the Runtime.getRuntime().exec(args) command, but will this be enough for what I want? Was just thinking of making something for my mum who is an accountant which can double as practice for me to learn new things.

Thanks!

1

u/fluffytme Oct 23 '20

I really can't comment on the python part I'm afraid, maybe someone who can will chime in.

The Runtime class for java is used for issuing commands like you would in the OS command line. For example, on windows, there is a command "whoami" which will return the logged in username. If you needed to know that, run that command using the Runtime class and then you'll have the output available to use in your program.

14

u/ILikeSahne Oct 23 '20

4

u/[deleted] Oct 23 '20

Thank you for this, I’ll take a look at it tongiht

4

u/xRageNugget Oct 23 '20

technically you can build java bots for everything what you can reach with a browser also, since it is capable of http and websockets.

When there is no API, you can always look at selenium, which makes automating websites a breeze.

2

u/[deleted] Oct 24 '20

Interesting, I figured that it would be possible. I’m also wondering, why is it much preferred to do it in python??

1

u/King5lay3r Oct 24 '20

Maybe because of the verbosity of Java, which led to abundance of Python bots and related libraries so much so now its ubiquitous

0

u/[deleted] Oct 23 '20

[deleted]

1

u/[deleted] Oct 23 '20

I can’t get this video to load unfortunately. Thank you for the input though

0

u/[deleted] Oct 23 '20

[deleted]

1

u/[deleted] Oct 23 '20

Got it, will check it out. I’ve never worked with angular, would be good to learn a bit. Thanks

1

u/fluffytme Oct 23 '20

He's not looking to make a clone, he wants to be able to talk to the official reddit public API