I want to develop Android Apps – What languages should I learn?

June 10, 2014

Eclipse_4.2_Juno_screenshot

Even if you don’t think we are fully in a Post-PC era, it is clear that mobile platforms play an essential role in many parts of our lives. Whether for fun or for profit, developing Android apps can be rewarding, both personally and financially. Assuming you have a certain level of technical knowledge then it is possible to develop Android apps yourself, but what programming languages do you need to learn?

The official language for Android development is Java. Large parts of Android are written in Java and its APIs are designed to be called primarily from Java. It is possible to develop C and C++ app using the Android Native Development Kit (NDK), however it isn’t something that Google promote. According to Google, “the NDK will not benefit most apps. As a developer, you need to balance its benefits against its drawbacks. Notably, using native code on Android generally does not result in a noticable performance improvement, but it always increases your app complexity.”

Java

The job of these virtual machines is to interpret the bytecode.

Java is a programming language first released by Sun Microsystems back in 1995. It can be found on many different types of devices from smartphones, to mainframe computers. You can use it on your desktop PC and even on the Raspberry Pi. Java doesn’t compile to native processor code but rather it relies on a “virtual machine” which understands an intermediate format called Java bytecode. Each platform that runs Java needs a virtual machine (VM)  implementation. On Android the original VM is called Dalvik. Google has also started previewing its next generation VM called ART. The job of these virtual machines is to interpret the bytecode, which is really just a set of instructions similar to the machine code found in CPUs, and execute the program on the processor. The VMs use a variety of technologies including  just-in-time compilation (JIT) and ahead-of-time compilation (AOT) to speed up the processes.

What this all means is that you can develop Android apps on Windows, Linux or OS X and the Java compiler converts the source code into bytecode. This in turn is executed on the VM built-in to Android. This is different to the model used by iOS which uses a native compiler to turn Objective-C into ARM machine code.

Here is an example of what some Java looks like. This example uses a nested look to print out increasingly longer strings of asterisks:

for (int i = 0; i < 5; i++) {
  for (int j = 0; j <= i; j++) {
    System.out.print("*");
  }
  System.out.println();
}

This is a very simple example and the real code for an actual app is much more complex.

There are lots of online tutorials for learning Java. Here are a few from Oracle:

  • Getting Started — An introduction to Java technology and lessons on installing Java development software and using it to create a simple program.
  • Learning the Java Language — Lessons describing the essential concepts and features of the Java Programming Language.
  • Essential Java Classes — Lessons on exceptions, basic input/output, concurrency, regular expressions, and the platform environment.

You might also want to look at the following tutorials:

Google offers Android Developer Tools (ADT) bundle which includes the SDK, a version of the Eclipse IDE with the ADT plugins, and the Android Platform-tools with the Android emulator.

Once you have learned Java, the next step is to learn how to use Java to create Android apps. For that you will need the Android Software Development Kit (SDK). The Android SDK provides all the API libraries and tools you need build an Android app. Google offers the Android Developer Tools (ADT) bundle which includes the SDK, a version of the Eclipse IDE with the ADT plugins, and the Android Platform-tools with the Android emulator.

Developing an Android app is more than just Java, you need to understand how the Android UI is constructed (using XML), and how to access the different Android subsystems. Google has a series of tutorials about Android development. The  Getting Started tutorial shows you the bare essentials of Android app development.

Corona

CoronaSDK-code-and-emulatorIf you don’t want to learn Java or how to design user interfaces in XML, then there are alternatives. One is to use the Corona SDK. Corona is a high level SDK built on the LUA programming language. LUA is much simpler to learn than Java and the SDK takes away a lot of the pain in developing Android app. A simple app which displays a background image of your choice and writes some text on the screen can be written in just 3 lines of code with Corona.

Here is what some LUA code looks like, this does the same as the Java code above:

for i=1,5 do
  for j=1,i do
    io.write("*")
  end
  io.write("\n")
end

Here is the 3 line program to display a background image and write some text on the screen:

local background = display.newImage( "myimage.jpg", display.contentCenterX,
                                                     display.contentCenterY )
local myText = display.newText( "Hello, World!", display.contentCenterX,
                              display.contentWidth / 4, native.systemFont, 40 )
myText:setFillColor( 1, 110/255, 110/255 )

The first line loads the background image, the second line displays the text, and the third line sets the text color. Simple.

Almost everything in Corona is displayed via OpenGL.

Corona includes a sophisticated emulator which allows you to run your program instantly without needing to compile your code. When you want to create an Android .apk file you start a build via Corona’s online compilers and the app is saved to your PC.

Corona is designed mainly for games (but not exclusively) and as such includes libraries for sprites, audio, game networking and a 2D physics engine. Almost everything in Corona is displayed via OpenGL. This means you get GPU accelerated graphics, plus the default app is a blank canvas, all you need to do is start painting!

Corona provides a comprehensive set of getting started guides and tutorials including an Introduction to Lua, plus a Corona in 5 Minutes guide which also includes an introduction to the 2D physics engine.

Corona is free to download and use, but if you want features like in-app purchasing or the ability to call native Android APIs you need to pay a monthly subscription fee.

Phonegap

