I'm curious how true this - not a nitpick, this is a genuine question. Will a Java application that runs on desktops also run fine on J2ME?
It won't even run. About 98% of classes used by desktop are missing. JME has 20 or so classes total + vendor extensions. JDK has about 100k in standard library alone.
Then there's Android which uses some form of Java, but isn't AFAIK compatible (at least, I don't think applications for J2ME run on Android, and certainly not vice versa). OTOH, C++, whilst not supported by major platforms like S40, will run on a range of higher end mainstream platforms like Android and Symbian.
They are different things. Android isn't even Java. It's Java like syntax (that whole licensing dispute with Oracle they had back then was over Google not licensing Java).
I've listed options above:
JEE (enterprise edition, IBM WebSphere, Rational* tools, App servers)
JDK (standard edition)
JME (there's about 3 basic profiles, and a lot of proprietary extensions, the only thing shared is the very basics of some classes and syntax)
Android (Java compatible syntax, but uses custom JVM and unlicensed runtime, if lawyers had it their way it wouldn't be even called Java).
These are the most common ones. There's some other variations but not in widespread use.
Then there is the Open vs. proprietary libraries dispute. Oracle holds some patents on parts of standard library. Despite being open, one isn't allowed to do certain things with it, so the open versions of JVM runtime are missing some minor parts or are a patent minefield so they are available as part of optional install. It's a mess really.
JDK is subset of JEE. Both run on same VM, difference is in tooling and standard library. JDK is what desktop users install, there's plugin + SDK downloads.
JME is simply per-device, there is nothing portable about it.
Android is something different again.
Soon there will be commercial edition of some of Java platform, but it should be compatible with JDK/JEE. Then again, who knows.
JVM could run on a variety of platforms, being portable, and because it was ported to the mobile phone so easily. (although, it does require the Linux Kernel to back it) it seemed to me it could be transported to other platforms as well.
Bytecode and source code could. But if mobile device uses a non-standard proprietary API that exposes OGL/ES mapping which isn't available anywhere else, then you're stuck. Same goes for all media and 2D/3D rendering code. It's either abandoned, not standardized or proprietary. So hypothetical portability in general sense isn't possible since crucial libraries aren't portable.
Between equal class of JVM however, things are write-once-run-anywhere, barring some major vendor snafus. JDK and JEE, for all practical purposes work everywhere, but only for standard libraries. OGL, for example, is not officially supported. Nor is anything beyond the most basic media playback, which requires native support from codecs, again due to patent and licensing issues. Good luck getting your special decoder for Solaris or somesuch non-mainstream (Windows XP+, Linux or OSX) OS.
If you stick in console or on server, things are ok-ish. Mostly. If staying on mainstream OSes. The recent versions. That do not block standard update channels (like Apple). Or mark JVM as malware (like Firefox).
Isn't this fun?