Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Develop a class layout tool like the Java's built-in executable file javap to show the skeleton of a class file. The tool can display

image text in transcribed

2. Develop a class layout tool like the Java's built-in executable file javap" to show the skeleton of a class file. The tool can display the fields, methods, exceptions and constructors of a given .class file without source code. The following gives an example. After compiling the following NewClass.java file on the left, the byte code NewClass.class is rendered. Your developed tool can accept NewClass.class as input to show the skeleton on the right. Feel free to run javap ClassName to verify accuracy. Ensure other class files can be processed without an error too. Note that constructors and methods that throw exceptions should also be displayed. This tool will be the building block for the next tool that you are going to build. (6 pts) // This is the original.java code. // This is the skeleton. public class NewClass { public class NewClass { int w, h. d; int w; public static void main(String[] args) { int h; } int d; public void ml(int i, int j, int k){ public NewClass: } public static void main(java.lang. String[] sa): public int m2(int i) { public void ml(int il, int i2, int i3); return 0; public int m2(int i); } protected java.lang. Integer m3 (double d): protected Integer m3(double d){ } return null; } } Hint: run the following sample code to get an idea about how to access information from a Class object. Note that Lab7 Rectangle will load in the Rectangle.class not the Rectangle.java file. package Lab7; package Lab7; public class Rectangle { import java.lang.reflect.Constructor; int w, h; public class MyProg { public Rectangle({ } public static void main(String[] args) throws public Rectangle(int w, int h){ ClassNotFoundException this.w=w; Class c = Class.forName("Lab7.Rectangle"); this.h=h; Constructor[] ca=c.getConstructors: } for(Constructor cons: ca){ public int getArea(){ System.out.println(cons); return w*h; } } } } 2. Develop a class layout tool like the Java's built-in executable file javap" to show the skeleton of a class file. The tool can display the fields, methods, exceptions and constructors of a given .class file without source code. The following gives an example. After compiling the following NewClass.java file on the left, the byte code NewClass.class is rendered. Your developed tool can accept NewClass.class as input to show the skeleton on the right. Feel free to run javap ClassName to verify accuracy. Ensure other class files can be processed without an error too. Note that constructors and methods that throw exceptions should also be displayed. This tool will be the building block for the next tool that you are going to build. (6 pts) // This is the original.java code. // This is the skeleton. public class NewClass { public class NewClass { int w, h. d; int w; public static void main(String[] args) { int h; } int d; public void ml(int i, int j, int k){ public NewClass: } public static void main(java.lang. String[] sa): public int m2(int i) { public void ml(int il, int i2, int i3); return 0; public int m2(int i); } protected java.lang. Integer m3 (double d): protected Integer m3(double d){ } return null; } } Hint: run the following sample code to get an idea about how to access information from a Class object. Note that Lab7 Rectangle will load in the Rectangle.class not the Rectangle.java file. package Lab7; package Lab7; public class Rectangle { import java.lang.reflect.Constructor; int w, h; public class MyProg { public Rectangle({ } public static void main(String[] args) throws public Rectangle(int w, int h){ ClassNotFoundException this.w=w; Class c = Class.forName("Lab7.Rectangle"); this.h=h; Constructor[] ca=c.getConstructors: } for(Constructor cons: ca){ public int getArea(){ System.out.println(cons); return w*h; } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions