Java Program learning about javap Part 2- IProgramX

Q. Compile sample program 2. Type the following command and view the bytecodes. javap -c MyClass.


Note: We haven't used the program mentioned in the question.

Program:

class MyClass {  
  MyClass();  
  public static void main(java.lang.String[]);  



Command:

javap -c MyClass

Output:

class MyClass {  
  MyClass();  
    Code:  
       0: aload_0         
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V  
       4: return          
  
  public static void main(java.lang.String[]);  
    Code:  
       0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;  
       3: ldc           #3                  // String hello java  
       5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V  
       8: return          

}  

Post a Comment

2 Comments

  1. Slip5_1: Write a program for multilevel inheritance such that Country is inherited from
    Continent.State is inherited from Country. Display the place, State, Country and Continent.
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
    import java.io.IOException;
    class Continent{
    String con;
    InputStreamReader i = new InputStreamReader(System.in);
    BufferedReader r = new BufferedReader(i);
    void con_input() throws IOException
    {
    System.out.println("Enter the continent name:");
    con = r.readLine();
    }
    }
    class Country extends Continent
    {
    String cou;
    void cou_input()throws IOException
    {
    System.out.println("Enter the country name:");
    cou = r.readLine();}
    }
    class State extends Country
    {
    String sta;
    void sta_input()throws IOException
    {
    System.out.println("Enter the state name:");
    sta = r.readLine();}
    }
    class Main extends State
    {
    String pla;
    void pla_input()throws IOException
    {
    System.out.println("Enter the place name:");
    pla = r.readLine();}
    public static void main(String args[])throws IOException
    {
    Main s = new Main();
    s.con_input();
    s.cou_input();
    s.sta_input();
    s.pla_input();
    System.out.println("place is:"+s.pla);
    System.out.println("state is:"+s.sta);
    System.out.println("country is:"+s.cou);
    System.out.println("continent is:"+s.con);
    }
    }

    ReplyDelete