“架构中性”和“架构中性”有什么区别?和“便携式”?

发布于 2024-11-03 18:51:18 字数 91 浏览 9 评论 0原文

我正在阅读 Herbert Schildt 的书《Java:完整参考》,他在书中写道 Java 是可移植的并且与体系结构无关。这两个概念有什么区别?从文字上我无法理解。

I'm reading Herbert Schildt's book "Java: The Complete Reference" and there he writes that Java is portable AND architecture-neutral. What is the difference between this two concepts? I couldn't understand it from the text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(9

余厌 2024-11-10 18:51:18

请查看Java 白皮书

基本上他们是说,除了在多个环境中运行(因为在 JVM 中解释)之外,它还可以在任何环境中运行相同的内容。前者使其具有可移植性,后者使其与架构无关。例如,int 的大小不会因平台而异;它是由 JVM 建立的。

Take a look at this white paper on Java.

Basically they're saying that in addition to running on multiple environments (because of being interpreted within the JVM), it also runs the same regardless of environment. The former is what makes it portable, the latter is what makes it architecture-neutral. For example, the size of an int does not vary based on platform; it's established by the JVM.

清君侧 2024-11-10 18:51:18

一个可移植的 C 程序:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    printf("Hello, World!");

    return (EXIT_SUCCESS);
}

您可以使用该 C 程序并在任何具有 C 编译器的机器上对其进行编译并使其工作(假设它支持 printf...我猜有些东西可能不支持)。

如果您在 Windows 上编译它并尝试在 Mac 上运行该二进制文件,它将无法工作。

用 Java 编写的同类程序也可以在任何安装了 Java 编译器的计算机上进行编译,但生成的 .class 文件也可以在任何具有 Java VM 的计算机上运行。那是建筑中立的部分。

因此,可移植是一种源代码思想,而架构中立是一种可执行思想。

A portable C program:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    printf("Hello, World!");

    return (EXIT_SUCCESS);
}

You can take that C program and compile it on any machine with a C compiler and have it work (assuming it supports printf... I am guessing some things out there may not).

If you compile it on Windows and try to run that binary on a Mac it won't work.

The same sort of program written in Java will also compile on any machine with a Java compiler installed, but the resulting .class file will also run on any machine with a Java VM. That is the architectural neutral part.

So, portable is a source code idea, while architectural neutral is an executable idea.

眉黛浅 2024-11-10 18:51:18

环顾四周,我发现另一本书描述了两者之间的区别。

对于体系结构中立,编译器将生成一个体系结构中立的目标文件,这意味着编译后的 Java 代码(字节码)可以在存在 Java 运行时的许多处理器上运行。

对于可移植性来说,这意味着规范不存在依赖于实现的方面。例如,在 C++ 中,int 可以是 16 位,也可以是 32 位,具体取决于谁实现规范,而在 Java 中,int 始终是 32 位。

我从另一本书(Core Java 2:基础知识)中获得了我的信息,因此它可能与他的含义有所不同。这是一个链接:核心 Java 2:基础知识

Looking around I found another book that describes the difference between the two.

For architecture neutral the compiler will generate an architecture-neutral object file meaning that compiled Java code (bytecode) can run on many processors given the presence of a Java runtime.

For portable it means there are are no implementation-dependent aspects of the specification. For instance in C++ an int can be 16-bit, or 32 bit depending on who is implementing the specification where as in Java an int is always 32 bit.

I got my information from a different book (Core Java 2: Fundamentals) so it may differ from his meaning. Here is a link: Core Java 2: Fundamentals

要走就滚别墨迹 2024-11-10 18:51:18

本书中的架构中立意味着字节码独立于程序运行的底层平台。例如,无论您的操作系统是32位还是64位,Java字节码都是完全相同的。您不必将 Java 源代码重新编译为 32 位或 64 位。 (所以,“架构”指的是CPU架构)。

“可移植”是指为在一个操作系统上运行而编写的程序无需进行任何更改即可在另一个操作系统上运行。使用Java,您甚至不必重新编译源代码;例如,在 Windows 上编译的 *.class 文件可以在 Linux、Mac OS X 或您拥有可用 Java 虚拟机的任何其他操作系统上运行。

请注意,您必须注意一些事情才能使您的 Java 代码真正可移植。例如,如果您在 Java 应用程序中硬编码 Windows 样式的文件路径 (C:\Users\Myself...),则它无法在其他操作系统上运行。

With architecture-neutral, the book means that the byte code is independent of the underlying platform that the program is running on. For example, it doesn't matter if your operating system is 32-bit or 64-bit, the Java byte code is exactly the same. You don't have to recompile your Java source code for 32-bit or 64-bit. (So, "architecture" refers to the CPU architecture).

