- Java class attribute name
- Field Summary
- Constructor Summary
- Method Summary
- Methods declared in class java.lang.Object
- Field Detail
- MANIFEST_VERSION
- SIGNATURE_VERSION
- CONTENT_TYPE
- CLASS_PATH
- MAIN_CLASS
- SEALED
- EXTENSION_LIST
- EXTENSION_NAME
- EXTENSION_INSTALLATION
- IMPLEMENTATION_TITLE
- IMPLEMENTATION_VERSION
- IMPLEMENTATION_VENDOR
- IMPLEMENTATION_VENDOR_ID
- IMPLEMENTATION_URL
- SPECIFICATION_TITLE
- SPECIFICATION_VERSION
- SPECIFICATION_VENDOR
- MULTI_RELEASE
- Constructor Detail
- Name
- Method Detail
- equals
- hashCode
- toString
- Java Class Attributes
- Example
- Accessing Attributes
- Example
- Modify Attributes
- Example
- Example
- Example
- Multiple Objects
- Example
- Multiple Attributes
- Example
- Class Attributes.Name
- Field Summary
- Constructor Summary
- Method Summary
- Methods declared in class java.lang.Object
- Field Details
- MANIFEST_VERSION
- SIGNATURE_VERSION
- CONTENT_TYPE
- CLASS_PATH
- MAIN_CLASS
- SEALED
- EXTENSION_LIST
- EXTENSION_NAME
- EXTENSION_INSTALLATION
- IMPLEMENTATION_TITLE
- IMPLEMENTATION_VERSION
- IMPLEMENTATION_VENDOR
- IMPLEMENTATION_VENDOR_ID
- IMPLEMENTATION_URL
- SPECIFICATION_TITLE
- SPECIFICATION_VERSION
- SPECIFICATION_VENDOR
- MULTI_RELEASE
- Constructor Details
- Name
- Method Details
- equals
- hashCode
- toString
- Java class attribute name
- Nested Class Summary
- Nested classes/interfaces inherited from interface java.util.Map
- Field Summary
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Methods inherited from interface java.util.Map
- Field Detail
- map
- Constructor Detail
- Attributes
- Attributes
- Attributes
- Method Detail
- get
- getValue
- getValue
- put
- putValue
- remove
- containsValue
- containsKey
- putAll
- clear
- size
- isEmpty
- keySet
- values
- entrySet
- equals
- hashCode
- clone
Java class attribute name
The Attributes.Name class represents an attribute name stored in this Map. Valid attribute names are case-insensitive, are restricted to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70 characters in length. Attribute values can contain any characters and will be UTF8-encoded when written to the output stream. See the JAR File Specification for more information about valid attribute names and values.
Field Summary
Name object for Extension-List manifest attribute used for the extension mechanism that is no longer supported.
Constructor Summary
Method Summary
Methods declared in class java.lang.Object
Field Detail
MANIFEST_VERSION
Name object for Manifest-Version manifest attribute. This attribute indicates the version number of the manifest standard to which a JAR file’s manifest conforms.
SIGNATURE_VERSION
CONTENT_TYPE
CLASS_PATH
MAIN_CLASS
Name object for Main-Class manifest attribute used for launching applications packaged in JAR files. The Main-Class attribute is used in conjunction with the -jar command-line option of the java application launcher.
SEALED
EXTENSION_LIST
Name object for Extension-List manifest attribute used for the extension mechanism that is no longer supported.
EXTENSION_NAME
Name object for Extension-Name manifest attribute. used for the extension mechanism that is no longer supported.
EXTENSION_INSTALLATION
@Deprecated public static final Attributes.Name EXTENSION_INSTALLATION
IMPLEMENTATION_TITLE
IMPLEMENTATION_VERSION
IMPLEMENTATION_VENDOR
IMPLEMENTATION_VENDOR_ID
@Deprecated public static final Attributes.Name IMPLEMENTATION_VENDOR_ID
IMPLEMENTATION_URL
@Deprecated public static final Attributes.Name IMPLEMENTATION_URL
SPECIFICATION_TITLE
SPECIFICATION_VERSION
SPECIFICATION_VENDOR
MULTI_RELEASE
Constructor Detail
Name
Method Detail
equals
hashCode
toString
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Java Class Attributes
In the previous chapter, we used the term «variable» for x in the example (as shown below). It is actually an attribute of the class. Or you could say that class attributes are variables within a class:
Example
Create a class called » Main » with two attributes: x and y :
Another term for class attributes is fields.
Accessing Attributes
You can access attributes by creating an object of the class, and by using the dot syntax ( . ):
The following example will create an object of the Main class, with the name myObj . We use the x attribute on the object to print its value:
Example
Create an object called » myObj » and print the value of x :
Modify Attributes
You can also modify attribute values:
Example
Or override existing values:
Example
Change the value of x to 25:
If you don’t want the ability to override existing values, declare the attribute as final :
Example
The final keyword is useful when you want a variable to always store the same value, like PI (3.14159. ).
The final keyword is called a «modifier». You will learn more about these in the Java Modifiers Chapter.
Multiple Objects
If you create multiple objects of one class, you can change the attribute values in one object, without affecting the attribute values in the other:
Example
Change the value of x to 25 in myObj2 , and leave x in myObj1 unchanged:
Multiple Attributes
You can specify as many attributes as you want:
Example
The next chapter will teach you how to create class methods and how to access them with objects.
Class Attributes.Name
The Attributes.Name class represents an attribute name stored in this Map. Valid attribute names are case-insensitive, are restricted to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70 characters in length. Attribute values can contain any characters and will be UTF8-encoded when written to the output stream. See the JAR File Specification for more information about valid attribute names and values.
Field Summary
Name object for Extension-List manifest attribute used for the extension mechanism that is no longer supported.
Name object for Extension-Name manifest attribute used for the extension mechanism that is no longer supported.
Constructor Summary
Method Summary
Methods declared in class java.lang.Object
Field Details
MANIFEST_VERSION
Name object for Manifest-Version manifest attribute. This attribute indicates the version number of the manifest standard to which a JAR file’s manifest conforms.
SIGNATURE_VERSION
CONTENT_TYPE
CLASS_PATH
MAIN_CLASS
Name object for Main-Class manifest attribute used for launching applications packaged in JAR files. The Main-Class attribute is used in conjunction with the -jar command-line option of the java application launcher.
SEALED
EXTENSION_LIST
Name object for Extension-List manifest attribute used for the extension mechanism that is no longer supported.
EXTENSION_NAME
Name object for Extension-Name manifest attribute used for the extension mechanism that is no longer supported.
EXTENSION_INSTALLATION
IMPLEMENTATION_TITLE
IMPLEMENTATION_VERSION
IMPLEMENTATION_VENDOR
IMPLEMENTATION_VENDOR_ID
IMPLEMENTATION_URL
SPECIFICATION_TITLE
SPECIFICATION_VERSION
SPECIFICATION_VENDOR
MULTI_RELEASE
Constructor Details
Name
Method Details
equals
hashCode
toString
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Java class attribute name
The Attributes class maps Manifest attribute names to associated string values. Valid attribute names are case-insensitive, are restricted to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70 characters in length. Attribute values can contain any characters and will be UTF8-encoded when written to the output stream. See the JAR File Specification for more information about valid attribute names and values.
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Map
Field Summary
Constructor Summary
Constructs a new Attributes object with the same attribute name-value mappings as in the specified Attributes.
Method Summary
Returns the value of the specified attribute name, specified as a string, or null if the attribute was not found.
Methods inherited from class java.lang.Object
Methods inherited from interface java.util.Map
Field Detail
map
Constructor Detail
Attributes
Attributes
public Attributes(int size)
Attributes
Constructs a new Attributes object with the same attribute name-value mappings as in the specified Attributes.
Method Detail
get
getValue
Returns the value of the specified attribute name, specified as a string, or null if the attribute was not found. The attribute name is case-insensitive. This method is defined as:
return (String)get(new Attributes.Name((String)name));
getValue
public String getValue(Attributes.Name name)
Returns the value of the specified Attributes.Name, or null if the attribute was not found. This method is defined as:
put
public Object put(Object name, Object value)
Associates the specified value with the specified attribute name (key) in this Map. If the Map previously contained a mapping for the attribute name, the old value is replaced.
putValue
public String putValue(String name, String value)
Associates the specified value with the specified attribute name, specified as a String. The attributes name is case-insensitive. If the Map previously contained a mapping for the attribute name, the old value is replaced. This method is defined as:
return (String)put(new Attributes.Name(name), value);
remove
Removes the attribute with the specified name (key) from this Map. Returns the previous attribute value, or null if none.
containsValue
containsKey
putAll
Copies all of the attribute name-value mappings from the specified Attributes to this Map. Duplicate mappings will be replaced.
clear
size
isEmpty
keySet
values
entrySet
public SetMap.EntryObject,Object>> entrySet()
equals
Compares the specified Attributes object with this Map for equality. Returns true if the given object is also an instance of Attributes and the two Attributes objects represent the same mappings.
hashCode
clone
Since the attribute names and values are themselves immutable, the Attributes returned can be safely modified without affecting the original.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.