This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Byte code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Byte code" Watch "Byte code" New topic
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
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Byte code
 
Similar Threads
Doubt
doubt in implict casting
doubt
Doubt in if()
doubt