Why Java is a platform independent language?
Answers were Sorted based on User's Feedback
Answer / nikhlesh gupta datia(m.p.)
The compiler converts source code file into bytecode files. These codes are machine independent and can be run on any machine. Java interpreter reads the bytecode files and translates them into machine code for the specific machine on which the Java program in running.
Is This Answer Correct ? | 252 Yes | 12 No |
Answer / prapanch
platform independent means,the java compiled program can be
run on any operating system.because when you compile a
program you will get a class file which contains byte code
which is specific to java. that byte code can understand by
jvms (java virtual machines).for different operating
systems different jvms will be there.so the jvm will
convert the byte code into machine understandable code.so
as the jvm is different for different operating systems no
need to worry much,that will take care of explaining to the
os.ok.
Is This Answer Correct ? | 126 Yes | 15 No |
Answer / rani
Java solves the problem of platform-independence by using
byte code. The Java compiler does not produce native
executable code for a particular machine like a C compiler
would. Instead it produces a special format called byte
code. Java byte code written in hexadecimal, byte by byte,
looks like this:
CA FE BA BE 00 03 00 2D 00 3E 08 00 3B 08 00 01 08 00 20 08
This looks a lot like machine language, but unlike machine
language Java byte code is exactly the same on every
platform. This byte code fragment means the same thing on a
Solaris workstation as it does on a Macintosh PowerBook.
Java programs that have been compiled into byte code still
need an interpreter to execute them on any given platform.
The interpreter reads the byte code and translates it into
the native language of the host machine on the fly. The most
common such interpreter is Sun's program java (with a little
j). Since the byte code is completely platform independent,
only the interpreter and a few native libraries need to be
ported to get Java to run on a new computer or operating
system. The rest of the runtime environment including the
compiler and most of the class libraries are written in Java.
All these pieces, the javac compiler, the java interpreter,
the Java programming language, and more are collectively
referred to as Java.
Is This Answer Correct ? | 118 Yes | 34 No |
Answer / guest
One of the key reasons Java technology is useful in a
networked environment is that Java makes it possible to
create binary executables that will run unchanged on
multiple platforms. This is important in a networked
environment because networks usually interconnect many
different kinds of computers and devices. In a typical
enterprise environment, for example, a network might
connect Macintoshes in the art department, UNIX
workstations in engineering, and PCs running Windows
everywhere else. Although this arrangement enables various
kinds of computers and devices within the company to share
data, it requires a great deal of administration. Such a
network presents a system administrator with the task of
keeping different platform-specific editions of programs up
to date on many different kinds of computers. Programs that
can run without change on any networked computer,
regardless of the computer's type, make the system
administrator's job simpler, especially if those programs
can actually be delivered across the network.
Is This Answer Correct ? | 27 Yes | 11 No |
Answer / ashwani maddeshiya
This is because of the magic of Byte Code which is OS indepedent. When java compiler compile any code then it generate the byte code not the machine native code(unlike C compiler).Now this byte code need a interpreter to execute on a machine.This interpreter is JVM.So JVM read that byte code(that is machine indepedent) amd execute it. Different JVM is designed for different OS and byte code is able to run on different OS.
Is This Answer Correct ? | 12 Yes | 1 No |
Answer / shital mhetre
Platform independent is nothing but write-once
Run-Anywhere.It means program can run on any Operating
System(OS).
compiler Interpreter
Java source code------->M/C code------->Linux or windows
javac JVM
Fig.
When you compile a source code by using javac compiler you
will get .class file which contains byte code.
that byte code can understand by JVM(Java Virtual Machine).
so, the JVM is different for different OS(operating system).
after that the JVM will convert the byte code(by using
interpreter) into machine understandable code i.e 1's & 0's.
Java is compiler as well as Interpreter Programming Language.
Is This Answer Correct ? | 12 Yes | 6 No |
Why packages are used?
Explain different ways of creating a thread?
Define class?
Can an abstract class be final?
What is a heavyweight component?
How are multiple inheritances done in Java?
What is ternary operator?
How to do encapsulation in java?
Is sizeof a preprocessor?
How many types of string data types are there?
What is memory leak and how does java handle it?
Is string thread safe in java?