What is the Attribute.getValue method in Java?

The Attribute class denotes an MBean attribute. The MBean server and other objects use this class to get and set the values of attributes. The Attribute class is present in the javax.management.Attribute package.

The getValue method can be used to get the value of the attribute object.

Syntax

public Object getValue()

This method doesn’t take any parameters.

The getValue method returns the value of the Arrtribute object.

Code

The code below demonstrates how to use the getValue method.

import javax.management.Attribute;
class AttributeGetValueExample {
public static void main( String args[] ) {
Attribute attr = new Attribute("Website_Name", "Educative");
System.out.println( "Attribute value is: " + attr.getValue());
}
}

Explanation

In the code above:

  • In line 1, we import the Attribute class.

  • In line 4, we create an Attribute object with the name attr. For this object, we set the attribute name as Website_Name and the attribute value as Educative.

  • In line 5, we call the getValue method on the attr object and print the returned value.

New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources