Technology update: Java architecture for mobile applications

You can also read this article in French.


You can also read this article in French.

The“mobile app” is becoming indispensable. At the start of 2010, there were 200,000 mobile applications. By the end of 2011, the one million mark was reached.

Driving this rapid market growth is both an increasingly complete offering from leaders such as Apple or Google but also, and above all, an increasingly high demand from users. As shown in a diagram produced by MDG advertising, by late 2010 more time was spent on mobile applications than spent on the web itself in the United States. A trend that should also catch up in Europe.

With richer user experiences, integration with specific hardware (camera, GPS, accelerometer, etc) and offline access, it’s easy to understand how mobile apps have taken such an important place in the lives of mobile users. However, this brings with it changes and new demands, especially in terms of applications for communication.

Java, originally intended for business applications, naturally finds its place in mobile development; services created for the web are transferable to mobile, provided that needs have been correctly identified and the right solutions found. 

1. Different needs for data recovery

Accessing data on demand
This is a recurring need for many applications. Their operation requires access to data either occasionally, such as when registering with local data stores, or on a more regular basis. As with any application, in order to operate it must make a call to a server which will transmit the data back to it. Similarly, this process is used to save, edit and delete information.

Take an application such as Twitter for example. The Java backend enables it to retrieve time based information - tweets - or persisting information - a subscription - at the request of the user.

Get real-time data
Although less common, it is sometimes a necessary demand. In this instance, it is important to pass all changes to data through to the application immediately. This is the case for applications that require the display of stock fluctuations automatically, or when there is the need for geolocation to track movement on a map.

Obtaining real-time data requires that the application registers with the server to be kept informed. It does not call for direct updates, the server is responsible for sending new data to registered customers. This type of operation is commonly called "Push".



2. Flexible technical solutions

a. WebServices to deal with demand
A WebService is a computer program that allows communication and data exchange between applications. It registers on the Internet - or intranet - a set of features accessible by applications or machines. There are two types of services:

  • SOAP (Simple Object Access Protocol)
    Originally created by IBM and Microsoft, and based on XML, it allows the transmission of messages between remote objects. With a SOAP WebService, you can invoke methods remotely. In practice, they are widely used in enterprise systems.

Advantages: SOAP operates over HTTP, so communication difficulties (proxies, firewalls) are reduced and it can also be adapted to other protocols. SOAP is independent of platforms and language, and can be extended if necessary.

Disadvantages: Using SOAP can be problematic if the bandwidth is limited. This is due to the use of XML and the presence of a specific wrapper - header and body – which require the transfer of additional amounts of data. SOAP outlines how applications communicate, which induces a strong coupling between the client and the server. So any changes on the server side must often be passed client side.

Technologies: JAX-WS (Java API for XML Web Services), Axis, CXF

  • REST (Representational State Transfer)
    REST is neither a protocol nor a format, but an application development model based on the Web. Through this architecture you access resources, which can change, by their representation. REST is based on some simple principles:
    • A resource can be identified by its URI
    • Standard operations of the HTTP protocol (GET, POST, PUT and DELETE) are required and automated.

Advantages: Systems using REST do not hold a client state, thus increasing their performance and reducing the load. Use of the HTTP protocol can benefit from web functionality, such as caching. Unlike SOAP, REST does not define its own wrapper, thus reducing the impact on bandwidth.

Disadvantages: Actions are limited, only CRUD is possible. Security is low although solutions, which we will subsequently tackle, do exist.

Technologies: JAX-RS (Java API for RESTful Web Services), Restlet, RESTEasy, spring-mvc / Rest ...

b. WebSockets for real-time updates
WebSockets is part of web standards. It is a bidirectional communication channel and full-duplex allowing the client to communicate with a server, and the server to communicate with a client, simultaneously. The technology is still young and the specifications are not yet finalized, but  inspite of this, it is still useable. It can be implemented on modern browsers or through Java specific servers and its applications are numerous:

  • Multiplayer games
  • E-mail
  • Monitoring real-time information (Sports, financials or social networks)

Technologies: Jetty WebSocket Server, Caucho Resin or jwebsocket


3. Security, a necessity
Unless you want to see your data revealed or your computer systems undermined, security is a key step. There are 3 components:

  • Authentication: This determines whether the user or the machine is who they claim to be.
  • Digital signature: This is part of a message that ensures authenticity and the identity of its author.
  • Encoding: This transforms the data representation so that it is not readable by others.

There are technologies that ignore part of the complexity of these concepts to facilitate the task of developing. WS-Security (WSS) is a protocol established in 2004 that specifies how to secure WebServices (integrity, confidentiality and authenticity) and responds to the issues mentioned above. In the Java world, Spring-WS or Axis2 are complete and satisfactory WSS solutions.


4. Data transfer
In a mobile application, be it either iOS or Android, one will often manipulate data objects written in Objective-C or Java. For data exchange, the preferred formats are XML or JSON (JavaScript Object Notation). It is then advisable, for transit, to convert the objects into one of these two formats. Setting up the conversion solutions is done natively or through the addition of bookstores and is valid in both directions.

a. Java to XML
The most popular is JAXB (Java Architecture for XML Binding) API provided by Oracle. On Android, to limit the memory footprint, you may also choose SAX (Simple API for XML)

b. Objective-C to XML
Some libraries allow this transformation, including XSWI or WonderXML.

c. Java to JSON
Again several libraries are available. In particular, we may note Gson Google or Json-lib.

d. Objective-C to JSON
There are numerous options here. We can consider a parser, such as JSONKit or YAJL, or opt for Jastor. This last one allows populating objects from a JSON Dictionary.

These solutions allow object-oriented operation, either the client or server side while the 2 parties communicate through a transfer format and maintain a small memory footprint during this transformation.


To conclude: Be it for data on demand, remote backups or outsourced data streaming, the Java world provides a set of stable and mature solutions to meet the specific needs of connected mobile applications.


Digital news!

Are you as digitally addicted as we are? We can supply you with a regular dose of digital news. Simply sign-up, or click to Follow us online.

About the author

Bertrand Cirot
Bertrand Cirot

Bertrand is a Consultant in our J2EE Solutions team, where he works on developing java and mobile applications for prominent clients.