• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key

image

Play button

image

Play button

image

Progress

1/5

Click to flip

5 Cards in this Set

  • Front
  • Back
What is the reflection API in Java?
Reflection is commonly used by programs which require the ability to examine or modify the run-time behavior of applications running in the Java virtual machine. You can examine the class structure of a given class at run-time, discover the class members and examine the class declaration information. This can be a powerful tool for debugging, diagnosis and reverse-engineering.
What are the drawbacks of using the reflection API?
1. Reflection involves types that are dynamically resolved. As a result, certain optimizations can not be performed by the JVM. This can result in slower execution.
Reflection can be used only when the caller has the right permissions.
Reflection can compromise the access rules of objects such as being able to access the private or protected members. This may result in unexpected behavior or it may render the code dysfunctional or platform specific.
How can you construct an object of a given class using reflection?
You can use the newInstance() method defined on the Class object. This will only work if the class has a public constructor without parameters. Otherwise you get an exception.
How can you get the class object from a class name?
Use the Class.forName(className) method. Fully qualified classname may be required if the class is not in the same package as the caller.
Using reflection, how can you tell if a member is public or private?
All the classes that implement the Member interface have a method called getModifiers(). This gives an integer value. There is a class called Modifier that exposes a number of static methods to interpret this integer. Here is an example:
Member mem;
//...
int mod = mem.getModifiers();
Modifier.isPrivate(mod);