为什么Java类文件格式的前四个字节是CAFEBABE?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2808646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why are the first four bytes of the Java class file format CAFEBABE?
提问by zengr
Why are the first four bytes of the Java class file format CAFEBABE? Who named it?
为什么 Java 类文件格式的前四个字节是CAFEBABE?谁命名的?
Your views/guesses?
你的看法/猜测?
Source: IBM Java Programing Dynamics
资料来源:IBM Java 编程动态
采纳答案by polygenelubricants
James Gosling, the father of Java programming language, once explained it as follows:
Java 编程语言之父 James Gosling 曾这样解释:
As far as I know, I'm the guilty party on this one. I was totally unaware of the NeXT connection. The small number of interesting HEX words is probably the source of the match. As for the derivation of the use of
CAFEBABE
in Java, it's somewhat circuitous:We used to go to lunch at a place called St Michael's Alley. According to local legend, in the deep dark past, the Grateful Dead used to perform there before they made it big. It was a pretty funky place that was definitely a Grateful Dead Kinda Place. When Jerry died, they even put up a little Buddhist-esque shrine. When we used to go there, we referred to the place as Cafe Dead.
Somewhere along the line it was noticed that this was a HEX number. I was re-vamping some file format code and needed a couple of magic numbers: one for the persistent object file, and one for classes. I used
CAFEDEAD
for the object file format, and in grepping for 4 character hex words that fit afterCAFE
(it seemed to be a good theme) I hit onBABE
and decided to use it.At that time, it didn't seem terribly important or destined to go anywhere but the trash-can of history. So
CAFEBABE
became the class file format, andCAFEDEAD
was the persistent object format. But the persistent object facility went away, and along with it went the use ofCAFEDEAD
- it was eventually replaced by RMI.
据我所知,我是这件事的罪魁祸首。我完全不知道 NeXT 连接。少数有趣的 HEX 单词可能是匹配的来源。至于
CAFEBABE
Java中使用的推导,有点绕:我们过去常去一个叫 St Michael's Alley 的地方吃午饭。据当地传说,在黑暗的过去,Grateful Dead 曾经在那里表演过,然后才壮大起来。这是一个非常时髦的地方,绝对是一个 Grateful Dead Kinda Place。杰瑞死后,他们甚至建立了一座佛教式的小神龛。我们过去常去那里时,我们称这个地方为死咖啡馆。
沿线的某个地方注意到这是一个十六进制数。我正在重新修改一些文件格式代码,需要几个幻数:一个用于持久对象文件,另一个用于类。我用于
CAFEDEAD
目标文件格式,并在搜索适合之后的 4 个字符的十六进制单词时CAFE
(这似乎是一个很好的主题),我BABE
决定使用它。在那个时候,它似乎并不重要,也没有注定的去处,除了历史的垃圾桶。于是
CAFEBABE
变成了类文件格式,成为了CAFEDEAD
持久对象格式。但是持久对象设施消失了,随之CAFEDEAD
而来的是使用- 它最终被 RMI 取代。