package com.zwx.jvm; public class JVMDemo { public static void main(String[] args) { int sum = add(1, 2); print(sum); } public static int add(int a, int b) { a = 3; int result = a b; return result; } public static void print(int num) { System.out.println(num); } }
javap -c xxx\xxx\JVMDemo.class >1.txt
Compiled from "JVMDemo.java" public class com.zwx.jvm.JVMDemo { public com.zwx.jvm.JVMDemo(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: iconst_1 1: iconst_2 2: invokestatic #2 // Method add:(II)I 5: istore_1 6: iload_1 7: invokestatic #3 // Method print:(I)V 10: return public static int add(int, int); Code: 0: iconst_3 1: istore_0 2: iload_0 3: iload_1 4: iadd 5: istore_2 6: iload_2 7: ireturn public static void print(int); Code: 0: getstatic #4 // Field java/lang/System.out:Ljava/io/PrintStream; 3: iload_0 4: invokevirtual #5 // Method java/io/PrintStream.println:(I)V 7: return }
package com.zwx.jvm.overload; public class OverloadDemo { static class Human { } static class Man extends Human { } static class WoMan extends Human { } public void hello(Human human) { System.out.println("Hi,Human"); } public void hello(Man man) { System.out.println("Hi,Man"); } public void hello(WoMan woMan) { System.out.println("Hi,Women"); } public static void main(String[] args) { OverloadDemo overloadDemo = new OverloadDemo(); Human man = new Man(); Human woman = new WoMan(); overloadDemo.hello(man); overloadDemo.hello(woman); } }
Hi,Human Hi,Human
overloadDemo.hello(man);
Human man = new Man();
package com.zwx.jvm.overload; import java.io.Serializable; public class OverloadDemo2 { public static void hello(Object a){ System.out.println("Hello,Object"); } public static void hello(double a){ System.out.println("Hello,double"); } public static void hello(Double a){ System.out.println("Hello,Double"); } public static void hello(float a){ System.out.println("Hello,float"); } public static void hello(long a){ System.out.println("Hello,long"); } public static void hello(int a){ System.out.println("Hello,int"); } public static void hello(Character a){ System.out.println("Hello,Character"); } public static void hello(char a){ System.out.println("Hello,char"); } public static void hello(char ...a){ System.out.println("Hello,chars"); } public static void hello(Serializable a){ System.out.println("Hello,Serializable"); } public static void main(String[] args) { OverloadDemo2.hello('1'); } }
Hello,char
Hello,int
char->int->long->float->double->Character->Serializable->Object->chars
package com.zwx.jvm.override; public class OverrideDemo { static class Human { public void hello(Human human) { System.out.println("Hi,Human"); } } static class Man extends Human { @Override public void hello(Human human) { System.out.println("Hi,Man"); } } static class WoMan extends Human { @Override public void hello(Human human) { System.out.println("Hi,Women"); } } public static void main(String[] args) { Human man = new Man(); Human woman = new WoMan(); man.hello(man); man.hello(woman); woman.hello(woman); woman.hello(man); } }
Hi,Man Hi,Man Hi,Women Hi,Women
Compiled from "OverrideDemo.java" public class com.zwx.jvm.override.OverrideDemo { public com.zwx.jvm.override.OverrideDemo(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: new #2 // class com/zwx/jvm/override/OverrideDemo$Man 3: dup 4: invokespecial #3 // Method com/zwx/jvm/override/OverrideDemo$Man."<init>":()V 7: astore_1 8: new #4 // class com/zwx/jvm/override/OverrideDemo$WoMan 11: dup 12: invokespecial #5 // Method com/zwx/jvm/override/OverrideDemo$WoMan."<init>":()V 15: astore_2 16: aload_1 17: aload_1 18: invokevirtual #6 // Method com/zwx/jvm/override/OverrideDemo$Human.hello:(Lcom/zwx/jvm/override/OverrideDemo$Human;)V 21: aload_1 22: aload_2 23: invokevirtual #6 // Method com/zwx/jvm/override/OverrideDemo$Human.hello:(Lcom/zwx/jvm/override/OverrideDemo$Human;)V 26: aload_2 27: aload_2 28: invokevirtual #6 // Method com/zwx/jvm/override/OverrideDemo$Human.hello:(Lcom/zwx/jvm/override/OverrideDemo$Human;)V 31: aload_2 32: aload_1 33: invokevirtual #6 // Method com/zwx/jvm/override/OverrideDemo$Human.hello:(Lcom/zwx/jvm/override/OverrideDemo$Human;)V 36: return }