Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create a java Destop app that can parse php from an API?

 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just curious what i would need to use to creat a desktop application that could communicate with a server API that uses and returns PHP?? Do i need a third party plug-in, or is there something already built into Java
that can do this? any links or tipps woiuld be appreciated!!

Thanks
Mike
 
Campbell Ritchie
Sheriff
Pie
Posts: 50270
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’ll scare off all the real beginners if you ask such difficult questions here! Not sure where the best place to move it is, so it might move several times, but let’s try here.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Returns php? why would you want to return php from the server?
What I could make out from your query is:
"You need a build a java desktop application which woulc communicate with the server. And this server is implemented in PHP."

So you send the request from the Java desktop application to the server, the server processes it and sends back the response to the desktop application.

Check out the java.net package for classes which support making http requests.
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell,

ok wouldn't wanna scare anyone away ;) just asked it in the beginners forum cause it sounded to me like a beginner question.


Thanks for moving it , I would like to create a small, simple desktop app to see how this is done.
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mohamed,

Yes sorry that is what i meant ;) thanks foir the tipp!!! I will go there and check it out now.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50270
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beginner’s questions are more like, “How do I write a for loop?” than, “How do I connect to a remote server?”
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Campbell,

OK i understand.

I was reading through an API example from the API i plan to try, and it says "All data is returned in JSON format", i don't know what json is really, is this something i will have to learn in order to do this as well? For that matter i don't know much in the way of PHP either.Will i need more extensive knowledge of PHP/json in order for me to do this?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50270
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should start here for JSON. If it is in JavaScript, you doubtless realise that is a completely different language from Java™?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would be learning PHP if you want to write the server which handles the requests and sends the response.

You can either use XML or JSON for the response format. JSON is similar to xml just that it kind of is similar to the JavaScript syntax. But in anycase you can find Parser libraries for parsing JSON or XML. Have a look at google-gson for creating java object from the json document and vice-versa
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the answers!! yes i realise that JavaScript is not Java. I will only be getting information from the server and showing it in my application.All it is , is a game API, i will have a app that is in the system tray and will for instance show a pop-up when one of your friends is
"Online", and creating a clickable link to the server they are on.and possibly if the user wants to, a button to start the game.exe and go to that server.as well as server info with names of players and how many and so on.
I will take a look at the link from Mohamed!!!

thanks again
Mike
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use java.net.URL with URLConnection / HttpURLConnection, but perhaps you'd prefer a more high-level abstraction like that of Apache's HttpClient. It can do the same, but it's easier in some aspects (like cookie handling for instance).
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Thanks for your reply. hm I am looking a bit through my deitel "How to program eighth edition" for some guidance, it has a networking chapter , but not exactly what i am looking for at the moment.I will take a look at the apache httpclient , then i will have to pick what i will try and just go for it and see what i end up with.I think i will just start off by opening a connection to the API server and get that working and then see if i can communicate with it. Not really sure how to send it anything yet either.I was thinking this will be an easy little program to learn about networking, but i think it involves allot more than i was expecting it too lol.
But it is OK i want to learn about this as i think it is pretty interesting and something that is worthwhile to learn.If anyone has a good tutorial about this type of client/server API program feel free to send me a link;)


Thanks
Mike
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15494
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are libraries such as Google GSON to work with JSON data in Java.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I just glanced through the HttpClient tutorials and they should be a good start point for you
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohamed,

That is exactly the page i just opened up as you wrote this ;) so i think i will just start there .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic