Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Byte code

 
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
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic