Forums Register Login

basic query

1
+Pie Number of slices to send: Send
If we can directly code a java compiler for different machines then why to introduce byte code concept at all?
1
+Pie Number of slices to send: Send
So you don't need to recompile your code on every machine you want to run it on.
+Pie Number of slices to send: Send
Welcome to the Ranch

Please be more informative in your thread titles.
+Pie Number of slices to send: Send
And that is why Java is platform independent.

Rohit , Welcome to JavaRanch
+Pie Number of slices to send: Send
Don't think yourself noob for asking that question.

Sometimes even the experienced developer never question why Java is the way it is...

The most stupid question is the one that is not asked....
+Pie Number of slices to send: Send
Thanks for your suggestions.
Still I want to know that bytecode is also not machine independent. We need a java interpreter which is unique for every machine. So why not use a machine compatible java compiler instead of using interpreter?

+Pie Number of slices to send: Send
 

rohit delhi wrote:Thanks for your suggestions.
Still I want to know that bytecode is also not machine independent. We need a java interpreter which is unique for every machine. So why not use a machine compatible java compiler instead of using interpreter?



Java compiler is javac which you use to convert the source code to byte code.
You won't want to send the source code to the customer to first compile it. Right? You want to deliver the code which is machine understandable...

Bytecode is partially machine level code which is run on a virtual machine is platform(not railways platform ) independent.

Interpreter is for running the java programs. This is because Java specifications mandates a number of run time checks all of which are not possible to be run by using a compiler.

I assume you know the difference between compiler and interpreter.

Hope that helps....
+Pie Number of slices to send: Send
 

rohit delhi wrote:Thanks for your suggestions.
Still I want to know that bytecode is also not machine independent. We need a java interpreter which is unique for every machine. So why not use a machine compatible java compiler instead of using interpreter?



Adding to what Sunny said,

These days almost all the OS have JRE which you can use to execute your Bytecode/Java applications. But the bytecode depends on only one platform i.e Java Virtual Machine
+Pie Number of slices to send: Send
 

Sunny wrote:
Bytecode is partially machine level code which is run on a virtual machine is platform(not railways platform ) independent



Thanks a lot sunny for your assitance. I am highly grateful.

Can you please explain me the above lines in detail.

What I know about diff. between interpreter and compiler is the execution pattern(compiler do it in one go and interpreter accomplish line by line).If there are any other differences...please update me about them.

Another thing that why is it easier to code an interpreter than a compiler?
+Pie Number of slices to send: Send
 

Mohamed Sanaulla wrote:
These days almost all the OS have JRE which you can use to execute your Bytecode/Java applications



Thanks a lot Mohamed Sanaulla. Can you please further explain me that how can we use the same JRE for different machines.

What I really want to add is (This is what I am concluding) : Java source code and byte both are not machine languages.Byte code can be considered a machine language for its own JVM. But similarly the code of any language can be considered machine language for its own compiler/interpreter.

Then what is different in Java if every time i need a different interpreter for different machines which is the scenario with every other language.
+Pie Number of slices to send: Send
The JRE- Java Runtime Environment consists of the Java Virtual Machine and the Java API Class files. The compiler converts the code into an equivalent Bytecode (Class files). Once the Bytecode is generated- It can be distributed to execute on any platform without the need to recompile them for different platforms.

And the JVM is NOT an interpreter, but generally we use the term JVM interprets the Bytecode, but every implementation of the JVM will have different approach to execute your bytecode- Some of them are- Just in Time compilation(JIT), Adaptive optimizer and so on.

Now coming to other languages(C/C++)- You would have to recompile the code each time for the target platform (also note that the primitives like int would have different size on different bit OS/platforms), but that's not the case with Java- You just compile it once. But to execute your bytecode you would need some software- which is the JVM and that has to be installed in which ever platform you are going to execute your code.

Agree that you would need to install platform specific JRE (Java Runtime environment) but that shouldn't be so much of a concern as posed by languages like C/C++. These days most of the OS come pre installed with JRE. You should think of JVM as a mini OS sitting on top of your actual OS.

+Pie Number of slices to send: Send
Thanks Mohamed Sanaulla for your valuable guidance. It really helped me out in solving my doubt. To consider JVM as an OS on top of a real OS makes things clear.Thanks a lot.
moose poop looks like football shaped elk poop. About the size of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 969 times.
Similar Threads
Netscape7.1 and window.createPopup()
Why we live?
input type=file
onload
build.xml question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:45:38.