Java for Android 和 Java for PC 相同吗?

huangapple go评论70阅读模式
英文:

Are Java for Android and Java for pc identical

问题

对Java在Android和通常的"纯净"Java之间的相似性感兴趣。

英文:

Interested in the similarity of Java for Android and the usual, "vanilla".

答案1

得分: 2

Java和Android中的Java是不同的东西。一般来说,这与事实并不太远。关键在于:

  1. 就语法而言,Java在任何地方都是相同的。
  2. 编译器也是相同的。
  3. 然后差异开始出现,即:

a) 并非所有标准的普通Java库都在Android中实现。

b) 一个根本性的区别:普通的Java在标准JVM虚拟机中执行,而Android在完全不同的Dalvik虚拟机中执行(在较新版本的ART(Android RunTime)中,它使用与JVM不兼容的字节码,即所谓的DEX字节码)。

从技术上讲,它的工作方式如下:

  • 程序员编写纯粹的Java代码。
  • 然后使用常规的Java编译器(javac)进行编译。
  • 接着开发系统(通常在后台且对程序员不可见)将生成的目标代码转换为Dalvik/ART目标代码(使用dx/d8工具),并附加来自Android API的必要库,就是这样。

因此,从程序员的角度来看,他是在编写Java代码,尽管从技术上来说,它并不完全是Java...

英文:

Java and Java in Android are different things. In General, this is not so far from the truth. The trick here is this:

  1. In terms of syntax, Java is the same everywhere
  2. Compilers are also the same
  3. Then the differences begin, namely:

a) not all standard vanilla Java libraries are implemented in Android

b) A fundamental difference: vanilla Java is executed in a standard JVM VM, while Android is executed in a completely different Dalvik VM (in a later version of ART (Android RunTime), which uses bytecodes incompatible with the JVM - the so-called DEX bytecodes.

Technically it works like this:

  • Proger writes for pure Java
  • Then it compiles using the regular Java compiler (javac)
  • Then the development system (usually in the background and invisible
    to the programmer) translates the resulting object code into the
    Dalvik/ART object code (the dx/d8 dock utility), attaches the
    necessary libraries from the Android API, and that's it.

Therefore, from the point of view of the programmer, he writes under Java, although technically it will not be quite Java...

答案2

得分: 1

语法并没有不同,但许多库调用是不同的。这是因为平板电脑或手机与台式机或服务器环境非常不同。例如,您的台式机可能不使用4G,也不打电话。Android手机的用户界面与“标准”桌面应用程序中的界面相当不同。而且,与桌面环境不同,Android应用程序只针对一个操作系统 - Android。

此外,Android使用的虚拟机与Oracle Java不同,并且在支持的功能方面往往有所不同。例如,参见

英文:

The syntax isn't different, but many of the library calls are. That's because a tablet or phone is very different than a desktop or server environment. Your desktop probably does not use 4G, for example, or make phone calls. The User Interface for an Android phone is quite different than what you'd have in a "standard" desktop application. Also, unlike a desktop environment, Android apps only target one OS - Android.

Also, Android uses a different virtual machine than Oracle Java, and it tends to be somewhat "behind" Oracle Java in which features it supports. See this and this, for example.

huangapple
  • 本文由 发表于 2020年9月26日 03:32:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/64070332.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定