"Portable" means that a program written to run on one operating system works on another operating system without changing anything. With Java, you don't even have to recompile the source code; a *.class file compiled on Windows, for example, works on Linux, Mac OS X or any other OS for which you have a Java virtual machine available.

Note that you have to take care with some things to make your Java code truly portable. If you for example hard-code Windows-style file paths (C:\Users\Myself...) in your Java application, it is not going to work on other operating systems.

神妖 2024-11-10 18:51:18

我怀疑他的意思是代码可以在许多平台上运行而无需重新编译。
还可以编写无需重写或无条件即可处理底层系统的代码。

例如,来自 32 位 Windows 系统的序列化对象可以在 64 位 Linux 系统上读取。

I suspect that he means that code can run on many platforms without recompilation.
It is also possible to write code that deals with the underlying system without rewrites or conditions.

E.g. Serialized objects from a 32 bit Windows system can be read on a 64bit Linux system.

捎一片雪花 2024-11-10 18:51:18

java中有3个相关的特性。

  1. 平台无关->这意味着java程序可以在任何操作系统上运行,而无需考虑其供应商。它是通过使用称为“字节代码”的魔法代码来实现的。然后,JVM 在运行时对此进行解释,或者使用 JIT(即时)编译将其编译为正在运行的体系结构(例如 i386)的机器代码。
  2. 建筑中立 ->这意味着java程序可以在任何处理器上运行,无论其供应商和体系结构如何。所以它避免了重建问题。
  3. 便携式->如果一种编程语言/技术满足上述两个特征,则可以说它是纯粹可移植的。

there are 3 related features in java.

  1. platform independent -> this means that the java program can be run on any OS without considering its vendor. It is implemented by using the MAGIC CODE called "BYTE CODE". The JVM then either interprets this at runtime or uses JIT (Just in Time) compilation to compile it to machine code for the architecture that is being run on (e.g. i386).
  2. architecture neutral -> it means the java program can be run on any processor irrespective of its vendor and architecture. so it avoids rebuilding problem.
  3. portable -> a programming language/technology is said to be purely portable if it satisfies the above two features.
巷雨优美回忆 2024-11-10 18:51:18

.class 文件是可移植的,因为它可以在任何操作系统上运行。原因是,JVM 生成的 .class 文件对于所有操作系统都是相同的。另一方面,JVM 与 OS 不同,但它为所有操作系统生成相同的 .class 文件,因此 JVM 是架构中立的。

.class file is portable because it can run on any OS . The reason is , .class file generated by JVM is same for all OS. On the other hand JVM is differ as OS , but it generate same .class file for all OS, so JVM is architectural neutral.

在风中等你 2024-11-10 18:51:18

架构中立和便携式之间有什么区别?
架构中立:Java 是一种架构中立的编程语言,因为 Java 允许其应用程序在一种硬件架构上编译并在另一种硬件架构上执行。
可移植性:Java是一种可移植的编程语言,因为Java能够执行其应用程序以及所有操作系统和所有硬件系统。

What is difference between Architecture Neutral and Portable?
Architecture Neutral: Java is an Architecture neutral programming language because, java allows its application to compile on one hardware architecture and to execute on another hardware architecture.
Portable: Java is a portable programming language because, java is able to execute its application and all the operating system and all the hardware system.

疑心病 2024-11-10 18:51:18

就 Java 而言,

Java 体系结构中立 - 这里我们讨论的是操作系统体系结构,即 java 生成中间字节代码(二进制代码)(由 JVM 处理)并允许 java 代码在您拥有的任何操作系统上运行可用的 Java 虚拟机(无论其操作系统架构如何,处理内存分配、兑现、寄存器处理、位代码处理 32 位或 64 位,同时解释代码,就像每个解释器逐行执行代码一样 - 这是由jvm(关于硬件和操作系统配置)。

可移植(通用含义如可转移、平台独立,或者甚至就源代码而言是针对所有人的修复,即简单地表示支持许多)

Java 可移植意味着 Java 机器代码在一台机器上编写,并将在任何具有适当 JVM 的机器上运行尊重操作系统

In Terms of Java

Java Architecture Neutral - Here we are talking about the Operating System Architecture i.e the java Generate the Intermediate Byte-code(binary code) (handle by the JVM) and allow the java code to run on any O.S for which you have a Java virtual machine available( irrespective of its O.S architecture to handle memory allocation ,Cashing, register handling , bit code processing 32 bit or 64 bit while interpreting the code like each interpreter execute the code line by line - this is handle by jvm with respect to Hardware and O.S configuration) .

Portable (Generic meaning like transferable, Platform Independent, or even in terms of the Source code is fix for all i.e Simply means support to many)

Java Portable means java machine code write in one machine and will run on any machine that has proper JVM with respect to O.S.

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