Java 运行时与操作系统调用
Java运行时提供了一组标准系统库供程序使用。 这些库在多大程度上类似于操作系统的系统调用,以及它们在多大程度上不同???
The Java runtime provides a set of standard system libraries for use by programs. To what extent are these libraries similar to the system calls of an operating system, and to what extent are they different???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
java 的一半目的是使其独立于平台,因此它试图提供一个无论其底层操作系统如何都保持不变的 api。
如果操作系统能力不足,Java 将添加库代码来弥补。
如果操作系统有一个不映射的实现,Java 将尽力映射它。
如果一个新功能变得流行并且 Java 用户需要提供对它的访问,则可以创建一个新库,通过它您可以访问新功能。 如果这个库很受欢迎,它会在某个时候被重组并添加到Java SDK中。
例如,一些并发库的实现变得流行,很快它们就被投票并添加到标准库中。 这事儿常常发生。
Half the point of java was to make it platform independent, so what it tries to do is provide an api that remains the same regardless of the OS underneath it.
If the OS is underpowered, Java will add library code to compensate for it.
If the OS has an implementation that doesn't map, Java will do it's best to map it.
If a new function becomes popular and Java users need to provide access to it, a new library can be created through which you can access the new functionality. If this library is popular, it will be restructured and added into the Java SDK at some point
For instance, an implementation of some concurrency libraries became popular, and soon they were voted upon and added to the standard libraries. This happens all the time.
这显然取决于您运行的操作系统,因为每个操作系统的系统调用通常都不同:-)。
也就是说,我相信 Java 主要受到 Unix 约定的启发(这并不奇怪,因为 Sun 是 Unix 供应商),因此一些 Java 系统库类似于 Unix 系统调用。
例如 java.nio.MappedByteBuffer 可能受到 Unix 的 mmap() 调用的启发。 但最终大多数概念都存在于大多数操作系统上,因此您无法真正说出什么启发了什么。
That obviously depends on the OS you're running on, since the system calls are generally different for every OS :-).
That said, I believe Java was mostly inspired by Unix conventions (not surprinsingly, as Sun is a Unix vendor), so some Java system libraries are similar to Unix sytem calls.
E.g. java.nio.MappedByteBuffer was probably inspired by Unix's mmap() call. But ultimately most concepts are present on most OSes, so you cannot really say what inspired what.
Java 的一些“低级”功能基本上是某些操作系统的“包装器”
系统调用。
我没有看到一种客观的方式(和理由)来“比较”两者。
如果你对这个话题感兴趣,可以搜索Java源码
对于native关键字,表示一些“隐藏”
(主要取决于操作系统)功能。
Some of Java's "low-level" functions are basically "wrappers" around some OS
system calls.
I don't see an objective way (and reason) to "compare" both.
If you are interested in this topic, you can search the Java source code
for the native keyword, which indicates some "hidden"
(mostly OS-dependend) functionality.
与本机库相比,Java 的标准库通常具有类似的功能集,但也有一些重要的区别。
Listeners
和Runnable
以及其他Java 模式来完成在C++ 中涉及函数指针的操作。 因此,任何需要这些功能之一的 API 在 Java 中将与在本机操作系统中显着不同。总之,Java 通常具有提供与本机操作系统类似行为的库,有时提供完全不同的行为,但最好将 Java 视为一个独立的平台。 有时您需要高级性能,例如 OpenGL 或超快速数据传输,在这种情况下您将需要特定的 Java API(Jogl、nio),但大多数时候您应该将 Java 视为自己的东西。
Java's standard library often has a similar feature set compared to the native library but there are several important differences.
Listeners
andRunnable
and other Java patterns for doing things that in C++ would involve function pointers. So any API that needs one of these features will be significantly different in Java than in the native OS.So in conclusion, Java often has libraries that offer similar behaviour to the native OS, and sometimes offer completely different behaviour, but it's best to think of Java as a platform in its own right. Sometimes you need advanced performance, such as OpenGL or super-fast data transfer, in which case you'll want a specific Java API (Jogl, nio), but most of the time you should evaluate Java as its own thing.