Apache BCEL provides encapsulations of .class file parsing, which provides a set of API. Almost for every element in .class file, there's a corresponding Class in BECL API to represent it. So in some way, it is not that straightforward if you just want to print out certain sections of the class file. Here is a simple example you can refer, pay attention to the org.apache.bcel.classfile.ClassParser
:
ClassParser cp = new ClassParser("TestClass.class");
JavaClass jc = cp.parse();
ConstantPool constantPool = jc.getConstantPool(); // Get the constant pool here.
for (Constant c : constantPool.getConstantPool()) {
System.out.println(c); // Do what you need to do with all the constants.
}