Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Why java is platform independent ?

  Asked By: Sunil    Date: Jun 13    Category: Java    Views: 1304

I know java is platform independent.How is it .because
with out JVM java is not platform indep. plz send some
reason why java is platform idependent



7 Answers Found

Answer #1    Answered By: Alan Palmer     Answered On: Jun 13

Well Losely speaking, a BYTECODE is a platform
So, JVM is a MACHINE that interprets this BYTECODE
that is generated with extension .class ( after you
compile your program - source code with extension

Therefore, by machine independent  is meant that:

Your program (BYTECODE) can run in most evey machine
that has installed the JVM.

Answer #2    Answered By: Guadalupe Rogers     Answered On: Jun 13

I have to tell you some history inorder to make you understand why java  is
platform independent. You see, every application is compiled to native code,
whether they are written in C,C++, or assembly language(Java does n't include in
this list). A native code is just what processor understands. It is just binary
numbers that signify different numbers for different operations. These numbers
are called operation codes or opcodes for short. So, when these opcodes are
passed to CPU, it will do specified things. Now each operating system has
different library for programmers to write applications on top of that
particular operating system. So an application developed for one
platform(operating system) cannot run over another platform. There are some
libraries that allow this, but still the programmer cannot release a single
application to run on different operating systems. So programs written in C, C++
are not platform  independent.
Now Java and ..NET are a bit different. They doesn't compile a source file
into Native opcodes. They simply compile them into some other format, which is
some way in between native code and source code, which is called byte code. Now,
a special piece of software called Java Virtual Machine(JVM) is being developed,
which converts this byte code into machine native code. So the byte code is a
portable format. i.e., it will run on every platform where Java Virtual Machine
exists. This makes Java platform independent. I think you understood now.

Answer #3    Answered By: Gustavo Taylor     Answered On: Jun 13

That i don't think is platform  independence. Even if you have 2 or more
different OS on your system, the underlying machine code is the same
since u have 1 processor only. Whether u compile using VC on windows or
gcc on Linux both produce the machine code for the same processor. What
differs are the libraries or other related stuff.

What platform independence means that your code will run on different
processor architectures. i.e. you write your code for your pc and you
can move it to say a sun SPARC machine, or an IBM mainframe, or even a
Nokia mobile phone. It will work since the task of converting byte code
to machine code is of the Java virtual machine.

Answer #4    Answered By: Velma Adams     Answered On: Jun 13

While this is substantially correct, it is seldom possible to transport
executables between operating systems - even on the same processor. Although
the underlying machine code is the same, everything else is different - library
entry point names, library calling sequences, file systems, etc. Unless an
operating system is designed to run executables from a different operating
system, they will not run even if the underlying processor is the same.

Java achieves the independence by two items: (1) the object code is the same on
all processors, (2) all library calls are the same on all processors. The
run-time environments (which are not part of the program) are different for each
processor and operating system and have the task of running the pseudo code and
of providing the standard libraries.

Answer #5    Answered By: Wilbur Hall     Answered On: Jun 13

as universal rule....
it too has it's +es and -es..
+ point : it is platform  independent
- point : it's slower than c (executable)

Answer #6    Answered By: Chione Massri     Answered On: Jun 13

I read your question regarding java  is independent  or not. Have you read any
books on Java? Never mind if not then please go for Begging Java 2 from
Wrox, it's a really nice book for a beginner. As you may already know when
you compile a Java source file, Java compiler is convert it to Bite Code
that is .class file. When run this .class file Java interpreter will convert
it to that Machine Native language and now it can be execute on that
particular machine. See JVM is needed if you would like to run any java
code. But the plus point of Java independent is you can write once and run
it anywhere, means if you have created any Java source can run on Windows,
Unix, Linux, OS-2 or any Operating system on any machine just you need is
JVM installed on that machine. This is not possible with any other
procedural languages like VB. Today we have Java enabled Browsers available.
A little example of Java independent is Websites you currently access (made
with the help of Java) is not made for a particular machine or a particular
OS though we are able to run it on any machine that may have several OS

I hope this may cleared your doubt?

Answer #7    Answered By: Thomas Camaroon     Answered On: Mar 06

Java is Platform Neutral because the same Java code will run on multiple platforms (Operating Systems) without modification, provided that the code does not intentionally put any specific demands on the system, holding true to the slogan, "Write Once, Run Anywhere" . Java's platform independence consists mostly of its Java Virtual Machine (JVM), which is a well-specified and mature virtual machine.



Didn't find what you were looking for? Find more on Why java is platform independent ? Or get search suggestion and latest updates.