Talk:Java class file
//hello.java } class java
Structure section needs a lot of work
The structure sections need some work, it is incorrect as is. The "arrays", such as the constant pool, are not arrays in the typical sense (the entries are not all the same size), instead it is more like a stream. Thus the formulas calculating it's size are misleading at best; they don't compute the number of bytes used. Also they don't account for the strange fact that long and double types consume two slots (leaving a phantom unused slot behind) rather than one slot like all other types. It should also be mentioned that the JVM's UTF-8 string type is not quite standard UTF-8; it is a modified non-standard form. The C representation is also by no means able to "fully represent" the file structure as stated. First, one must assume big-endian layout, no padding bytes, and the use of IEEE 754 floating point storage format. And as mentioned the arrays are nothing like C arrays at all (they contain variable-width members), so that part is pseudo code at best. Also the structure shown is only the outermost layer; none of the dependent inner types are shown in the code (so it can not be a complete representation). The table is also just visually cluttered, I'm sure it could be cleaned up a lot. - Dmeranda 05:20, 23 October 2007 (UTC)
- I've made some attempts at cleaning up the large table and elaborating on some of the details. I also removed the fake "C structure" section entirely; it was not even close to being correct C code, and was not at all useful to this article. - Dmeranda 21:09, 23 October 2007 (UTC)
C programming language representation belongs in article
The Java Virtual Machine Specification introduces the class file format with a C-like representation rather than a binary table format for a reason. Some find this more readable and easier to comprehend. That is why both are present in this article. @modi 05:06, 8 November 2007 (UTC)
- I appreciate trying to make this article more readable, but with this case I disagree. The reason is apparently because the JVM spec authors don't know C, or didn't care, or because they follow the code with dozens of pages of clarifying text which then go on to explain why the format is actually not like the pseudo-C code they just presented. This example code is not even remotely close to being correct C code (or even Java code), and trying to present it as such is quite misleading. Most of the "types" are of undefined variable length (C types are always fixed length). No padding bytes are ever introduced (as C frequently does). A definite byte-order is mandated, which C can never indicate. The things which look like C arrays are stored absolutely nothing like real C arrays. Even the indicated "length" of the arrays is completely wrong in the constant_pool case due to the double-slot flaw. In fact, just about everything in the file format is so completely not like C that I wonder what in the world the writers of the specification were thinking. If a reader can't understand a table of simple file offsets and wants to pretend like they can use a C structure then they can read the spec; that's why it's listed in the references. This article is not trying to replace the entire quite-lengthy specification, it is only showing a flavor of the format. Copying large blocks of poorly-authored text verbatim from the referenced document (which shouldn't be done regardless of quality) and taken out of context (from all the clarifying text that follows) provides no extra value here, and only clutters the article and adds about a dozen ways the reader can be easily misled. - Dmeranda 14:08, 8 November 2007 (UTC)