8

Is it possible to use only Java (without C++ /NDK) for building good, fast, beautiful Android apps (including 3D development)?

When I look for Android developer position requirements (vacancies), I see that knowledge of C/C++/NDK is very important. Some companies even require to build their test tasks using only C++ (OpenGL).

2
  • Why would you want not to know something? Since it is at least useful, you'd better spend a couple of days and learn it. Commented Nov 2, 2012 at 11:53
  • Have you ever tried to use OpenGL in Java? It's a real pain to do. Commented Nov 2, 2012 at 12:09

4 Answers 4

6

In most cases you do not need c/c++ to develop for android.

According to Android NDK Overview

II. Android NDK Non-Goals:

The NDK is not a good way to write generic native code that runs on Android devices. In particular, your applications should still be written in the Java programming language, handle Android system events appropriately to avoid the "Application Not Responding" dialog or deal with the Android application life-cycle.

however c/c++ is important if you want to use existing c/c++ libraries.

Example: Android has no build-in mp3 encoder but you can use opensource lame library.

The same might apply to 3d-imageprocessing

4
  • 4
    That's just the hype from Google - all the fast and fancy games I have on my phone are built with the NDK - look for yourself, get Addons Detector (originally for showing dodgy ad networks) and look at the developer toolkit section. You'll see all the good stuff is built with the NDK. Now whether that's because java sucks or because all the best developers use C/C++ is debatable. Commented Nov 2, 2012 at 12:57
  • 2
    @gbjbaanb: games are somewhat of a special case (on both the Desktop and on mobile platforms). Granted, on mobile platforms they are a more widespread special case ;-) Commented Nov 2, 2012 at 13:02
  • @gbjbaanb: intresting to hear that most fast games are developped in c/c++. Are these Games Cross-platform? (i.e. exist for android and iphone?) Commented Nov 2, 2012 at 13:06
  • 1
    The only language that allows writing portable applications is still C++. That's simply fact. Some mobile platforms hava Java, some have CLR, but neither is reasonably available on all. Therefore any complex application will have C++ core. On top of which it may have Java UI for Android. Commented Nov 2, 2012 at 13:51
3

There are many applications in Java. Development in Java is faster and the devices are so powerful these days that efficiency does not matter when the application is mainly cool user interface for some data pulled off the net. Which is majority of applications out there. So you can certainly get a job in Android application development even without C++ knowledge.

There are however several very good reasons to choose C++ for more complex applications:

  1. To this day C++ is still the only language portable to all platforms. Some mobile platforms have Java, some have CLI/CLR (.NET), but neither is available on all of them. Writing portable application in C++ is a lot of work, but is doable and proven by many examples.
  2. Java has memory inefficiency built into the language. If you look at various comparisons, similar task usually takes 3-10 times more memory in Java than in C++. So if you are doing something that needs lot of data in memory, Java would not be good choice (note that situation is much better with CLI/CLR).
  3. Dalvik, the JVM on Android, is quite a bit behind the best of breed JVMs like HotSpot. So if you are doing something that really needs raw computing power, Java is not a good choice on Android. There are however very few applications that actually need that much power. Most applications just sit there and twiddle their thumbs 99% of time waiting for user to click something and for that kind of applications Java is fine (for most of them even Python would be fine).

I think the first reason is by far the most important.

2
  • 1
    Correct me if I'm wrong, but don't even NDK apps have to compile to Dalvik to even run on Android devices? Commented Nov 3, 2012 at 2:30
  • @MichaelK: Well, yes and no. The native code is native machine code, not Dalvik. But it needs a bit of Java glue and Dalvik is loaded for it and runs that glue (and the native part is loaded into it as shared library). The latest NDK reduced the need for the glue a lot, but I am not sure whether completely. Commented Nov 5, 2012 at 9:25
2

It depends on how 'native' your apps are expected to go. It seems that for now, many apps need to be native in order to give the full Ux/UI that end users demand. Will the HTML5 & Java based API abstraction become good enough to not need this going forwards? Who knows :-)

1

It works perfectly when modifying for C/C++ code, but when java code is modified it does not automatically rebuild it. Java modifications are not send to emulator or device.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.