• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Byte code

 
sharad kalla
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sharad kalla
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Jesper de Jong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic