Reputation: 11
I like to know "how to find class name from a .class file". I hope you will explain this as clearly as possible,because I know only basics about java.
Upvotes: 1
Views: 189
Reputation: 10891
A java class file is a data structure that follows the specified format.
ClassFile { u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[constant_pool_count-1]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[interfaces_count]; u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; }
Constant pool data entries follow the following general specified format where tag determines the length of info.
cp_info {
u1 tag;
u1 info[];
}
except if tag=CONSTANT_Utf8 then the following specified format is followed.
CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes[length];
}
.This will probably be related to the name of the file.
Upvotes: 3
Reputation: 3793
The class name is usually, but not always, the name of the file. Try using the following command:
javap -public -classpath . FileName
Where "filename" does not include the ".class" suffix.
javap is the Java class file disassembler, and the -public switch will show you the public classes and members. In Java, the classpath is the directory or directories which the Java runtime will look in for class files. Substitute the "." for the directory of the file you're interested in if it's not in your current directory.
Upvotes: 1
Reputation: 282
Usually the class name is what precedes the .class, so ClassName.class is the convention.
Upvotes: 0