Phonegap+JavascriptIf you already know HTML, CSS, and most importantly Javascript, then rather than learn Java or LUA, you can build Android apps using the skills you already have. Phonegap is based on Apache’s Cordova project. Basically it creates a webview which you can then populate and manipulate using Javascript. The web app can interact with the various device features, just like a native app, by referencing the cordova.js file to get the API bindings. Native functions which PhoneGap support include the accelerometer, the camera, the current location, the local storage and so on.

Here is how you would output the asterisks on a web page via Javascript:

var i, j;
for (i = 1; i <= 5; i += 1) {
  s = '';
  for (j = 0; j < i; j += 1)
    s += '*';
  document.write(s + '<BR>');
}

Other choices and wrap up

Java, LUA and HTML/Javascript aren’t the only choices out there. In closing it is worth mentioning Titanium, another Javascript development system, and Gamesalad, a mobile game creator which allows you to create games without doing any coding!

If you have any experience using any of these development systems, or if you want to recommend a different one, please leave a comment below.

Comments

  • Harvie Galenzoga Boles

    Java for the win free and open source

    • Jaime A.G.

      And for the slowness!

  • Johnny

    I’m surprised there is no mention of C# using mono for android.

  • Azalar

    Seriously you should have a stopped at Java.

  • ims0ul

    Awesome post! You can use Android Studio as well. It’s improving a lot now!

  • MasterMuffin

    I used Corona and made myself just for fun an app where the name and developer’s name drops to the screen and when you press the name, a tnt drops. When you press the tnt it explodes. My experiment ended because I couldn’t get the sound to work properly :/ It would work in the emulator, but on real devices there were always problems with the sound. I still recommend recommend Corona, it’s easy to get started and many people have actually made successful apps with it. It’s easy to use in the beginning, but will get harder when trying to do more complex stuff though (like the damn explosion with animation and sound).

    BTW English is also one language you should know, makes life much easier :)

  • Ccg

    Gamesalad is the best, I am 15 and I have been making apps for years now!

    • Corbin Crutch

      Yeah, but can you take the logcat of an error report on your app and be able to fix the issue? What about implement Google Games API so that people can have their high-scores. It’s cool and all that these things exist, but they’re not logical in the long run

  • Rob Triggs

    Two friends, Java and C, are sitting in a bar late one night having a chat. Intrigued by their exotic languages, a steady stream of guys have been walking over to hit on them. However, they’re all paying a lot more attention to Java, leaving poor C stuck in a loop back and forth to the bar.

    After a few more iterations, C’s feeling a little tipsy. Eventually, she plucks up some courage and asks the next guy why he’s so keen on Java and not her.

    He replies: “It’s nothing personal C, really. I just prefer girls with a little more class.”

    • Groud Frank

      Hahahahahhah! That was genius! :D

    • IntelCore

      One hell of a story :D

  • TONY ALDO

    I’m a person who has been looking into this exact topic. The problem I find is the concept of learning Java and then figuring it out how to use it in the IDE and having everything work together.

  • rbrundritt

    C# and xamarin. The cross platform of phonegap plus the benefit of a native app.

  • Groud Frank

    I would suggest Home and Learn’s “Java For Beginners'” tutorials. They show you how to install all the software you need like Netbeans, etc. When you’re getting into app development it’s also a good idea to learn C. It helps you to better understand concepts, memory management, cpu functionality and gives you a better mental picture of how your code works. Carl Herold has an excellent C tutorial playlist on youtube. His lessons helps me better understand concepts when learning JavaScript, Python and Java. The best advice I can give is to be patient with yourself. Don’t expect to be writing super apps in a few weeks or even a few years. Practice plenty, share your code, don’t work alone and be open to constructive criticism. Make sure you understand key concepts like Classes, Objects and Functions when you’re dealing with Java. My last advice is to check out a video on youtube called “The Myth of the Genius Programmer.” It was a session done by Google developers at I/O 2009 and it’s full of wisdom. Good luck and wish me luck as I continue to learn :)

  • Jusephe

    An advertising language….

  • Wudien

    Thank you so much! This is what I needed. Also thanks to all the commenter’s. You all rock

  • Eddie Goh

    Currently learning it using ADT eclipse for android programming

  • fudge

    Shield with TCP IP 6, come off it really, four 7850s instead of three 850s? You bring it. You watch the postman, you blueprint it. You need to feel loved by your betters money. Hey kid, I’ve got tree 7, how does it sound? % 0. They set it up, no masm64, but your real.

  • csharpner

    I can’t believe you left out Xamarin’s C#. It’s very, very popular. It’s not free though. http://xamarin.com/platform

  • Chirag Jain

    GameMaker Studio for making games for ios,android,windows

  • Chirag Jain

    JS and CSS to use with appcelerator Titanium

  • Jaime A.G.

    Android needs to get rid of java ASAP!

    Benefits for developers (LESS WORK) and pain for customers (SLOWNESS)

  • derekmorr

    I’m surprised no one has suggested Scala. It’s a object-functional hybrid for the JVM, so its easy to convert to Dalvik. Much cleaner, compact, and regular syntax compared to Java.

  • Alice

    Great article on the benefits of learning another language: https://www.examtime.com/guide/learn-another-language/

  • Guru99

    You could also check out our Java tutorials – http://www.guru99.com/java-tutorial.html