This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
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
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply 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: 24081
    
  15

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How does byte[] get compiled in the class file?
 
Similar Threads
Compile with the package statement
technical doubt
JSP Compilation doubt
How JIT (Just In Time Compiler) Works
Getting Image height in a JSP