• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Need info on Java platform independence

 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that java gives platform independence. I know the reason, which is like when i write my java class and compile it, my code gets converted into bytecodes. Now this bytecode can be moved to different platform.Now there are 2 question which arise...

1)Those platforms (clients) where we are deploying our bytecodes, must have JRE,JVM installed right..? So that means its not completely platform independent....isn't it?

and the sec question,which is more interesting is

2)Why do i need compile java class at all? i mean why can't i just move the whole source code in java(instead of the bytecodes) to the client machine.Client machine will have JRE/JVM installed and it will take the source code and take it forward(i.e say run it and all)...isn't it? I guess Perl works like that..please correct me if iam wrong...

 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"platform independence" is not a well defined term. It means different things to different people, and nobody is more right or wrong than anyone else. Therefore, arguing over whether something is 'platform independent' is a pointless exercise.

IMHO, the idea is that you can distribute the same executable code to everyone. In the old 'C' days, I would need to compile my source code for every platform I wanted it to run on. I would need a Windows-95 version, a Windows 98 version, a Windows NT version, a SunOS version, an AIX version, etc.

That also means I need to purchase a compiler for each of those systems. When a patch was needed, I had to recompile it for every platform, and manage distributing the correct version of each file to each customer based on what platform they ran on...

If i was trying to get a new customer who had a deal on hardware that I didn't currently support, I'd have to buy a new compiler for their platform...

With Java, I only need one compiler, I only need one set of distributable. I can send the exact same set of .class files to everyone, and I don't have to worry about what platform they are on.

As to why you need to compile it at all...that is a decent question. The platform could have been written so that you didn't have to do so, but (i believe) it generally runs slower and is easier for someone else to alter/hack/reverse engineer. Those may not be the best reasons (or even valid), but that is what I think.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks fred !
You answered my first question very well.....so thanks for that..

as far as my sec question goes, even i had the same thoughts. (i.e to prevent hacks,alter etc).

Waiting for other's responses too...
 
Ranch Hand
Posts: 34
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maan,

1) Platform Independence: It basically means write once, run anywhere. You write a piece of Java utility in Windows, the same piece can be run on Linux or Solaris without any change to source. It would save you lot of effort. Generally, all development is done on Windows Box and application in deployed on Unix Box. Thus, if Java source is written on Windows platform, you don't have to do anything special to make it run on Unix.
(Why applications are deployed on Unix & not Windows, thats a different question altogether ;))

All you need is to install JRE on the machine when the program is to be run. JRE implementations of Windows, Unix and Solaris are different. But that is at a much lower level.

2) Why you need to compile Java classes? Well, computer only understands binary (class files). It basically wouldn't have any clue about logic written using various programming constructs. Perl on the other hand is a scripting language and not a programming language.

Thanks,
Badal
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Badal Chowdhary wrote:1) Platform Independence: It basically means write once, run anywhere. You write a piece of Java utility in Windows, the same piece can be run on Linux or Solaris without any change to source.


That's the basic principle, but it does require the programmer to not use any platform specific code. The use of wrong line breaks (\r\n vs \r vs \n), file separators (/ vs \), path separators (: vs ;) etc can break the entire platform independence.

2) Why you need to compile Java classes? Well, computer only understands binary (class files).


The computer doesn't understand class files. The JVM does, and it translates it into code the operating system understands - a lever lower than Java byte code. This is done by the JIT.

It basically wouldn't have any clue about logic written using various programming constructs. Perl on the other hand is a scripting language and not a programming language.


But Python, Perl and PHP all allow code to be directly executed without the need to compile it. Java could have chosen for the same approach. It was a design decision to compile into intermediate byte code - a middle way to running code directly (usually slower but platform independent) and compiling into code native to the operating system (usually faster but no longer platform independent). In the old days, this middle way caused Java programs to run significantly slower than native applications, but the JVM has been improved quite a bit to decrease this slowness. Java applications hardly run slower than native applications these days.
 
please buy my thing and then I'll have more money:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic