What is the Attribute.getName method in Java?
The Attribute class denotes an MBean attribute. The MBean server and other objects use this class to get and set attributes values.
The Attribute class is present in the javax.management.Attribute package.
What is the getName method of the Attribute class?
The getName method can be used to get the name of the attribute object.
Syntax
public String getName()
Arguments
This method doesn’t take an argument.
Returns
This method returns a string representing the key of the Attribute object.
Code
The code below shows how to use the getName method.
import javax.management.Attribute;class AttributeGetNameExample {public static void main( String args[] ) {Attribute attr = new Attribute("Website_Name", "Educative");System.out.println( "Attribute name is: " + attr.getName());}}
Explanation
In the code above:
- Line 1: We imported the
Attributeclass.
import javax.management.Attribute
- Line 4: We created an
Attributeobject with the nameattr. For this object, we set the attribute name asWebsite_Nameand the attribute value asEducative.
Attribute attr = new Attribute("Website_Name", "Educative");
- Line 5: We called the
getNamemethod on theattrobject and printed the value returned.
attr.getName(); //Website_Name