• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JVM,JRE & PORTABILITY

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i am a novice in this JAVA world. went throgh a couple of books trying to understand all these JAVA jargons. could someone please explain me what these JVM and JRE are in simple way and how these two are related.
how java is PORTABLE. saw that java is "write once, run everywhere". what does it mean? how and what makes this possible? what are some of languages that are not portable?
it would be great help if you guys could educate me on these to make me good enough to see the JAVA world like you guys.
thanks.
[ October 26, 2002: Message edited by: Namaste Sathi ]
[ October 26, 2002: Message edited by: Namaste Sathi ]
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Namaste Sathi:
hi all,
i am a novice in this JAVA world. went throgh a couple of books trying to understand all these JAVA jargons. could someone please explain me what these JVM and JRE are in simple way and how these two are related.


JVM is the Java Virtual Machine. It is the thing that takes the class files and makes them run on whatever machine you are using.
JRE is the Java Runtime Environment. It includes a JVM and all the other stuff (like the standard class libraries) that you need to run Java code.
You may also see reference to the JDK (Java Development Kit) or the Java SDK (Software Dev. Kit). These are the same thing, and include the JRE plus other stuff you will need to develop (write) java programs (like source code and documentation and examples).


how java is PORTABLE. saw that java is "write once, run everywhere". what does it mean? how and what makes this possible? what are some of languages that are not portable?


Java is portable because the code that you write and compile can be run on any computer that has a JRE. The Java language is designed to not include things that only work on some computers.
You compile Java source code into Classes. These classes can be used with any computer's JRE.
The JVM is the thing that enables the portability. It translates the code in the class files into instructions that the computer can understand.
So the JVM is different for Unix and Windows and Mac computers, but the Java classes that it executes are the same.
Languages like C/C++ are not portable in the same way. First, they must be compiled from source code into an executable that only runs on one kind of computer - I worked on some C/C++ code that ran on about a dozen different kinds of computers and we had to compile it a dozen times to make it work. Same stuff in Java would need one compile.
Other portability issues can come up in the source language itself. Java includes libraries that are "platform neutral" so the same code can work on many systems. That dozen-platform program I worked on had pieces of code that had to get switched out for each platform (if Linux, do it this way, else if Windows do it this way, else if VMS do it this way, etc).
Java allows you to write code without thinking about these sorts of issues too much. Programmers can still do platform-specific things in Java, but for the most part, it is pretty easy to write code that "runs anywhere".
 
Brian Smith
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave you said the following,


JVM is the Java Virtual Machine. It is the thing that takes the class files and makes them run on whatever machine you are using.
JRE is the Java Runtime Environment. It includes a JVM and all the other stuff (like the standard class libraries) that you need to run Java code.


let me be more clear about what you mentioned. So what's the relationship between JVM and a machine with any OS in it? what am i asking is how does the JVM or JRE for that matter gets installed in a machine that understands the java bytecode?
For example, i have a hello.class. now if i would like to run this hello.class in another machine, that machine must have JVM to understand this hello.class. how does that machine alreaddy gets JVM in it? or must JVM go to that machine with hello.class? please help me understand these things this is so fundamental to understanding and working with JAVA.
thanks.
[ October 27, 2002: Message edited by: Namaste Sathi ]
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Namaste Sathi:
For example, i have a hello.class. now if i would like to run this hello.class in another machine, that machine must have JVM to understand this hello.class. how does that machine alreaddy gets JVM in it? or must JVM go to that machine with hello.class?


