• 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

Portability

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am new to Java world. I was reading this site [URL=http:////java.sun.com/java2/whatis/] and found that

The idea is simple: Java technology-based software can work just about everywhere. Java technology components don't care what kind of computer, phone, TV, or operating system they run on. They just work, on any kind of compatible device that supports the Java platform.

So The questions are:
1. I am not sure how can any device be able to support Java Platform?
2. can't a device any other programig platform like it does Java Platform?
I can't get my head around above statements. It would be a great help if someone could explain me in a layman terms.
thanks.
[ May 14, 2003: Message edited by: Buipali Thulung ]
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you need to run a Java Program is a JVM (Java Virtual Machine).
There are JVM's for Windows, Linux, Mac, HP-UX, etc. So if your TV has a little operating system -- you can install a JVM and tada -- run Java. Granted... most TV's haven't come to the point of having an OS.
Now phones -- they can run Java. J2SE (Java 2 Standard Edition) is what computers run. J2ME (Java 2 Micro Edition) is a version that has a teeny tiny footprint that can fit on a phone (or PDA, or maybe a microwave / watch or TV). You can install J2ME on a device and voila -- it can run a Java program too.
Realize this is all a bit over-simplified... but hopefully that helps to wrap your head around things.
 
Buipali Thulung
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jessica,
thanks for the quick reply.
There are JVM's for Windows, Linux, Mac, HP-UX, etc. So if your TV has a little operating system -- you can install a JVM and tada -- run Java. Granted... most TV's haven't come to the point of having an OS.
so if the program is developed and then let's say is going to be executed on Linux, do we need to attach the JVM with the program for Linux or the target machine has JVM already? i hope i have been able to make myself clear to you?
thanks.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mostly you just require that the target machine has the java environment installed. For windows users, there are installers that will install the correct version of the JRE (Java Runtime Environment) if needed. For UNIX users, well, you assume anybody using UNIX is technologically aware enough to install Java themselves
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java langauge adhears to a strict specification. When compiled, byte code is produced (this is not the same as executable code on your PC). The Java Virtual Machine interprets the byte code and executes it on the target platform, thus the code you compile can be run on any platform with a JVM installed. The JVM is written specifically for that platform.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi peter,
thanks for you reply. however, i still have a couple of questions that i hope you might be able to help me out.

When compiled, byte code is produced (this is not the same as executable code on your PC).


what does that mean? isn't it true that the bye code that is "class" file is executable?

The Java Virtual Machine interprets the byte code and executes it on the target platform, thus the code you compile can be run on any platform with a JVM installed.


am i correct that the target machine has to have a JVM to run a program written in java? does that JVM needs to be installed by someone in target machine or the program that's going to be run on that machine takes the JVM with it? how does it make portable? or how does it differ with program written in VB or C++ as far as portabilty is concerned?
i would appreciate if any one could clearify it?
thanks.
 
Joel McNary
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's what's going on "behind the scenes" with Java. The Java language is extremely portable and powerful because it is (at different levels) both a compiled language and an interpreted language.
In an interpreted language (such as PERL or LISP or a shell script/batch file), the code must be read and parsed. This means that your machine must have something installed to parse the file; you cannot run a Python script without the Python interpreter present. Interpreted code is very flexible; you could write a PERL script to work on any platform. However, since the interpreter is required, each platform must have its own interpreter.
Interpreting a script is a time-consuming process, since each time the program is run the script must be re-parsed. Compiling a language allows you to turn your code into efficient, machine-understandable code that does not need to be parsed every time.
(Rather silly) Example: You have a program with 1000 lines of code. 999 lines are comments describing what you intend the program to do and the entire revision history of the project. The remaining line reads 'print "Hello, World"'
An interpreter would have to parse the file every time, reading the 999 lines of comments (even if it does nothing with them, it still has to figure out where the comments end...) and then executing the code. A compiled language would parse the file once, throw out all the comments, optimize the code, and then create a new file that can be run to print "Hello, World". Every time the resulting file is run, it is optimized so that the machine can efficiently print "Hello, World"
The problem with compiling a program is that different platforms have different machine-level code sets; a Windows processor has no clue how to run a program compiled for a Mac Classic. To write code that is portable, it must be interpreted.
Enter Java.
Java provides a special kind of interpreter called a virtual machine. There are different Virtual Machines out there: one to interpret for UNIX, one to interpret for Windows, one to interpret for your cell phone, etc. They all take the same input and produce different output.
The difference between a Virtual Machine and a classic interpreter is what they are interpreting. A classic interpreter has to parse the source file every time (like our file with 999 lines of comments). A virtual machine takes a standard set of "virtual machine instructions" and interprets them for the platform that the VM is running on. These virtual machine instructions are the bytecode that is produced when you compile your java code. what javac does is exactly like the compiler above; it strips out the comments, optimizes the code, etc. But the resulting file is not intended for a UNIX or Windows processor; it is intended for the JVM. The JVM then interprets this code for the specific platforms.
So, to answer your questions:
1). No, the byte code is not truly "executable." It must be interpreted by the JVM
2). Yes, the JVM must be present. The code does not take the JVM with it; it must be installed separatly. You can either have the person installing your program make sure that java is installed -OR- use an installation program (such as InstalAnywhere) to automatically detect if the JVM is installed and install it if not.
3). This is different from C++ in that C++ must be recompiled on every platform you want to run it on (but Java requires the JVM to be present, where a compiled C++ program is truly "stand-alone"). Using java, you compile your program once and then any JVM can run it (depending on version, of course...)
This is different from VB in that Java works on more platforms than just Windows....
 
T Rai
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi joel,
thank you so much for your thorough explanation. let me reinforce my understanding by reiterating what you explained.

1). No, the byte code is not truly "executable." It must be interpreted by the JVM
2). Yes, the JVM must be present. The code does not take the JVM with it; it must be installed separatly. You can either have the person installing your program make sure that java is installed -OR- use an installation program (such as InstalAnywhere) to automatically detect if the JVM is installed and install it if not.

3). This is different from C++ in that C++ must be recompiled on every platform you want to run it on (but Java requires the JVM to be present, where a compiled C++ program is truly "stand-alone"). Using java, you compile your program once and then any JVM can run it (depending on version, of course...)
JVM


Based on you explanation what i can see is that Java's portability means unlike C++, a program written in Java does not need to be recompiled based on the machine platform it's going to be executed. it's compiled once and JVM takes care of it.
I think, It looks like, at least to me, it's different level of indirection that in C++, you recompile based on the machine where as in Java, you compile once but you need to install corresponding JVM in every machine. AM I CORRECT?
thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic