Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > does bytecode and machine code are same ?

Reply
Thread Tools

does bytecode and machine code are same ?

 
 
gk
Guest
Posts: n/a
 
      09-20-2006
does bytecode and machine code are same ?

i am asking in the context of of JVM functionality.


Hi i have the following questions in my mind ....which i dont have
answer.....so i have presenting here as a list ......can you please
tell me ?




bytecode= .class file (after java file compilation)

(a) what is machine code ?

(b) does bytecode==machine code....same thing ?


(c) what JVM do actually ? does JVM converts byte code to machine code
? or what it does ?


(d) when we compile with javac ---->does JVM invoked ?

(e) when we run with java command -->does JVM invoked ?

 
Reply With Quote
 
 
 
 
Ingo R. Homann
Guest
Posts: n/a
 
      09-20-2006
Hi,

In short:

> (a) what is machine code ?


Some 'binary data' that can be executed by some 'machine'.

> (b) does bytecode==machine code....same thing ?


Well 'bytecode' is the machine code for the JVM ('java virtual machine').

> (c) what JVM do actually ? does JVM converts byte code to machine code
> ? or what it does ?


In interprets some bytecode, it optimizes, it compiles some bytecode to
'native' machine code (for the processor it runs on), it does memory
management/garbage collection, ... some very complicated things.

On a different level: It initializes classes and executetes code...

> (d) when we compile with javac ---->does JVM invoked ?


Yes.

> (e) when we run with java command -->does JVM invoked ?


Yes.

Ciao,
Ingo

 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      09-20-2006
Byte code and machine code are similar but different.

Machine Code is the Instruction set that the hardware understands, so
for example x86 (Intel/AMD... pc compatible) machines understand the
same machine code, while Power Pc (old macs) machines understand a
different machine code.

Byte Code is the instruction set a virtual machine understands. MS .Net
produces byte code that is essentially the same as our java byte code.
Similar to machine code, byte code compiled for the java virtual
machine is readable by compatible machines (jvm's), it would not
however be readable by the microsoft VM designed to interpret the
microsoft byte code.

Yes in short the JVM translates the byte code into machine code, but
not directly. This is done through calls to operating system methods.
This is why we need different JVM's for different OS's (Mac, PC,
*nix)

The java command invokes the JVM... not much else to say about this...
cjl


gk wrote:
> does bytecode and machine code are same ?
>
> i am asking in the context of of JVM functionality.
>
>
> Hi i have the following questions in my mind ....which i dont have
> answer.....so i have presenting here as a list ......can you please
> tell me ?
>
>
>
>
> bytecode= .class file (after java file compilation)
>
> (a) what is machine code ?
>
> (b) does bytecode==machine code....same thing ?
>
>
> (c) what JVM do actually ? does JVM converts byte code to machine code
> ? or what it does ?
>
>
> (d) when we compile with javac ---->does JVM invoked ?
>
> (e) when we run with java command -->does JVM invoked ?


 
Reply With Quote
 
Sachin
Guest
Posts: n/a
 
      09-20-2006
(a) Machine code is the code that underatand by the native instruction
set of the computer. (eg. RISC & CISC)

(b)No. Byte code deals only with the java virtual computer (java gains
platform independence because of this java virtual computer).

(c)Java VM understands byte code. Byte code executes on the JVM
instruction set. Which has a stack based architecuture (architecture of
the machine instruction set might be different). Threrefore no need
(and do not have a meaning) to convert byte code to machine code.

gk wrote:
> does bytecode and machine code are same ?
>
> i am asking in the context of of JVM functionality.
>
>
> Hi i have the following questions in my mind ....which i dont have
> answer.....so i have presenting here as a list ......can you please
> tell me ?
>
>
>
>
> bytecode= .class file (after java file compilation)
>
> (a) what is machine code ?
>
> (b) does bytecode==machine code....same thing ?
>
>
> (c) what JVM do actually ? does JVM converts byte code to machine code
> ? or what it does ?
>
>
> (d) when we compile with javac ---->does JVM invoked ?
>
> (e) when we run with java command -->does JVM invoked ?


 
Reply With Quote
 
gk
Guest
Posts: n/a
 
      09-20-2006
wait a minute please.......i am getting confused now.

so when we compile

javac A.java

JVM is called and a bytecode(.class) file is generated

Now, when we run

java A

what JVM do now ? (i) does it picks up the bytecode and convert into
machine code ?
(ii) does it picks up the bytecode and convert into machine code and
then run that machine code...all three task in one go. ?

i am confused how and when a byte code is converted into machine code
and how and when this machine code executes and produce the result ?










Ingo R. Homann wrote:
> Hi,
>
> In short:
>
> > (a) what is machine code ?

>
> Some 'binary data' that can be executed by some 'machine'.
>
> > (b) does bytecode==machine code....same thing ?

>
> Well 'bytecode' is the machine code for the JVM ('java virtual machine').
>
> > (c) what JVM do actually ? does JVM converts byte code to machine code
> > ? or what it does ?

>
> In interprets some bytecode, it optimizes, it compiles some bytecode to
> 'native' machine code (for the processor it runs on), it does memory
> management/garbage collection, ... some very complicated things.
>
> On a different level: It initializes classes and executetes code...
>
> > (d) when we compile with javac ---->does JVM invoked ?

>
> Yes.
>
> > (e) when we run with java command -->does JVM invoked ?

>
> Yes.
>
> Ciao,
> Ingo


 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      09-20-2006

"Ingo R. Homann" <(E-Mail Removed)> wrote in message
news:45113d27$0$17404$(E-Mail Removed)-online.net...
>> (d) when we compile with javac ---->does JVM invoked ?

>
> Yes.


Really? How? I thought javac was a C/C++ program.

- Oliver

 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      09-20-2006
Hi,

Oliver Wong wrote:
>>> (d) when we compile with javac ---->does JVM invoked ?

>>
>> Yes.

>
> Really? How? I thought javac was a C/C++ program.


I thought, "javac.exe" is only a small wrapper which starts a JVM and
calls sun.compiler.Javac or something like that.

But I might be wrong...

Ciao,
Ingo

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      09-20-2006
On Wed, 20 Sep 2006 13:37:09 GMT, Oliver Wong wrote:
> Really? How? I thought javac was a C/C++ program.


Both "java" and "javac" are written in C, as is the JVM iteslf.

Both programs launch a JVM using JNI_CreateJavaVM().

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Thomas Kellerer
Guest
Posts: n/a
 
      09-20-2006
Oliver Wong wrote on 20.09.2006 15:37:
>
> "Ingo R. Homann" <(E-Mail Removed)> wrote in message
> news:45113d27$0$17404$(E-Mail Removed)-online.net...
>>> (d) when we compile with javac ---->does JVM invoked ?

>>
>> Yes.

>
> Really? How? I thought javac was a C/C++ program.


Yes and no. javac is a wrapper to start a JVM (very similar to java). The actual
javac "executable" is implemented in Java (sun.tools.javac.Main). Have a look at
the source that come with your JDK. The C sources for the java.exe and javac.exe
wrappers are part of that.

Thomas


 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      09-20-2006
Hi,

gk wrote:
> wait a minute please.......i am getting confused now.
>
> so when we compile
>
> javac A.java
>
> JVM is called


I'm not completely sure about that (see my answer to Oliver), but I
think, yes.

> and a bytecode(.class) file is generated


Yes.

> Now, when we run
>
> java A
>
> what JVM do now ? (i) does it picks up the bytecode and convert into
> machine code ?
> (ii) does it picks up the bytecode and convert into machine code and
> then run that machine code...all three task in one go. ?
> i am confused how and when a byte code is converted into machine code
> and how and when this machine code executes and produce the result ?


Well, early JVMs didnt convert anything to (native) machine code at all
- everything was interpreted. Nowadays, JVMs do compile some of the
bytecode to native machine code becaus of performance issues( -> HotSpot
/ JIT ). Not that this is only done for critical sections.

Because of the fact, that the JVM can use runtime-information for
optimizing (which e.g. a statical C++-compiler does not have), Java-Code
sometimes can run faster that 'native' C++-code.

Note that the internals are *very* complicated... Fortunately you do not
have to care about them!

However: If performance is a problem in your java application, then, in
99% of all cases, the problem is *not* the JVM/language, but a bad
design/implementation of your application.

Ciao,
Ingo

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
basic bytecode to machine code compiler (part 3) Rouslan Korneychuk Python 2 06-21-2011 08:06 PM
basic bytecode to machine code compiler (part 2) Rouslan Korneychuk Python 0 05-18-2011 01:03 AM
a basic bytecode to machine code compiler Rouslan Korneychuk Python 10 04-03-2011 12:12 AM
Same directory structure on development machine and final machine.... UJ ASP .Net 2 02-20-2006 08:09 PM
Is bytecode machine (in)dependent? Robert McLay Python 1 10-28-2005 04:04 PM



Advertisments