• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Byte code

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Jesper de Jong.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic