r/learnjava • • Sep 02 '21

Realistically, can Java do any cool things like making bots?

I'm still in year one of college, but I am really interested in bots. I know Python is the way to go, but I know nothing about it. Curious if it's doable with Java? I know it is possible but not conveniently especially for a novice.

0 Upvotes

13 comments sorted by

5

u/Koda003 Sep 02 '21

Bots for what? If you mean for discord, I do believe there is a library for Java

0

u/Willy988 Sep 02 '21

Discord, twitter, anything main stream is fair game for me.

Is it convenient though? I tried to make a Reddit bot in Java and as a undergrad taking general courses I knew nothing about all the wrappers and extras since it was *made* for Python...

3

u/Koda003 Sep 02 '21

Discord is the only one I’m aware of that has a Java api

1

u/Willy988 Sep 02 '21

Thanks! I'll look into it.

3

u/NautiHooker Sep 02 '21

Pretty much everything that has the option for bots will do it via REST APIs. So every language that supports REST calls can make bots. (Thats pretty much every popular language there is)

1

u/nutrecht Sep 02 '21

There are Java libraries for almost anything. There are Java libraries for Twitter for example.

1

u/UnhappyGolem Sep 08 '21

I imagine every one of their values.

2

u/nutrecht Sep 02 '21

Sure. What do you want to do exactly? I've made bots for Slack and Twitter for example.

1

u/Willy988 Sep 02 '21

I'm pretty interested in some sort of social media such as Reddit or Twitter. As I said, tried it for Reddit and since it is not made for Java and instead Python, I had to use some confusing libraries that as a novice made no sense..

2

u/TheMightyHamhock Sep 02 '21

can your provide some example the code you're talking about. I would assume that you can do basically anything to twitter through use of an API. As another commenter mentioned, and language that has libraries for HTTP request should easily be able to reach out to twitter. That being said, if twitter provides a package in said language to make it easier, then that does make a difference. The difference being that you don't have to write the conde to communicate with their API as they've already provided it to you. We call these modules of code that are built to communicate with a certain service a "client". This can be a pretty broad term. You can have an Http Client. This is a library of code written to handle requests over http. You can also have specific clients for platforms like Twitter or twillio. These clients may use http or even other protocols. Http is going to be the most comment when dealing with APIs on the web, though so don't work about the other protocols too much in the beginning.

Have a look through twitters dev documentation for example

https://developer.twitter.com/en/docs/twitter-api/tools-and-libraries

You can see the clients they officially support and then if you continue to scroll you can see many open source clients. Here is one for java from that list

https://github.com/redouane59/twittered

1

u/Willy988 Sep 02 '21

I sadly don't have the code I was messing with anymore, but I think I had to use JSoup. The issue is I don't have much experience so I don't know how to start and all the tutorials are for Python is what I mean.

1

u/TheMightyHamhock Sep 02 '21

Jsoup is usually used for web scraping. You could scrape twitter's website to get information on tweets, but i'm assuming you could also get all of that information from twitter's api as well

Webpage Scraping is basically when your program get's the entire webpage and then looks through the HTML to find specific pieces of information. This is a powerful technique and is very useful. This is a very common way to collect information off of the web in an automated fashion. You can also "scrape" APIs by enumerating through the endpoints provided by the API and trying to get as much information as your can from them.

Python lends itself to a lot of those sort of activates as it's generally pretty simple to work with and has a very easy way to bring in dependencies via pip. It's great for writing small, powerful scripts. You can also use Django and Flask to make great little APIs or websites. I think it's barrier to entry is a little easier than Spring boot which would be the equivalent for java.

1

u/SadGrapeCloud Sep 08 '21

Good find! However, I do get your point