Sergey
Sergey

Reputation: 49728

What is the difference between "architecture-neutral" and "portable"?

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.

Upvotes: 8

Views: 31837

Answers (9)

jaskirat Singh
jaskirat Singh

Reputation: 826

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.

Upvotes: 0

santosh kumar
santosh kumar

Reputation: 1

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.

Upvotes: 0

Abhishek kumar
Abhishek kumar

Reputation: 1

.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.

Upvotes: 0

cybog
cybog

Reputation: 11

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.

Upvotes: 1

TofuBeer
TofuBeer

Reputation: 61526

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.

Upvotes: 9

Patrick McDaniel
Patrick McDaniel

Reputation: 1083

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

Upvotes: 2

Jacob Mattison
Jacob Mattison

Reputation: 51052

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.

Upvotes: 9

Fortyrunner
Fortyrunner

Reputation: 12782

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.

Upvotes: 1

Jesper
Jesper

Reputation: 206776

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.

Upvotes: 1

Related Questions