aspose file tools*
The moose likes Java in General and the fly likes How does byte[] get compiled in the class file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How does byte[] get compiled in the class file?" Watch "How does byte[] get compiled in the class file?" New topic
Author

How does byte[] get compiled in the class file?

ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85
Hi,

If I have a method which has a byte[] as its variable,

public void f1() {
byte[] matchBytes = {0x50, 0x4e, 0x47};
...
}

like this, how does that compile into a class file?
When I open the compiled class file, and search for '0x50' '0x4e' '0x47', nothing is found.

And what if I have a class which has static constants attribute of byte[] matchBytes = {0x50, 0x4e, 0x47}; how does that compile into a class file?

Thank you.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

It's rather unsettling, actually. Array initializers aren't compiled into a block of data that can be copied directly into an array; they're compiled into a stream of executable code that sets the elements of the array one at a time!



You can disassemble classes like this using the "javap" tool: "javap -c Foo" shows you the bytecode for class Foo.


[Jess in Action][AskingGoodQuestions]
ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How does byte[] get compiled in the class file?