• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

platform independency

 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
everyone say that java is widely used because of its platform independency.
it is platform independent because we can write JVMs for any platform,right?(i hope so)
so...similarly c/c++ can be called platform independent if someone can write c compilers for other platforms...
why cannot someone write c compilers for someother platforms and make it platform independent??

may be i'm insane about asking this...but somebody clear me please..?
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinoth kumar k wrote:
it is platform independent because we can write JVMs for any platform,right?(i hope so)


Nope.
You dont write the jvm. It is already written by Sun. Rather the jre.
What you write is code which is executed by this jvm.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a C compiler for a different platform, you must re-compile the C code before it can be executed. If you distribute Java bytecode, you don't have to compile it again.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun is not the only company that makes the JRE; for example Apple makes their own version of the JDK and JRE for Mac OS X and IBM and HP also have their own Java implementations for the servers that they make.

The difference between Java and C or C++ in this regard is that Java programs are binary compatible - you don't have to recompile your Java program to make it work on another operating system.

When you write software in C or C++, you almost always use the API of the specific operating system you write your software for. Each operating system has its own API, and the APIs of for example Windows, Linux and Mac OS X are totally different. If you wrote a program for Windows, then you cannot just compile it for Linux or Mac OS X and it works - you most likely have to rewrite a large part of the program to make it work on another OS.

There are some standard APIs that some operating systems implement (POSIX for example), but you almost always need more than that for a real program. Especially the GUI systems of different operating systems are totally different from each other.

So, software in C or C++ is most of the time not platform-independent or even portable at all.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somebody asked this *exact* question a week or two ago:

http://www.coderanch.com/t/457622/Java-General/java/java-platform-independent

 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks David...!
that link convinced me greately in believing java is platform independent and c/c++ is not!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic