| Author |
Byte code
|
sharad kalla
Greenhorn
Joined: Jun 14, 2011
Posts: 3
|
|
Hi i am new to java and here too,
i have one doubt i have one class and i compile it, jvm converts it to byte code, if i run this its fine but if i change something into byte code than complier will give some error,
my doubt is how does complier that given byte code is modified?
sharad
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2925
|
|
if i run this its fine but if i change something into byte code than complier will give some error,
You cannot just change something in the byte code- You got to follow the byte code structure or the guidelines which the compiler uses to generate the byte code.
If you want to play with the byte code at run time you can have a look at- Byte Code instrumentation.
|
Mohamed Sanaulla | My Blog
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
Welcome to the Ranch!
sharad kalla wrote:i have one doubt i have one class and i compile it, jvm converts it to byte code,
No, the Java compiler converts source code (in a *.java file) to bytecode (in a *.class file), not the JVM. The JVM executes the bytecode in the *.class file.
sharad kalla wrote:if i run this its fine but if i change something into byte code than complier will give some error,
my doubt is how does complier that given byte code is modified?
How did you modify the bytecode - did you edit the *.class file with a hex editor? What exactly did you do, and why do you want to edit the bytecode directly?
The JVM does a lot of checks; before it executes the code it is checked by the bytecode verifier to make sure that it doesn't do things it isn't supposed to do.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
sharad kalla
Greenhorn
Joined: Jun 14, 2011
Posts: 3
|
|
well i just want to know how compiler knows that byte code has been modified,
i have one class file abc.class, i complied and it runs, what i did i just open this file with notepad and i can see some byte codes(eg.####), i copy byte codes and paste and save the file, now as per logic abc.class have only byte codes(eg.######) nothing else(and they already complied), so it should run but its giving errors, my doubt is how complier verify that this modify byte code is not original one?
sharad
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
|
You cannot edit *.class files with Notepad - *.class files are binary files, and Notepad can only edit text files. When you try to edit a *.class file with Notepad, it will become corrupted and unreadable to the Java compiler and JVM.
|
 |
sharad kalla
Greenhorn
Joined: Jun 14, 2011
Posts: 3
|
|
thank you Jesper de Jong.
|
 |
 |
|
|
subject: Byte code
|
|
|