You are right, the machine where you want to run hello.class must have a JVM.
So how does it get one? There are several ways.
It would be ideal if the computers you bought just had the JRE already installed. This is not always the case, but is starting to happen much more. Biggest problem is you may want to use new Java features that might not be available on an older machine.
If you are sharing code with other Java users, it is a good bet that they will have a JRE/JDK already and know how to use it. For example, I can send a java class to any of my co-workers or any of our customers and I don't have to worry about it. I also figure I could post something at JavaRanch without having to provide lots of instructions about how to run it, etc.
If you are building a product, you might consider including a JRE with your installer. Many products that I have installed will give the option of using a JRE that I already have, or installing one with the product.
Or you could write your application as an Applet. There are then limitations about what you can do but the browser should provide the JRE (or know how to download/install one if it doesn't have it).
Another option is something like Java Web Start. I have no experience with this, but it is technology to help install your code and the proper JRE. You might check java.sun.com or the JavaRanch forum on Web Start / JNLP.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only thing that is different from one platform to another platform, one OS to another OS is the JVM. If you have a Mac with OS10, you must locate the JVM for that particular computer, download it, and install it. The MAC JVM is completely different from the PC/Windows JVM because it is designed and written only for a MAC. BUT, the two JVM's work the same way.
A good example is a Ford car and a Chevy car. Both are cars (like Macs and PC's are both computers), both have engines (like Mac's and PC's both have JVM's). Both cars work the same way, both perform the same function (like Mac's and PC's). But a Chevy engine only works in a Chevy car, and a Ford engine only works in a Ford car. Then say I give you a Chevy car without an engine. You want to make it go, so you must go out and find a Chevy engine and put it in.
Now you have a car with an engine. But there's no gas in it. You have to put gas in so you go to ANY gas station and put gas in it. In theory, all gasoline is exactly the same. You can go anywhere in the world, to any gas station and put gas in the car and make it go. The same is true for Java bytecode, which is what is inside class files. You can go to any web site that has Java applets, or run any java .class file on any machine that has it's version of a JVM on it, and make it go.
One of the few problems with Java is that it is VERY SLOW. Because the JVM must step through the bytecode in the class files, interpret the code, then perform the actions the bytecode calls for, it is very slow. All interpreted languages are slow. Visual BASIC traditionally is an interpreted language. COMPILED languages like C++ are very fast in comparison. C++ generates an executable .exe file that runs without an interpretor. But for every different computer, you must compile the source code with a compiler and linker designed for that machine.
Cool, ain't it?
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MacOS X comes with Java 1.3.1 built-in. You don't have to download or install anything to compile and run Java programs.
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Schowiak:

One of the few problems with Java is that it is VERY SLOW. Because the JVM must step through the bytecode in the class files, interpret the code, then perform the actions the bytecode calls for, it is very slow.


Nonsense.
This was somewhat true for java 1.0, but is just not true anymore.
And actually, the JVM is not required to be an interperter. Java is a bytecode-based language. Nowhere does it say that those bytecodes must be run by an interpreter. You are free to implement the JVM in any way that meets the spec, including implementing it in hardware.

COMPILED languages like C++ are very fast in comparison. C++ generates an executable .exe file that runs without an interpretor.


Bah.
Bytecode-based languages can be complied, too. This is what the hotspot compiler in sun's JVM is doing. Other JVMs (such as IBM's and BEA's JRocket) use similar technology. These JVMs are compiling the bytecodes on-the-fly to machine-specific code. This has the advantage over traditional compilers that the code can be optimised as it is run so it may be faster than similar code compiled from C/C++.
 
Brian Smith
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so the best bet would be to include JRE with the Java-based products that are going out in the world so a machine that'll use this product can get JVM from product itself. RIGHT?
As Steve Schowiak mentioned, machines with different OS require their corresponding JVM not the SAME ONE and since we don't know already which machine with which OS in it will use the java-product, how do we make sure that all machine get their required JVM regardless of OS they have?
appreciate if you could make it clear to me.
thanks.
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is common practice to make installers to cover "most" of your customers. These installers would be platform-specific and can do nice things like setting icons, menus, etc. And they can install athe right JRE if necessary or desired.
Then, you could make something like a zip file for those small number of customers on other platforms. Write a README to tell them that they need to get JRE version XXX and inform them how to run your product from java (i.e. "java -jar goodStuff.jar" or whatever).
 
Brian Smith
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Dave and Ron for your invaluable insight about JRE and JVM. Now i am comfortable to understand them.
thanks.
 
no wonder he is so sad, he hasn't seen this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic