|
Authored by: Anonymous on Friday, May 25 2012 @ 11:19 PM EDT |
To compile your Java language program, you need to have .class files for
any packages/classes that are USED BY your program.
This means that programs written for a Java platform, need to be
compiled against the Java platform's packages. These are part of the
JDK (Java Development Kit) you get from Oracle, or more properly, they
are part of the JRE (Java Runtime Environment) which is a subpart of the
JDK. You need the JRE to run your Java platform program, too. The JRE
contains a Java VM as well as those class library packages.
If you are making an Android program, you would instead use Android's
SDK (I don't know what its called). You would compile with javac, but
using the Android class libraries instead of the JRE ones. Some 51
packages have the same APIs between the two, but the rest are different.
(You would use dex after the javac step).
To make a program that works on BOTH platforms without modifications,
you would have to make both platform's entry point in your program, and
limit yourself to using only APIs from those 51 packages, and not use
other APIs that only one of the two platforms supports. In theory you
could then use either platform's class library when compiling the source
code with javac, and the compiled .class files would run fine on either
platform (for Android you'd have to run them through dex too).
What's a far more plausible scenario though, is taking large chunks of
code from one platform, and porting them to the other platform (by
changing only the parts that relied on non-supported APIs). This is much
less work than rewriting them from scratch. Many useful libraries exist, or
could be written, which would be 95-99% compatible with both platforms
(imagine image or data compression libraries, video and speech codecs,
sound synthesis libraries, a 2D software rasterizer, or file-processing
libraries, or a scientific math library for things like sparse matrices... or a
statistics library, or computational geometry, or image processing libraries,
or thousands of other useful things of this sort--none of these would need
much of anything outside the 51 packages, and they might all be useful
on (and easily ported between) both Android and J2SE.[ Reply to This | Parent | # ]
|
|
|
|
|