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

java platform independent?

pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
why java is called platform independent language?
because c++ can also be run in different platforms?

can anyone explain?
[ November 13, 2007: Message edited by: Bear Bibeault ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

In Java not just the source but also the compiled bytecode is the same across all platforms. You can take compiled Java code and run it on any JVM on any system.


A good workman is known by his tools.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11477
    
  16

Now i'm annoyed. as i typed my answer in your other thread, Marc answered it in this thread. so, either he or I have now wasted our time givng the same answer to the same question.

I have deleted your other copy of the thread.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
what happens in C/C++ then?


cant we do the same thing there?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11477
    
  16

no, you cannot. when you compile your C/C++ code, you change it into machine language. that language is native to a specific CPU.

Think of it this way... each kind of computer speaks it's own language. French, German, Italian, Farsi, Chinese... whatever.

the C/C++ way:
Think of my source code as English. I write the document in English (as I am a native English speaker). If i want to sent that document to each country, I have to translate it into each of those languages. I have to send the French one to France, the Chinese one to China, etc.

The Java way:
Now with java, it's a little different. the find folks at SUN computing have sent an interpreter to each country. I can now write my document in English, and send the EXACT same document to everywhere in the world. the interpreter in each country picks up the document, and they translate it into the local language.
[ November 13, 2007: Message edited by: Fred Rosenberger ]
pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
Hi sir,

when people say its platform independent are they reffering to the hardware architecture or the operating system?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11477
    
  16

that is going to depend on the person speaking. it could mean either.
pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
how does the interpretor work? Does it take token by token or line by line from the bytecode?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14345
    
  22

When you run your Java program, the JVM executes the compiled bytecode. It does not use the source code of your program. There are no tokens and lines in the bytecode. Bytecode looks like machine code instructions.
[ November 14, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
jQuery in Action, 2nd edition
 
subject: java platform independent?