I'm starting on Android and I also do not have much Java experience. My first application will have a query to a remote server. My question is:
In Java (and therefore in Java), what is more practical when it comes to getting data: in Json or XML?
I'm starting on Android and I also do not have much Java experience. My first application will have a query to a remote server. My question is:
In Java (and therefore in Java), what is more practical when it comes to getting data: in Json or XML?
Briefly, JSON is very concise and easy to interpret by the machine. Since XML is more expressive, you can express complex dialects, however it is quite verbose in relation to JSON, so the representation of the same dataset tends to be significantly larger.
Specifically for Java / Android there are good manipulation libraries for both formats, but if you do not know what to use I would recommend going with JSON as it is the simplest format.
I agree with BrunoBR, XML is more verbose and has more dialect possibilities than JSON, which is simpler and easier to understand.
As far as practicality, there are very good frameworks to deal with both, so I do not see this as a criterion that strongly influences the decision to choose between one or the other. I would take more into consideration the conversion speed of XML-> Java and Java-> XML in relation to the conversion speed of JSON-> Java and Java-> JSON and the size of the file that will be transferred from the web service to the application. On a mobile device with limited hardware and limited internet, any detail in performance makes a difference.
It has a very good post by Thomas Uhrig comparing performance of Java frameworks that deal with JSON x Java frameworks that deal with XML. As a result of the tests carried out by him, the following conclusions were reached:
The first result of my tests was that the Jackson framework (JSON) writes the data a bit faster than the framework JAXB (XML) and the Gson framework (JSON). The difference is not much.
Java writing -> XML and Java -> JSON did not have much of a performance difference between the 3, but said that Jackson did the task a little faster than the other 2.
What is most interesting is the fact that the two implementations of frameworks for JSON (Jackson and Gson) read much faster date than than JAXB.
He realized that reading JSON -> Java in both frameworks was much faster than XML - > Java in the JAXB framework.
The JSON file was about 68% of the size of the XML file correspondent.
If we put the same content in an XML file and a JSON file, the JSON file will be 68% lighter. Now, think how this can make a total difference if we take into account the mobile internet that we have in our country. We need to take very into consideration the size of what will be transferred from web service to application, this is basic concept. Delaying to load a dataset can make the user experience a bad experience. User does not like to wait, shoot that for me = D.