Talk:Java class file: Difference between revisions

Content deleted Content added
 
(17 intermediate revisions by 14 users not shown)
Line 1:
{{WikiProject banner shell|class=Start|
//hello.java
{{WikiProject Java|importance=low}}
} class java
}}
 
== Structure section needs a lot of work ==
 
heThe 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. - [[User:Dmeranda|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. - [[User:Dmeranda|Dmeranda]] 21:09, 23 October 2007 (UTC)
Line 37:
 
::I did find a nice EULA-free description of what happened in class format 50.0: [https://jdk.dev.java.net/verifier.html 50.0 type checking verifier].--[[Special:Contributions/128.210.4.214|128.210.4.214]] ([[User talk:128.210.4.214|talk]]) 19:12, 8 January 2008 (UTC)
 
== Major and Minor Version values in Class File header ==
 
What is the source for the description given for the Major version in the class file header?
 
I checked a number of JDK Java compilers, and found
 
* 45.3: javac 1.2.2
* 46.0: javac 1.4.2_12,1.4.2_14
* 49.0: javac 1.5.0_11,1.5.0_12
* 50.0: javac 1.6.0_06
 
So there is some difference to the description text for the major version given in this article, at least some JDK 1.4.x versions seem to be using major 46 instead of 48, and at least some 1.2.x versions use 45 instead of 46.
 
== boolean, byte, and short in constant pool ==
 
The article states, "Other integral types appearing in the high-level language, such as boolean, byte, and short must be represented as an integer constant."
 
While it's true that if you wanted to include a constant of one of these types into the constant pool, an integer entry
was needed, a standard compiler will never do so as there are instructions (bipush and sipush) for using small integer values directly without the need for a constant pool entry at all.
 
Since the Java bytecode makes no difference between these integral types, all int values fitting into the short value range are encoded this way. Only values outside this range or needed for initializing compile-time constants (e.g. static final fields) will end up in the constant pool. <span style="font-size: smaller;" class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/77.188.94.56|77.188.94.56]] ([[User talk:77.188.94.56|talk]]) 15:56, 22 February 2011 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
 
: Indeed, byte, short, and smaller char constant values used in the code will never appear in the constant pool (and maybe this is worth mentioning in the article). But for other uses of constant pool entries, e.g. the compile-time values of static final variables, these types require an int entry. There is another difference between the general class file format and the byte code instructions: as the article states, there’s no padding in the class file format, but within byte code instructions there is an exception to this rule regarding the two switch instructions as their tables are aligned. [[Special:Contributions/77.12.173.11|77.12.173.11]] ([[User talk:77.12.173.11|talk]]) <span style="font-size: smaller;" class="autosigned"> — Preceding [[Wikipedia:Signatures|undated]] comment added 09:40, 16 April 2014 (UTC)</span><!--Template:Undated--> <!--Autosigned by SineBot-->
::without jdk why we cant run the java programm in comand promnt [[Special:Contributions/119.235.54.130|119.235.54.130]] ([[User talk:119.235.54.130|talk]]) 09:17, 3 April 2024 (UTC)