Tool to check package name and class name of the class within a .class file

江枫思渺然 提交于 2019-12-07 22:42:26

Is the class contained in the .class file always the same as the file name (excluding .class)

In practice, yes. Every Java implementation I've come across relies on class file pathnames to locate classes to be loaded, etc.

In theory, a classloader could use some other mechanism, and therefore could store classes in files that bear no relation to the class names. However, I see no advantage in doing that.

even if I use some other language such as Groovy, Jython or Scala?

Given that these languages compile to bytecode files that are then loaded by standard class loaders, then it is pretty much a given that the class names in the bytecode files correspond to the file pathnames ... otherwise the class loaders wouldn't be able to locate the class files. However, this does not necessarily mean that the class names in the bytecode files are identical to Scala / Jython / Groovy the identifiers used in the source code. Indeed, this isn't even true for Java; e.g. the classfile names for anonymous and inner classes for not the same as the identifiers in the Java source code.

Colin Hebert

Call javap ClassName (not javap ClassName.class).

If your .class just to javap ClassName
If your .class is in a subfolder javap path/to/ClassName or javap path.to.ClassName


Resources :

Try this Java Decompiler. Should give you the information you want.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!