Cafe Babe

Posted by Kanon on December 1, 2017

今天查看编译Java程序生成的.class字节码文件的时候,无意中发现潜藏在一连串数字里的小秘密,如下:




每一个字节码文件的前四个字节都是cafe babe。

第一时间浮现脑海的是————咖啡宝贝????黑人问号。于是便立即google了下,跳出了这么一串解释

“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 after “CAFE” (it seemed to be a good theme) I hit on BABE 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, and CAFEDEAD was the persistent object format. But the persistent object facility went away, and along with it went the use of CAFEDEAD - it was eventually replaced by RMI.”


以上文字出自Java之父James Gosling的原话,大意是与之前很喜欢去的一家饭店有关,这家饭店在旧时候一个叫Grateful Dead的乐队经常在这里表演,算是时髦人的聚集地。后来乐队的主唱死了,人们就在饭店前立了一个佛龛。渐渐的,每当谈及这家饭店时,James都称之为CAFEDEAD。再再后来,某天在修改设计文件的格式时,脑回路清奇,大腿一拍,就将这8个字母用在了对象文件格式里(对象文件格式???什么鬼)。而CAFEBABE则是另外想出的一个名字,就用在了字节码文件里。那为啥用babe,babe是很口语化的词,用来指代beloved people,那么我就不负责任地猜测cafebabe可能是与在饭馆里邂逅的某段爱情有关,哈哈哈手动滑稽脸。