为什么我们在.class文件的开头需要一个幻数? [英] Why do we need a magic number in the beginning of the .class file?

查看:188
本文介绍了为什么我们在.class文件的开头需要一个幻数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读了几篇关于每个java .class 文件开头的幻数 0xCAFEBABE 的帖子,想知道为什么需要 - 这个标记的目的是什么?

它还需要它吗?或者它现在只是为了向后兼容?

I read a few posts here about the magic number 0xCAFEBABE in the beginning of each java .class file and wanted to know why it is needed - what is the purpose of this marking?
Is it still needed anymore? or is it just for backwards compatibility now?

找不到答案的帖子 - 我也没有在java中看到答案 spec

Couldn't find a post that answers this - nor did I see the answer in the java spec

推荐答案

幻数基本上是文件格式的标识符。例如,JPEG始终以FFD8开头。 Java本身没有必要,它只是帮助识别文件类型。您可以在此处了解有关幻数的更多信息。

The magic number is basically an identifier for a file format. A JPEG for example always starts with FFD8. It is not necessary for Java itself, it simply helps to identify the file-type. You can read more about magic numbers here.

这篇关于为什么我们在.class文件的开头需要一个幻数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