我试图通过查看其二进制数据来了解如何确定 .class 文件的版本。我知道使用javap
会告诉我版本 - 但遗憾的是我并不总是在需要检查的机器上安装 JDK 。但我可以访问普通的旧HEX编辑器......
我尝试从经过认证的来源找到相关文档 - 我能够提出的就是:http://fredericktang.wordpress.com/2007/09/28/java-class-file-version/
虽然这篇博文非常精彩 - 但它并没有真正备份官方Java文档。
任何提示?
编辑:没关系 - 抱歉 - 我找到了规范: here
答案 0 :(得分:4)
您引用的文档实际上是JVM类文件规范的逐字转录(更易于使用英语)。
我保持方便的一些hitoric值
Major Major(hex) Minor Java platform version
45 2d 3 1.0
45 2d 3 1.1
46 2e 0 1.2
47 2f 0 1.3
48 30 0 1.4
49 31 0 1.5
50 32 0 1.6
---为响应Neil的观察而编辑,1.0和1.1使用相同的少数主要数字---
从类标题中,无法确定该类是否针对1.0或1.1版本的Java进行编译。也就是说,还有许多其他技术可以帮助确定是否针对1.0或1.1编译了一个类。
首先,如果该类是针对1.1编译的,那么它可能包含一个仅1.1的库类。一旦在其中一个类中找到其中一个,就可以安全地得出结论,它是针对Java 1.1编译的类。
请注意,可以在类的开头搜索常量池,以确定类文件需要哪些类才能完全解析所有外部引用。
单独搜索课程可能很麻烦,幸运的是还添加了很多软件包。以下包特定于Java 1.1,即它们未包含在Java 1.0
中+ java.awt.datatransfer
+ java.awt.event
+ java.beans
+ java.lang.reflect
+ java.math
+ java.rmi.dgc
+ java.rmi
+ java.rmi.registry
+ java.rmi.server
+ java.security.acl
+ java.security
+ java.security.interfaces
+ java.sql
+ java.text
+ java.util.zip
在围栏的另一侧,对以下方法的大量调用建议(但不是实际证明)代码是针对Java 1.0编写的,因为它们在Java 1.1中由于新的awt事件重构而被弃用。
Deprecated Classes
java.io.LineNumberInputStream:
LineNumberInputStream is deprecated.
java.io.StringBufferInputStream:
StringBufferInputStream is deprecated.
Deprecated Methods
java.awt.BorderLayout:
addLayoutComponent() is deprecated.
java.awt.CardLayout:
addLayoutComponent() is deprecated.
java.awt.CheckboxGroup:
getCurrent() is deprecated.
java.awt.CheckboxGroup:
setCurrent() is deprecated.
java.awt.Choice:
countItems() is deprecated.
java.awt.Component:
getPeer() is deprecated.
java.awt.Component:
enable() is deprecated.
java.awt.Component:
enable() is deprecated.
java.awt.Component:
disable() is deprecated.
java.awt.Component:
show() is deprecated.
java.awt.Component:
show() is deprecated.
java.awt.Component:
hide() is deprecated.
java.awt.Component:
location() is deprecated.
java.awt.Component:
move() is deprecated.
java.awt.Component:
size() is deprecated.
java.awt.Component:
resize() is deprecated.
java.awt.Component:
resize() is deprecated.
java.awt.Component:
bounds() is deprecated.
java.awt.Component:
reshape() is deprecated.
java.awt.Component:
preferredSize() is deprecated.
java.awt.Component:
minimumSize() is deprecated.
java.awt.Component:
layout() is deprecated.
java.awt.Component:
inside() is deprecated.
java.awt.Component:
locate() is deprecated.
java.awt.Component:
deliverEvent() is deprecated.
java.awt.Component:
postEvent() is deprecated.
java.awt.Component:
handleEvent() is deprecated.
java.awt.Component:
mouseDown() is deprecated.
java.awt.Component:
mouseDrag() is deprecated.
java.awt.Component:
mouseUp() is deprecated.
java.awt.Component:
mouseMove() is deprecated.
java.awt.Component:
mouseEnter() is deprecated.
java.awt.Component:
mouseExit() is deprecated.
java.awt.Component:
keyDown() is deprecated.
java.awt.Component:
keyUp() is deprecated.
java.awt.Component:
action() is deprecated.
java.awt.Component:
gotFocus() is deprecated.
java.awt.Component:
lostFocus() is deprecated.
java.awt.Component:
nextFocus() is deprecated.
java.awt.Container:
countComponents() is deprecated.
java.awt.Container:
insets() is deprecated.
java.awt.Container:
layout() is deprecated.
java.awt.Container:
preferredSize() is deprecated.
java.awt.Container:
minimumSize() is deprecated.
java.awt.Container:
deliverEvent() is deprecated.
java.awt.Container:
locate() is deprecated.
java.awt.FontMetrics:
getMaxDecent() is deprecated.
java.awt.Frame:
setCursor() is deprecated.
java.awt.Frame:
getCursorType() is deprecated.
java.awt.Graphics:
getClipRect() is deprecated.
java.awt.List:
countItems() is deprecated.
java.awt.List:
clear() is deprecated.
java.awt.List:
isSelected() is deprecated.
java.awt.List:
allowsMultipleSelections() is deprecated.
java.awt.List:
setMultipleSelections() is deprecated.
java.awt.List:
preferredSize() is deprecated.
java.awt.List:
preferredSize() is deprecated.
java.awt.List:
minimumSize() is deprecated.
java.awt.List:
minimumSize() is deprecated.
java.awt.List:
delItems() is deprecated.
java.awt.Menu:
countItems() is deprecated.
java.awt.MenuBar:
countMenus() is deprecated.
java.awt.MenuComponent:
getPeer() is deprecated.
java.awt.MenuComponent:
postEvent() is deprecated.
java.awt.MenuContainer:
postEvent() is deprecated.
java.awt.MenuItem:
enable() is deprecated.
java.awt.MenuItem:
enable() is deprecated.
java.awt.MenuItem:
disable() is deprecated.
java.awt.Polygon:
getBoundingBox() is deprecated.
java.awt.Polygon:
inside() is deprecated.
java.awt.Rectangle:
reshape() is deprecated.
java.awt.Rectangle:
move() is deprecated.
java.awt.Rectangle:
resize() is deprecated.
java.awt.Rectangle:
inside() is deprecated.
java.awt.ScrollPane:
layout() is deprecated.
java.awt.Scrollbar:
getVisible() is deprecated.
java.awt.Scrollbar:
setLineIncrement() is deprecated.
java.awt.Scrollbar:
getLineIncrement() is deprecated.
java.awt.Scrollbar:
setPageIncrement() is deprecated.
java.awt.Scrollbar:
getPageIncrement() is deprecated.
java.awt.TextArea:
insertText() is deprecated.
java.awt.TextArea:
appendText() is deprecated.
java.awt.TextArea:
replaceText() is deprecated.
java.awt.TextArea:
preferredSize() is deprecated.
java.awt.TextArea:
preferredSize() is deprecated.
java.awt.TextArea:
minimumSize() is deprecated.
java.awt.TextArea:
minimumSize() is deprecated.
java.awt.TextField:
setEchoCharacter() is deprecated.
java.awt.TextField:
preferredSize() is deprecated.
java.awt.TextField:
preferredSize() is deprecated.
java.awt.TextField:
minimumSize() is deprecated.
java.awt.TextField:
minimumSize() is deprecated.
java.awt.Window:
postEvent() is deprecated.
java.io.ByteArrayOutputStream:
toString() is deprecated.
java.io.DataInputStream:
readLine() is deprecated.
java.io.PrintStream:
PrintStream() is deprecated.
java.io.PrintStream:
PrintStream() is deprecated.
java.io.StreamTokenizer:
StreamTokenizer() is deprecated.
java.lang.Character:
isJavaLetter() is deprecated.
java.lang.Character:
isJavaLetterOrDigit() is deprecated.
java.lang.Character:
isSpace() is deprecated.
java.lang.ClassLoader:
defineClass() is deprecated.
java.lang.Runtime:
getLocalizedInputStream() is deprecated.
java.lang.Runtime:
getLocalizedOutputStream() is deprecated.
java.lang.String:
String() is deprecated.
java.lang.String:
String() is deprecated.
java.lang.String:
getBytes() is deprecated.
java.lang.System:
getenv() is deprecated.
java.net.Socket:
Socket() is deprecated.
java.net.Socket:
Socket() is deprecated.
java.util.Date:
Date() is deprecated.
java.util.Date:
Date() is deprecated.
java.util.Date:
Date() is deprecated.
java.util.Date:
Date() is deprecated.
java.util.Date:
UTC() is deprecated.
java.util.Date:
parse() is deprecated.
java.util.Date:
getYear() is deprecated.
java.util.Date:
setYear() is deprecated.
java.util.Date:
getMonth() is deprecated.
java.util.Date:
setMonth() is deprecated.
java.util.Date:
getDate() is deprecated.
java.util.Date:
setDate() is deprecated.
java.util.Date:
getDay() is deprecated.
java.util.Date:
getHours() is deprecated.
java.util.Date:
setHours() is deprecated.
java.util.Date:
getMinutes() is deprecated.
java.util.Date:
setMinutes() is deprecated.
java.util.Date:
getSeconds() is deprecated.
java.util.Date:
setSeconds() is deprecated.
java.util.Date:
toLocaleString() is deprecated.
java.util.Date:
toGMTString() is deprecated.
java.util.Date:
getTimezoneOffset() is deprecated.
可以证明Java代码是1.1版,但仅在某些情况下(如果代码使用新添加的1.1功能)。通常不可能证明Java代码是1.0,但是没有使用Java 1.1特性,并且大量使用Java不推荐使用的功能暗示了针对Java 1.0环境的类。
我不知道任何可能能够区分这两者的类内标记(行号表的差异等),主要是因为我没有必要在十六进制中挖掘1.0和1.1类编辑器。
答案 1 :(得分:2)
JVM specification与您将获得的权威一样具有权威性。 Chapter 4可能就是你所追求的。