This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to create a java Destop app that can parse php from an API? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "how to create a java Destop app that can parse php from an API?" Watch "how to create a java Destop app that can parse php from an API?" New topic
Author

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

mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

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

Joined: Oct 13, 2005
Posts: 39084
    
  23
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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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.


Mohamed Sanaulla | My Blog
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

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

Joined: Aug 08, 2010
Posts: 210

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

Joined: Oct 13, 2005
Posts: 39084
    
  23
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

Joined: Aug 08, 2010
Posts: 210

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

Joined: Oct 13, 2005
Posts: 39084
    
  23
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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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

Joined: Aug 08, 2010
Posts: 210

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

Joined: Oct 27, 2005
Posts: 19697
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

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

Joined: Aug 16, 2005
Posts: 14194
    
  20

There are libraries such as Google GSON to work with JSON data in Java.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

And I just glanced through the HttpClient tutorials and they should be a good start point for you
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi Mohamed,

That is exactly the page i just opened up as you wrote this ;) so i think i will just start there .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to create a java Destop app that can parse php from an API?