Java Program to Implement Attribute API
Valid attribute names are case-insensitive, and they are restricted to the ASCII characters in the set of [0-9,a-z, A-Z_-], and cannot be exceeded over 70 characters in length. The attribute’s value can contain any characters and will be encoded in UTF-8 when written to the output stream in any program. This is the source code of the Java program to Implement Attributes API. The program is successfully run and the output of the program is also shown below:
- Setting attributes
- Creating an object of class in main() method and name it as ‘attribute’.
- Assigning attributes.
- Stores the value Value associated with key name in this Attribute using putValue() method.
- Returns a Set containing all the keys found in this Attributes using keySet() method.
- Iterator to traverse over collection interface of the object type.
- Checking condition using hasNext() method which holds true till there is a single element left in order to print the elements.
- Clearing all attribute objects from the collection using clear() method.
- Lastly, printing the display message whether the attribute is empty or not.
the key set of the Attributes is CLASS_PATH CONTENT_TYPE MANIFEST_VERSION MAIN_CLASS the values of the Attributes is root/sub_dir/class_path UTF-8 2 TESTMAIN.java the entry set of the Attributes is CLASS_PATH=root/sub_dir/class_path CONTENT_TYPE=UTF-8 MANIFEST_VERSION=2 MAIN_CLASS=TESTMAIN.java the Attributes contains Key CLASS_PATH:true the Attributes contains Value TESTMAIN.java :true the size of the Attributes is 4 the Attributes is empty