30

How do I view the contents of a .class file (java byte code)?

How do I open these type of files in Linux? I'm using Centos 5.8.

2
  • 1
    If you just want to view the binary or hex dump, you can use od
    – jpm
    Commented Jan 3, 2013 at 20:36
  • just want to see the code in the .class file.
    – karunakar
    Commented Jan 3, 2013 at 21:49

6 Answers 6

56

javap -c X will show the disassembly of X.class.

2
  • 1
    using javap X -c worked ! Thanks.
    – karunakar
    Commented Jan 3, 2013 at 23:36
  • I've been looking for something like this. Thanks! Commented Apr 18, 2019 at 10:59
13

Read bytecode

javap -v com.company.package.MainClass

To understand bytecode You can use this list of mnemonics

1
  • +1 for the link to the online decompiler! Commented Jan 3, 2013 at 22:24
2

You could decompile it.

To see Java source code check some decompiler. Go search for jad.

If you want to see bytecodes, just use javap which comes with the JDK.

1

use javap. it's a part of the standard jdk.

0

less filename.class

Not sure how it will help you, unless you can read byte code...

3
  • 1
    Geeee, I wanted to write that! But I think this would rather fit as a comment...
    – ppeterka
    Commented Jan 3, 2013 at 20:35
  • 1
    +1 for 'unless you can read byte code'
    – home
    Commented Jan 3, 2013 at 20:35
  • 6
    Chuck Norris can read byte code. He can sing it too!
    – ppeterka
    Commented Jan 3, 2013 at 20:36
0

Any binary file editor will do - gHex or xxd are two recommendations.

Note, this won't really help you unless you can understand the bytecode given to you by the .class file...

Not the answer you're looking for? Browse other questions tagged or ask your own question.