80 likes | 91 Views
Review key JVM topics, solve loaded type instances, explore object types and methods, prompt user input for class/interface names, and list classes from a given name to Object class.
E N D
Problem Solving #4: JVM ICS201-081
Outline • Review of Key Topics • Problem 1 • Problem 2 • Problem 3 • Problem 4
Review of Main Topics • JVM • Reflection • At runtime, the Java programmers can inspect various information including • name of the class of a given object • name of the superclass of that class • names of interfaces that class • methods that belong to that class • etc
Problem 1 • Write a program to show that each loaded type has only one instance of java.lang.Class associated with it, irrespective of how many times it is used in a class. Solution: Show Source Code Then run it in JCreator to check the output
Problem 2 • Write a program to create an object of type String. Then print out the type of this object, its superclass, its package, all constructors, all methods, and all fields defined in this type. Solution: Show Source Code Then run it in JCreator to check the output
Problem 3 • Modify the solution for problem 2 to prompt the user to type a class or an interface full name then print out whether the entered name is a class or interface, • All other information as in problem 2 Solution: Show Source Code Then run it in JCreator to check the output
Problem 4 • Modify the solution for problem 3 to print out all the classes on the path starting from the entered class name till the Object class in addition to all as in problem 2