• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

platform independency

 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76433
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somebody asked this *exact* question a week or two ago:

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

 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks David...!
that link convinced me greately in believing java is platform independent and c/c++ is not!
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic