Getting the Name of a Member Object - Java JNDI

Java examples for JNDI:Name

Description

Getting the Name of a Member Object

Demo Code

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Main {
  public static void main(String[] args) {
    Class cls = java.lang.String.class;
    Method method = cls.getMethods()[0];
    Field field = cls.getFields()[0];
    Constructor constructor = cls.getConstructors()[0];
    String name;/*from  ww w  . j ava 2 s  . c o m*/

    // Fully-qualified names
    name = cls.getName(); // java.lang.String
    name = cls.getName() + "." + field.getName(); // java.lang.String.CASE_INSENSITIVE_ORDER
    name = constructor.getName(); // java.lang.String
    name = cls.getName() + "." + method.getName(); // java.lang.String.hashCode

    // Unqualified names
    name = cls.getName().substring(cls.getPackage().getName().length() + 1); // String
    name = field.getName(); // CASE_INSENSITIVE_ORDER
    name = constructor.getName().substring(
        cls.getPackage().getName().length() + 1); // String
    name = method.getName(); // hashCode
  }
}

Related Tutorials