aspose file tools*
The moose likes Beginning Java and the fly likes platform independency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "platform independency" Watch "platform independency" New topic
Author

platform independency

Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

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


OCPJP 6
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10372
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38817
    
  23
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

Joined: Aug 16, 2005
Posts: 14146
    
  18

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 19, 2009
Posts: 276

thanks David...!
that link convinced me greately in believing java is platform independent and c/c++ is not!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: platform independency