Wednesday, October 15, 2014

Java Apps on iOS and Android— Now a Reality

Let me guess a couple of things about you. First, you are fuent in Java. Second, you have a smartphone, tablet, or both within reach. Am I right? Well, with the explosion of mobile device popularity, plus the fact that you are reading Java Magazine, these were not really tough guesses to make.

What might be a bit tougher is answering this queston: How do you take your Java skills and start building applicatons for the mobile devices that you—and your customers—have? That is the focus of this artcle.
As a Java developer, you can easily address the develop- ment of the back-end system that is accessed by mobile apps. But what are your optons when it comes to the actual user interface (UI) and mobile app development? A variant of Java is the language that is being used to develop Android-based applicatons, but limitng your app to just that market segment ignores a big chunk of users who are using a diferent mobile operatng system (OS)—specifcally iOS, which drives all Apple mobile devices. To solve the need for cross- device mobile development, many developers turn to hybrid mobile development. These apps run inside a con- ainer that is available as a natve app for each platform, allowing you to write a single app that runs on multple platforms. The tricky part s that most of the hybrid mobile solutons today rely on oding HTML5 plus JavaScript ode. Do you really need to abandon Java to go mobile? The answer is no. This artcle will introduce you to a Java-based hybrid mobile platform that lets you con- tnue developing in the language and tools you are using today, and enables you to run your apps on both iOS and Android. Welcome to the world of Oracle Mobile Applicaton Framework.

A Mobile Framework for Java Developers

In June 2014, Oracle released Oracle Mobile Applicaton Framework, a soluton that runs Java apps on both iOS and Android devices. Java code handles every layer of a mobile app, from the gener- atng the UI and responding to UI events, to dealing with data objects and providing access to remote services (including access to on-device mobile databases), all the way to handling the interacton with mobile device features such as the Global Positoning System (GPS), the camera, SMS, and more. Furthermore, going beyond just language similarites, the frame- work also leverages an architecture you are probably familiar with: model-view-controller (MVC). If you are currently doing MVC-based web development with Java, for example with JavaServer Faces (JSF), you are going to see familiar concepts that will make picking up this frame- work even more intuitve. And to further simplify your adop- ton, the framework has extensive integrated development environ- ment (IDE) support in both Eclipse, through Oracle Enterprise Pack for Eclipse, and Oracle JDeveloper.

Hybrid Mobile Architecture and You 

There are three approaches to building mobile applicatons: natve, web, and hybrid. In the natve approach, you work with the SDK and tools for a spe- cifc mobile OS, which means that your applicaton is not portable to other devices. In the web approach, you are stll building server-side served web pages and accessing them from the browser on your mobile device, but this doesn’t actually leverage the capabilites of modern devices and provides a less-than-ideal user experience. To overcome the challenge of developing mobile apps with those two approaches, the industry has turned to hybrid mobile applica- tons as the preferred soluton for enterprise applicatons. Hybrid mobile applicatons rely on a container that runs your code on the device. The container is available in natve format for mul- tple operatng systems, which allows you to code once and run on many platforms. Does the idea sound familiar? It should, because it is similar to the way the Java Virtual Machine (JVM) provides portability for Java code across operatng systems. In the mobile world, most of the hybrid solutons in the market are based on coding all your logic in JavaScript and coding the UI with HTML5. The container then uses the WebView component of each mobile OS to run the logic and render the UI. The Oracle Mobile Applicaton Framework hybrid container, while stll supportng the ability to code features in JavaScript and HTML5, adds Java and an MVC-based frame- work as another way to build mobile apps. An Oracle Mobile Applicaton Framework container includes a lightweight JVM that can run your Java logic, a WebView component that can show your user interface, an Apache Cordova–based layer for interacton with device features, an encrypted local SQLite database for on-device and ofine data storage, a push notfcaton handler, and a security layer for authentcaton and authorizaton. With this approach, Oracle Mobile Applicaton Framework can actually run applicatons that have a mix of the natve and web development approaches. This way, an organizaton with both Java and JavaScript developers can have them collaborate on the same mobile app.

 Powerful Development Framework

 Hand-coding every aspect of an applicaton is a recipe for a delayed delivery, which is why in the world of Java, we rely on frameworks to accelerate development. Oracle Mobile Applicaton Framework provides a complete and power- ful framework that can accelerate mobile applicaton delivery. In the world of Java development, instead of hand-coding low-level UI protocols such as HTML, we have opted for the simpler component- based approach to UI development (JSF and Google Web Toolkit are a couple of examples). For mobile user interfaces, Oracle Mobile Applicaton Framework provides a set of more than 80 UI components that can be used to create compelling mobile inter- faces. With components that range from basic input and selecton to advanced chartng, mapping, and data visualizaton, you can defne user interfaces much faster. Figure 1 shows an Oracle Mobile Applicaton Framework UI on an iPhone.
