简体   繁体   English

有多少Java SE api是用Java编写的?

[英]How much of the Java SE api is written in Java?

有多少Java SE api实际上是用Java编写的?

The easiest way to find out is just to look at the source code (that's from Sun's J2SE website; there's also the OpenJDK source for 6 and 7 ). 找出答案的最简单方法就是查看源代码 (来自Sun的J2SE网站;还有67的OpenJDK源代码)。 It's pretty much as you'd expect - things which absolutely have to be written in native code, eg "open a socket or a file" are native, but almost everything else is written in Java (in Sun's implementation, anyway). 它几乎与您期望的一样 - 绝对必须用本机代码编写的东西,例如“打开套接字或文件”是原生的,但几乎所有其他东西都是用Java编写的(无论如何都是在Sun的实现中)。

Download OpenJDK and find out! 下载OpenJDK并找出答案

Most of it is Java, but there are some low-level things that must be native code (graphics and file operations come to mind). 其中大多数是Java,但有一些低级的东西必须是本机代码(图形和文件操作会浮现在脑海中)。

Download Apache Harmony and find out! 下载Apache Harmony并找出答案!

Around 85% of Sun's JRE is written in Java. 大约85%的Sun的JRE都是用Java编写的。 In fact very little has to be written in native code. 实际上很少需要用本机代码编写。 IBM's Jikes RVM (formerly Jalapeño) and Sun's Maxine are JVMs almost entirely written in Java. IBM的Jikes RVM(以前称为Jalapeo)和Sun的Maxine是几乎完全用Java编写的JVM。 Most of the native code in Sun's JRE is native for legacy reasons. Sun的JRE中的大多数本机代码都是原生的,原因很遗憾。 Some because it's convenient. 有些因为它很方便。 A very small amount is native because it is (or was) fractionally faster. 非常少量是原生的,因为它(或者是)分数更快。

I don't have numbers, but it should be easy to compute. 我没有数字,但应该很容易计算。

If you want to take into consideration the total number of methods of the API to calculate a %, you could just count the total number and the ones with the native keyword on their definitions. 如果要考虑用于计算%的API的方法总数,您可以只计算其定义中的总数和具有native关键字的方法。

You can perform this calculation by parsing SUN's open source implementation source code. 您可以通过解析SUN的开源实现源代码来执行此计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM