Java 运行时与操作系统调用

发布于 2024-07-16 15:08:13 字数 69 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苄①跕圉湢 2024-07-23 15:08:13

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.

栖迟 2024-07-23 15:08:13

这显然取决于您运行的操作系统,因为每个操作系统的系统调用通常都不同:-)。

也就是说,我相信 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.

悲欢浪云 2024-07-23 15:08:13

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.

心如荒岛 2024-07-23 15:08:13

与本机库相比,Java 的标准库通常具有类似的功能集,但也有一些重要的区别。

  1. Java 是面向对象的,无论你喜欢与否。 这样做的优点是某些概念更容易管理。 例如,大多数与文件相关的操作都可以直接在 File 对象中找到。 将此与 Posix 进行比较,其中 FILE 是一个句柄,实际上只是一个数字; 进程的打开文件列表的索引。 Posix 方法非常接近操作系统实际实现内容的方式。 但在 Java 中你看不到、不知道、也不关心。
  2. Java 在某些情况下具有某些最低公分母行为。 有许多 AWT API 都是这样的,因为 AWT 需要在许多不同的平台上保持一致。 结果证明这是疯狂的,Sun 准弃用了 AWT 的大部分内容,因为支持平台同样意味着糟糕地支持每个平台。 较新的库 Swing 几乎用纯 Java 实现了所有功能,因此在跨平台方面表现得更好,因此拥有更丰富的 API。 该 API 与本机窗口库有很大不同。 另外,Swing 集成得不太好,因为它使用的本机操作系统太少。
  3. Java 具有本机库所没有的某些限制。 例如,您没有函数指针。 因此,您可以使用ListenersRunnable 以及其他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.

  1. Java is Object Oriented, whether you like it or not. The advantage of this is that certain concepts are easier to manage. For example, most file related operations are found directly in the File object. Compare this to Posix, where a FILE is a handle which is really just a number; an index into your process's open file list. The Posix approach is very close to how the OS actually implements stuff. But in Java you don't see that or know it or care.
  2. Java has certain lowest-common-denominator behaviours in certain cases. There are many AWT APIs that are the way they are because AWT needed to be identical on a number of separate platforms. That turned out to be madness, and Sun quasi-deprecated most of AWT, because supporting platform equally meant supporting every platform crappily. The newer library, Swing, implements almost everything in pure Java, and thus is far better at cross-platform stuff, and thus has a richer API. And that API is very different from the native windowing library. Also, Swing doesn't integrate too well because it uses so little of the native OS.
  3. Java has certain limitations that the native libraries don't have. For example, you don't have function pointers. Thus you have Listeners and Runnable 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文