What if a component is missing? You can build your own compo- nents with HTML5 and JavaScript and add them to the list of compo- nents you can use later on. Past experience with spaghet code–based coding (servlets, JavaServer Pages) taught us about the importance of proper functonal layer separaton when building and maintaining apps, and in Oracle Mobile Applicaton Framework, this is implemented with the MVC design patern. For the controller layer, Oracle Mobile Applicaton Framework provides a process fow engine that allows you to defne navigaton between pages in your applica- tons and also include method calls, decision points, and other fows in a fow. Code in the controller layer is writen in simple Java classes that are similar in concept to managed beans in JSF. Managed beans can also contain data that will be exposed in the UI layer. Oracle Mobile Applicaton Framework provides various scopes for beans to beter handle memory allocaton. In additon, data can be incorporated from a remote server through both REST (JSON or XML) and SOAP services. Oracle Mobile Applicaton Framework uses a declaratve data- binding layer to reduce the amount of code you need to manually write to hook up your UI components to the data and business services. At development tme, a simple drag and drop will create the expres- sion language that will connect a UI component to a datasource.

Building Truly Mobile Applications 

A truly mobile applicaton leverages the platform it runs on. For exam- ple, a truly mobile expense app lets you take pictures of receipts with the device’s camera, a truly mobile product catalog uses GPS on the device to show the nearest store where you can buy an item, and a truly mobile HR system lets you quickly add an employee you are looking at to the contact list on your phone. Oracle Mobile Applicaton Framework lets you build these types of truly mobile apps by expos- ing device features for easy integra- ton into your applicaton, as shown in Figure 2.
Using  the open source Apache Cordova soluton, Oracle Mobile Applicaton Framework provides Java and JavaScript APIs that let you invoke the camera, GPS, SMS, e-mail, and other services directly from your code. Furthermore, the framework supports the Cordova plugin archi- tecture to let you add other device- specifc capabilites to your app for features such as barcode scanning and temperature measurement. Another aspect of mobile apps that Oracle Mobile Applicaton Framework can leverage is push notfcaton. Leveraging either the Apple or Google push server, a mobile app can receive push not- fcatons and react to them with simple Java listeners that you code Oracle Mobile Applicaton Framework further supports ofine scenarios for mobile apps with a built-in encrypted SQLite database that apps can use to store data. Access to fles on the local device’s fle system is also supported from within Oracle Mobile Applicaton Framework. With all of these capabilites at Figure 2 hand, you can build applicatons that truly change the way people interact with back-end systems.

IDE Integration

Having a framework is great, but without proper tooling, using a framework can actually reduce your productvity. To simplify development using Oracle Mobile Applicaton Framework, Oracle built extensive IDE features in both Eclipse and Oracle JDeveloper, providing a com- plete integrated and declaratve development experience. Download the SDKs for Android and iOS, set the paths in your IDE of choice, and in additon to devel- oping code, you’ll be able to directly package, deploy, debug, and run your mobile apps on emulators or devices, all from inside the IDE. The IDEs provide a productv- ity boost for development through wizards that help set up projects, declaratve editors for confgura- ton fles, visual editors for your controller and UI layers, interac- tve structure panes, and property inspectors that reduce typos. All of this is in additon to the powerful coding features supported by the code editors in both Eclipse and Oracle JDeveloper. Figure 3 shows an example of the Oracle Mobile Applicaton Framework features in Eclipse. Want to get an impression of the overall development experience? Watch these 10-minute demos showing end-to-end development with Oracle Mobile Applicaton Framework in Eclipse and Oracle JDeveloper.

Geting Started

Getng started with Oracle Mobile Applicaton Framework is really simple: Download your preferred IDE and follow the tutorials to properly set up your environment and build your frst applicaton. Want to learn more? A quick, free online course will get you through the basics, and more- extensive training is available for free on the Oracle Mobile Platform YouTube channel. So what are you waitng for? It has never been easier for Java develop- ers to become mobile developers.


Mobile devices are all around us, and on-device mobile applicaton development skills are in demand. With the new Oracle Mobile Applicaton Framework, you can leverage the Java skills you already have to build this new generaton of applicatons. With a productvity- boostng framework that is open for extensibility, developing cross- platform mobile apps with Java has never been simpler. Figure 3 Tube-based training
Post a Comment