Skip to content

Instantly share code, notes, and snippets.

@rahulmutt
Created December 14, 2016 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulmutt/b54412607904601e2412f9f9b89fd163 to your computer and use it in GitHub Desktop.
Save rahulmutt/b54412607904601e2412f9f9b89fd163 to your computer and use it in GitHub Desktop.
JVM Class Naming

The file 2.jar contains a file 2.class that was generated manually (without javac). You can download it here.

Running java -jar 2.jar works perfectly and should output

Hello World!

Here is the output of running javap -c -v 2.class:

Classfile 2.class
  Last modified 14 Dec, 2016; size 314 bytes
  MD5 checksum 58880f3fe46c502feb88e671fe54498c
public class 2
  minor version: 0
  major version: 51
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Class              #2             // "2"
   #2 = Utf8               2
   #3 = Class              #4             // java/lang/Object
   #4 = Utf8               java/lang/Object
   #5 = Utf8               main
   #6 = Utf8               ([Ljava/lang/String;)V
   #7 = Fieldref           #8.#10         // java/lang/System.out:Ljava/io/PrintStream;
   #8 = Class              #9             // java/lang/System
   #9 = Utf8               java/lang/System
  #10 = NameAndType        #11:#12        // out:Ljava/io/PrintStream;
  #11 = Utf8               out
  #12 = Utf8               Ljava/io/PrintStream;
  #13 = Class              #14            // java/io/PrintStream
  #14 = Utf8               java/io/PrintStream
  #15 = String             #16            // Hello World!
  #16 = Utf8               Hello World!
  #17 = Methodref          #13.#18        // java/io/PrintStream.println:(Ljava/lang/String;)V
  #18 = NameAndType        #19:#20        // println:(Ljava/lang/String;)V
  #19 = Utf8               println
  #20 = Utf8               (Ljava/lang/String;)V
  #21 = Class              #22            // java/lang/String
  #22 = Utf8               java/lang/String
  #23 = Utf8               Code
  #24 = Utf8               StackMapTable
{
  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=1, args_size=1
         0: getstatic     #7                  // Field java/lang/System.out:Ljava/io/PrintStream;
         3: ldc           #15                 // String Hello World!
         5: invokevirtual #17                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
         8: return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment