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

platform independent vs portability?

 
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone clear the difference between these 2 concepts with suitable example
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Platform independent in the case of Java means that Java programs are completely independent of the operating system on which you run them. When you write a Java program, it can run on Windows, Linux, OS X or any other operating system without any changes or need to recompile the code (as long as there's a Java runtime environment available for the operating system).

Portable means that you can recompile the source code of a program to a platform-specific executable without changing the source code itself; you just need to compile it. The resulting executable will only work on the specific CPU type and operating system that you have compiled it for.

If you write a program in for example C++ and you use libraries and APIs that are for a specific operating system, then your program is not portable. You can't easily create a version of your program that would run on an Apple Mac, for example, because the Windows API that you used doesn't exist there.

Also in Java it's possible to write programs that are not platform independent. For example if you use paths in your code like "C:\Temp" etc. then it's not going to work on OS X or Linux, because path names look different on those operating systems.
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the commonest ways to lose platform independence is to hardcode line end characters. Never mind how many books use \n, it is almost always incorrect bcause line ends are platform‑specific.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's why I usually prefer to use String.format() with the "%n" conversion.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this definition of portability in context of java is incorrect :"compiled Java language programs are portable to any system on which the Java interpreter and run-time system have been implemented"
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is true in a very general sense, but as others have already pointed out it is entirely possible to write platform-dependent programs in Java.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic