|
Generated by JDiff |
||||||||
PREV PACKAGE NEXT PACKAGE FRAMES NO FRAMES |
This file contains all the changes in documentation in the packagejava.lang
as colored differences. Deletions are shownlike this, and additions are shown like this.
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The new HTML tags are shown in the differences. If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. Similarly, documentation which was inherited from another class or interface is not shown here.
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a <code> tag will cause all subsequent paragraphs to be displayed differently.
Thrown when an application tries to call an abstract method. Normally this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled. @author unascribed @version 1.13 0915 02/2102/9800 @since JDK1.0
Thrown when an exceptional arithmetic condition has occurred. For example an integer "divide by zero" throws an instance of this class. @author unascribed @version 1.17 0919 02/2102/9800 @since JDK1.0
Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array. @author unascribed @version 1.16 0918 02/2102/9800 @since JDK1.0
Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. For example the following code generates anArrayStoreException
:@author unascribed @version 1.Object x[] = new String[3]; x[0] = new Integer(0);6 098 02/2102/9800 @since JDK1.0
The Boolean class wraps a value of the primitive typeClass Boolean, boolean getBoolean(String)boolean
in an object. An object of typeBoolean
contains a single field whose type isboolean
.In addition this class provides many methods for converting a
boolean
to aString
and aString
to aboolean
as well as other constants and methods useful when dealing with aboolean
. @author Arthur van Hoff @version 1.29 0738 02/2302/9800 @since JDK1.0
ReturnsClass Boolean, Boolean valueOf(String)true
if and only if the system property named by the argument exists and is equal to the string"true"
. (Beginning with version 1.0.2 of the JavaTM platform the test of this string is case insensitive.) A system property is accessible throughgetProperty
a method defined by theSystem
class.If there is no property with the specified name or if the specified name is empty or null then
false
is returned. @param name the system property name. @return theboolean
value of the system property. @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String)
ReturnstheaBoolean
withbooleana value represented by the specified String.A newTheBoolean
object is constructed. This Booleanreturned represents the valuetrue
if the string argument is notnull
and is equal ignoring case to the string"true"
.Example: Boolean.valueOf("True") returns true.
Example: Boolean.valueOf("yes") returns false. @param s a string. @return theBoolean
value represented by the string.
The Byte class is the standard wrapper for byte values. @author Nakul Saraiya @version 1.Class Byte, int compareTo(Byte)13 0920 02/2102/9800 @see java.lang.Number @since JDK1.1
Compares two Bytes numerically. @param anotherByte theClass Byte, int compareTo(Object)Byte
to be compared. @return the value0
if the argument Byte is equal to this Byte; a value less than0
if this Byte is numerically less than the Byte argument; and a value greater than0
if this Byte is numerically greater than the Byte argument (signed comparison). @sinceJDK11.2
Compares this Byte to another Object. If the Object is a Byte this function behaves likeClass Byte, Byte decode(String)compareTo(Byte)
. Otherwise it throws aClassCastException
(as Bytes are comparable only to other Bytes). @param o theObject
to be compared. @return the value0
if the argument is a Byte numerically equal to this Byte; a value less than0
if the argument is a Byte numerically greater than this Byte; and a value greater than0
if the argument is a Byte numerically less than this Byte. @exceptionClassCastException
if the argument is not aByte
. @see java.lang.Comparable @sinceJDK11.2
Decodes aClass Byte, byte parseByte(String)String
into aByte
.The String may representAccepts decimal hexadecimal and octal numbers in the following formats:[-] decimal constant [-] 0x hex constant [-] # hex constant [-] 0 octal constantThe constant following an (optional) negative sign and/or "radix specifier" is parsed as by theByte.parseByte
method with the specified radix (10 8 or 16). This constant must be positive or a NumberFormatException will result. The result is made negative if first character of the specifiedString
is the negative sign. No whitespace characters are permitted in theString
. @param nm thestringString
to decode. @return theByte
represented by the specified string. @exception NumberFormatException if theString
does not contain a parsable byte. @see java.lang.Byte#parseByte(String int)
Assuming the specified String represents a byte returns that byte's value. Throws an exception if the String cannot be parsed as a byte. The radix is assumed to be 10. @param s the String containing the byte @return the parsed value of the byte @exception NumberFormatException If the string does not contain a parsable byte.Class Byte, byte parseByte(String, int)
Assuming the specified String represents a byte returns that byte's value. Throws an exception if the String cannot be parsed as a byte. @param s the String containing the byte @param radix the radix to be used @return the parsed value of the byte @exception NumberFormatException If the String does not contain a parsable byte.Class Byte, String toString(byte)
Returns a new String object representing the specified Byte. The radix is assumed to be 10. @param b the byte to be converted @return the string representation of the specified byte
Class Byte, Byte valueOf(String)Assuming the specified String represents a byte returns a new Byte object initialized to that value. Throws an exception if the String cannot be parsed as a byte. The radix is assumed to be 10. @param s the String containing the integer @return theClass Byte, Byte valueOf(String, int)Byte
instance representing the parsedbyte
value @exception NumberFormatException If the String does not contain a parsable byte.
Assuming the specified String represents a byte returns a new Byte object initialized to that value. Throws an exception if the String cannot be parsed as a byte. @param s the String containing the integer @param radix the radix to be used @return theByte
instance representing the parsedbyte
value @exception NumberFormatException If the String does not contain a parsable byte.
The Character class wraps a value of the primitive typechar
in an object. An object of typeCharacter
contains a single field whose type ischar
.In addition this class provides several methods for determining the type of a character and converting characters from uppercase to lowercase and vice versa.
Many of the methods of class
Character
are defined in terms of a "Unicode attribute table" that specifies a name for every defined Unicode code point. The table also includes other attributes such as a decimal value an uppercase equivalent a lowercase equivalent and/or a titlecase equivalent. The character attribute tables for specific versions of Unicode are available on the World Wide Web in various subdirectories of:ftp://ftp.unicode.org/Public/For a more detailed specification of the
Character
class one that encompasses the exact behavior of methods such asisDigit
isLetter
isLowerCase
andisUpperCase
over the full range of Unicode values see Gosling Joy and Steele The Java Language Specification. @author Lee Boynton @author Guy Steele @author Akira Tanaka @version 1.55 9861 02/0902/1600 @since JDK1.0
Instances of this class represent particular subsets of the Unicode character set. The only family of subsets defined in theCharacter
class is{@link Character.UnicodeBlock UnicodeBlock}
. Other portions of the Java API may define other subsets for their own purposes. @sinceJDK11.2
A family of character subsets representing the character blocks defined by the Unicode 2.0 specification. Any given character is contained by at most one Unicode block. @sinceJDK11.2
Compares two Characters numerically. @param anotherCharacter theClass Character, int compareTo(Object)Character
to be compared. @return the value0
if the argument Character is equal to this Character; a value less than0
if this Character is numerically less than the Character argument; and a value greater than0
if this Character is numerically greater than the Character argument (unsigned comparison). Note that this is strictly a numerical comparison; it is not locale-dependent. @sinceJDK11.2
Compares this Character to another Object. If the Object is a Character this function behaves likeClass Character, byte COMBINING_SPACING_MARKcompareTo(Character)
. Otherwise it throws aClassCastException
(as Characters are comparable only to other Characters). @param o theObject
to be compared. @return the value0
if the argument is a Character numerically equal to this Character; a value less than0
if the argument is a Character numerically greater than this Character; and a value greater than0
if the argument is a Character numerically less than this Character. @exceptionClassCastException
if the argument is not aCharacter
. @see java.lang.Comparable @sinceJDK11.2
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte CONNECTOR_PUNCTUATION
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte CONTROL
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte CURRENCY_SYMBOL
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte DASH_PUNCTUATION
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte DECIMAL_DIGIT_NUMBER
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte ENCLOSING_MARK
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte END_PUNCTUATION
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte FORMAT
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte LETTER_NUMBER
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte LINE_SEPARATOR
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte LOWERCASE_LETTER
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte MATH_SYMBOL
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte MODIFIER_LETTER
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte MODIFIER_SYMBOL
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte NON_SPACING_MARK
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte OTHER_LETTER
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte OTHER_NUMBER
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte OTHER_PUNCTUATION
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte OTHER_SYMBOL
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte PARAGRAPH_SEPARATOR
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte PRIVATE_USE
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte SPACE_SEPARATOR
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte START_PUNCTUATION
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte SURROGATE
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte TITLECASE_LETTER
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte UNASSIGNED
Public data for enumerated Unicode general category types. @since JDK1.1Class Character, byte UPPERCASE_LETTER
Public data for enumerated Unicode general category types. @since JDK1.1
Instances of the classClass Class, Class forName(String, boolean, ClassLoader)Class
represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as aClass
object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean
byte
char
short
int
long
float
anddouble
) and the keywordvoid
are also represented asClass
objects.
Class
has no public constructor. InsteadClass
objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to thedefineClass
method in the class loader.The following example uses a
Class
object to print the class name of an object:
@author unascribed @version 1.void printClassName(Object obj) { System.out.println("The class of " + obj + " is " + obj.getClass().getName()); }100 04107 02/2202/9900 @see java.lang.ClassLoader#defineClass(byte[] int int) @since JDK1.0
Returns theClass Class, Class[] getClasses()Class
object associated with the class or interface with the given string name using the given class loader. Given the fully qualified name for a class or interface (in the same format returned bygetName
) this method attempts to locate load and link the class or interface. The specified class loader is used to load the class or interface. If the parameterloader
is null the class is loaded through the bootstrap class loader. The class is initialized only if theinitialize
parameter istrue
and if it has not been initialized earlier.If
name
denotes a primitive type or void an attempt will be made to locate a user-defined class in the unnamed package whose name isname
. Therefore this method cannot be used to obtain any of theClass
objects representing primitive types or void.If
name
denotes an array class the component type of the array class is loaded but not initialized.For example in an instance method the expression:
is equivalent to:Class.forName("Foo")Note that this method throws errors related to loading linking or initializing as specified in Sections 12.2 12.3 and 12.4 of The Java Language Specification.Class.forName("Foo" true this.getClass().getClassLoader())If the
loader
isnull
and a security manager is present and the caller's class loader is not null then this method calls the security manager'scheckPermission
method with aRuntimePermission("getClassLoader")
permission to ensure it's ok to access the bootstrap class loader. @param name fully qualified name of the desired class @param initialize whether the class must be initialized @param loader class loader from which the class must be loaded @return class object representing the desired class @exception LinkageError if the linkage fails @exception ExceptionInInitializerError if the initialization provoked by this method fails @exception ClassNotFoundException if the class cannot be located by the specified class loader @see java.lang.Class#forName(String) @see java.lang.ClassLoader @sinceJDK11.2
Returns an array containingClass Class, Class getComponentType()Class
objects representing all the public classes and interfaces that are members of the class represented by thisClass
object. This includes public class and interface members inherited from superclasses and public class and interface members declared by the class. This method returns an array of length 0 if thisClass
object has no public member classes or interfaces. This method also returns an array of length 0 if thisClass
object represents a primitive type an array class or void.For this class and each of its superclasses the following security checks are performed: If there is a security manager the security manager's
checkMemberAccess
method is called withthis
andMember.PUBLIC
as its arguments wherethis
is this class or the superclass whose members are being determined. If the class is in a package then the security manager'scheckPackageAccess
method is also called with the package name as its argument. Either of these calls could result in a SecurityException. @return the array ofClass
objects representing the public members of this class @exception SecurityException if access to the information is denied. @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns theClass Class, Constructor getConstructor(Class[])Class
representing the component type of an array. If this class does not represent an array class this method returns null. @return theClass
representing the component type of this class if this class is an array @see java.lang.reflect.Array @since JDK1.1
Returns aClass Class, Constructor[] getConstructors()Constructor
object that reflects the specified public constructor of the class represented by thisClass
object. TheparameterTypes
parameter is an array ofClass
objects that identify the constructor's formal parameter types in declared order.The constructor to reflect is the public constructor of the class represented by this
Class
object whose formal parameter types match those specified byparameterTypes
.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.PUBLIC
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @param parameterTypes the parameter array @return theMethod
object of the public constructor that matches the specifiedparameterTypes
@exception NoSuchMethodException if a matching method is not found. @exception SecurityException if access to the information is denied. @see java.lang.reflect.Constructor @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns an array containingClass Class, Class[] getDeclaredClasses()Constructor
objects reflecting all the public constructors of the class represented by thisClass
object. An array of length 0 is returned if the class has no public constructors or if the class is an array class or if the class reflects a primitive type or void.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.PUBLIC
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @return the array containingMethod
objects for all the declared public constructors of this class matches the specifiedparameterTypes
@exception SecurityException if access to the information is denied. @see java.lang.reflect.Constructor @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns an array ofClass Class, Constructor getDeclaredConstructor(Class[])Class
objects reflecting all the classes and interfaces declared as members of the class represented by thisClass
object. This includes public protected default (package) access and private classes and interfaces declared by the class but excludes inherited classes and interfaces. This method returns an array of length 0 if the class declares no classes or interfaces as members or if thisClass
object represents a primitive type an array class or void.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.DECLARED
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @return the array ofClass
objects representing all the declared members of this class @exception SecurityException if access to the information is denied. @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns aClass Class, Constructor[] getDeclaredConstructors()Constructor
object that reflects the specified constructor of the class or interface represented by thisClass
object. TheparameterTypes
parameter is an array ofClass
objects that identify the constructor's formal parameter types in declared order.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.DECLARED
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @param parameterTypes the parameter array @return TheMethod
object for the constructor with the specified parameter list @exception NoSuchMethodException if a matching method is not found. @exception SecurityException if access to the information is denied. @see java.lang.reflect.Constructor @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns an array ofClass Class, Field getDeclaredField(String)Constructor
objects reflecting all the constructors declared by the class represented by thisClass
object. These are public protected default (package) access and private constructors. The elements in the array returned are not sorted and are not in any particular order. If the class has a default constructor it is included in the returned array. This method returns an array of length 0 if thisClass
object represents an interface a primitive type an array class or void.See The Java Language Specification section 8.2.
If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.DECLARED
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @return the array ofMethod
objects representing all the declared constructors of this class @exception SecurityException if access to the information is denied. @see java.lang.reflect.Constructor @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns aClass Class, Field[] getDeclaredFields()Field
object that reflects the specified declared field of the class or interface represented by thisClass
object. Thename
parameter is aString
that specifies the simple name of the desired field. Note that this method will not reflect thelength
field of an array class.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.DECLARED
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @param name the name of the field @return theField
object for the specified field in this class @exception NoSuchFieldException if a field with the specified name is not found. @exception SecurityException if access to the information is denied. @see java.lang.reflect.Field @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns an array ofClass Class, Method getDeclaredMethod(String, Class[])Field
objects reflecting all the fields declared by the class or interface represented by thisClass
object. This includes public protected default (package) access and private fields but excludes inherited fields. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface declares no fields or if thisClass
object represents a primitive type an array class or void.See The Java Language Specification sections 8.2 and 8.3.
If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.DECLARED
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @return the array ofField
objects representing all the declared fields of this class @exception SecurityException if access to the information is denied. @see java.lang.reflect.Field @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns aClass Class, Method[] getDeclaredMethods()Method
object that reflects the specified declared method of the class or interface represented by thisClass
object. Thename
parameter is aString
that specifies the simple name of the desired method and theparameterTypes
parameter is an array ofClass
objects that identify the method's formal parameter types in declared order. If more than one method with the same parameter types is declared in a class and one of these methods has a return type that is more specific than any of the others that method is returned; otherwise one of the methods is chosen arbitrarily. If the name is "<init>"or "<clinit>" aNoSuchMethodException
is raised.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.DECLARED
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @param name the name of the method @param parameterTypes the parameter array @return theMethod
object for the method of this class matching the specified name and parameters @exception NoSuchMethodException if a matching method is not found. @exception SecurityException if access to the information is denied. @see java.lang.reflect.Method @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns an array ofClass Class, Class getDeclaringClass()Method
objects reflecting all the methods declared by the class or interface represented by thisClass
object. This includes public protected default (package) access and private methods but excludes inherited methods. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface declares no methods or if thisClass
object represents a primitive type an array class or void. The class initialization method<clinit>
is not included in the returned array. If the class declares multiple public member methods with the same parameter types they are all included in the returned array.See The Java Language Specification section 8.2.
If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.DECLARED
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException. @return the array ofMethod
objects representing all the declared methods of this class @exception SecurityException if access to the information is denied. @see java.lang.reflect.Method @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
If the class or interface represented by thisClass Class, Field getField(String)Class
object is a member of another class returns theClass
object representing the class in which it was declared. This method returns null if this class or interface is not a member of any other class. If thisClass
object represents an array class a primitive type or void then this method returns null. @return the declaring class for this class @since JDK1.1
Returns aClass Class, Field[] getFields()Field
object that reflects the specified public member field of the class or interface represented by thisClass
object. Thename
parameter is aString
specifying the simple name of the desired field.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.PUBLIC
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException.The field to be reflected is determined by the algorithm that follows. Let C be the class represented by this object:
- If C declares a public field with the name specified that is the field to be reflected.
- If no field was found in step 1 above this algorithm is applied recursively to each direct superinterface of C. The direct superinterfaces are searched in the order they were declared.
- If no field was found in steps 1 and 2 above and C has a superclass S then this algorithm is invoked recursively upon S. If C has no superclass then a
NoSuchFieldException
is thrown.See The Java Language Specification sections 8.2 and 8.3. @param name the field name @return the
Field
object of this class specified byname
@exception NoSuchFieldException if a field with the specified name is not found. @exception SecurityException if access to the information is denied. @see java.lang.reflect.Field @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns an array containingClass Class, Method getMethod(String, Class[])Field
objects reflecting all the accessible public fields of the class or interface represented by thisClass
object. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface has no accessible public fields or if it represents an array class a primitive type or void.Specifically if this
Class
object represents a class this method returns the public fields of this class and of all its superclasses. If thisClass
object represents an interface this method returns the fields of this interface and of all its superinterfaces.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.PUBLIC
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException.The implicit length field for array classs is not reflected by this method. User code should use the methods of class
Array
to manipulate arrays.See The Java Language Specification sections 8.2 and 8.3. @return the array of
Field
objects representing the public fields @exception SecurityException if access to the information is denied. @see java.lang.reflect.Field @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns aClass Class, Method[] getMethods()Method
object that reflects the specified public member method of the class or interface represented by thisClass
object. Thename
parameter is aString
specifying the simple name the desired method. TheparameterTypes
parameter is an array ofClass
objects that identify the method's formal parameter types in declared order. IfparameterTypes
isnull
it is treated as if it were an empty array.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.PUBLIC
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException.If the
name
is "<init>"or "<clinit>" aNoSuchMethodException
is raised. Otherwise the method to be reflected is determined by the algorithm that follows. Let C be the class represented by this object:To find a matching method in a class C: If C declares exactly one public method with the specified name and exactly the same formal parameter types that is the method reflected. If more than one such method is found in C and one of these methods has a return type that is more specific than any of the others that method is reflected; otherwise one of the methods is chosen arbitrarily.
- C is searched for any matching methods. If no matching method is found the algorithm of step 1 is invoked recursively on the superclass of C.
- If no method was found in step 1 above the superinterfaces of C are searched for a matching method. If any such method is found it is reflected.
See The Java Language Specification sections 8.2 and 8.4. @param name the name of the method @param parameterTypes the list of parameters @return the
Method
object that matches the specifiedname
andparameterTypes
@exception NoSuchMethodException if a matching method is not found or if then name is "<init>"or "<clinit>". @exception SecurityException if access to the information is denied. @see java.lang.reflect.Method @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns an array containingClass Class, int getModifiers()Method
objects reflecting all the public member methods of the class or interface represented by thisClass
object including those declared by the class or interface and and those inherited from superclasses and superinterfaces. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if thisClass
object represents a class or interface that has no public member methods or if thisClass
object represents an array class primitive type or void.If there is a security manager this method first calls the security manager's
checkMemberAccess
method withthis
andMember.PUBLIC
as its arguments. If the class is in a package then this method also calls the security manager'scheckPackageAccess
method with the package name as its argument. Either of these calls could result in a SecurityException.The class initialization method
<clinit>
is not included in the returned array. If the class declares multiple public member methods with the same parameter types they are all included in the returned array.See The Java Language Specification sections 8.2 and 8.4. @return the array of
Method
objects representing the public methods of this class @exception SecurityException if access to the information is denied. @see java.lang.reflect.Method @see SecurityManager#checkMemberAccess(Class int) @see SecurityManager#checkPackageAccess(String) @since JDK1.1
Returns the Java language modifiers for this class or interface encoded in an integer. The modifiers consist of the Java Virtual Machine's constants forClass Class, ProtectionDomain getProtectionDomain()public
protected
private
final
static
abstract
andinterface
; they should be decoded using the methods of classModifier
.If the underlying class is an array class then its
public
private
andprotected
modifiers are the same as those of its component type. If thisClass
represents a primitive type or void itspublic
modifier is alwaystrue
and itsprotected
andprivate
modifers are alwaysfalse
. If this object represents an array class a primitive type or void then itsfinal
modifier is alwaystrue
and its interface modifer is alwaysfalse
. The values of its other modifiers are not determined by this specification.The modifier encodings are defined in The Java Virtual Machine Specification table 4.1. @return the
int
representing the modifiers for this class @see java.lang.reflect.Modifier @since JDK1.1
Returns theClass Class, boolean isAssignableFrom(Class)ProtectionDomain
of this class. If there is a security manager installed this method first calls the security manager'scheckPermission
method with aRuntimePermission("getProtectionDomain")
permission to ensure it's ok to get theProtectionDomain
. @return the ProtectionDomain of this class @throws SecurityException if a security manager exists and itscheckPermission
method doesn't allow geting the ProtectionDomain. @see java.security.ProtectionDomain @see SecurityManager#checkPermission @see java.lang.RuntimePermission @sinceJDK11.2
Determines if the class or interface represented by thisClass Class, boolean isInstance(Object)Class
object is either the same as or is a superclass or superinterface of the class or interface represented by the specifiedClass
parameter. It returnstrue
if so; otherwise it returnsfalse
. If thisClass
object represents a primitive type this method returnstrue
if the specifiedClass
parameter is exactly thisClass
object; otherwise it returnsfalse
.Specifically this method tests whether the type represented by the specified
Class
parameter can be converted to the type represented by thisClass
object via an identity conversion or via a widening reference conversion. See The Java Language Specification sections 5.1.1 and 5.1.4 for details. @param cls theClass
object to be checked @return theboolean
value indicating whether objects of the typecls
can be assigned to objects of this class @exception NullPointerException if the specified Class parameter is null. @since JDK1.1
Determines if the specifiedClass Class, boolean isPrimitive()Object
is assignment-compatible with the object represented by thisClass
. This method is the dynamic equivalent of the Java languageinstanceof
operator. The method returnstrue
if the specifiedObject
argument is non-null and can be cast to the reference type represented by thisClass
object without raising aClassCastException.
It returnsfalse
otherwise.Specifically if this
Class
object represents a declared class this method returnstrue
if the specifiedObject
argument is an instance of the represented class (or of any of its subclasses); it returnsfalse
otherwise. If thisClass
object represents an array class this method returnstrue
if the specifiedObject
argument can be converted to an object of the array class by an identity conversion or by a widening reference conversion; it returnsfalse
otherwise. If thisClass
object represents an interface this method returnstrue
if the class or any superclass of the specifiedObject
argument implements this interface; it returnsfalse
otherwise. If thisClass
object represents a primitive type this method returnsfalse
. @param obj the object to check @return true ifobj
is an instance of this class @since JDK1.1
Determines if the specifiedClass
object represents a primitive type.There are nine predefined
Class
objects to represent the eight primitive types and void. These are created by the Java Virtual Machine and have the same names as the primitive types that they represent namelyboolean
byte
char
short
int
long
float
anddouble
.These objects may only be accessed via the following public static final variables and are the only
Class
objects for which this method returnstrue
. @return true if and only if this class represents a primitive type @see java.lang.Boolean#TYPE @see java.lang.Character#TYPE @see java.lang.Byte#TYPE @see java.lang.Short#TYPE @see java.lang.Integer#TYPE @see java.lang.Long#TYPE @see java.lang.Float#TYPE @see java.lang.Double#TYPE @see java.lang.Void#TYPE @since JDK1.1
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example the following code generates aClassCastException
:@author unascribed @version 1.Object x = new Integer(0); System.out.println((String)x);15 0917 02/2102/9800 @since JDK1.0
Thrown when a circularity has been detected while initializing a class. @author unascribed @version 1.10 0912 02/2102/9800 @since JDK1.0
Thrown when the Java Virtual Machine attempts to read a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file. @author unascribed @version 1.15 0917 02/2102/9800 @since JDK1.0
The classClass ClassLoader, constructor ClassLoader(ClassLoader)ClassLoader
is an abstract class. A class loader is an object that is responsible for loading classes. Given the name of a class it should attempt to locate or generate data that constitutes a definition for the class. A typical strategy is to transform the name into a file name and then read a "class file" of that name from a file system.Every
Class
object contains a reference to theClassLoader
that defined it.Class objects for array classes are not created by class loaders but are created automatically as required by the Java runtime. The class loader for an array class as returned by Class#getClassLoader() is the same as the class loader for its element type; if the element type is a primitive type then the array class has no class loader.
Applications implement subclasses of
ClassLoader
in order to extend the manner in which the Java virtual machine dynamically loads classes.Class loaders may typically be used by security managers to indicate security domains.
The
ClassLoader
class uses a delegation model to search for classes and resources. Each instance ofClassLoader
has an associated parent class loader. When called upon to find a class or resource aClassLoader
instance will delegate the search for the class or resource to its parent class loader before attempting to find the class or resource itself. The virtual machine's built-in class loader called the bootstrap class loader does not itself have a parent but may serve as the parent of aClassLoader
instance.Normally the Java virtual machine loads classes from the local file system in a platform-dependent manner. For example on UNIX systems the virtual machine loads classes from the directory defined by the
CLASSPATH
environment variable.However some classes may not originate from a file; they may originate from other sources such as the network or they could be constructed by an application. The method
defineClass
converts an array of bytes into an instance of classClass
. Instances of this newly defined class can be created using thenewInstance
method in classClass
.The methods and constructors of objects created by a class loader may reference other classes. To determine the class(es) referred to the Java virtual machine calls the
loadClass
method of the class loader that originally created the class.For example an application could create a network class loader to download class files from a server. Sample code might look like:
ClassLoader loader = new NetworkClassLoader(host port); Object main = loader.loadClass("Main" true).newInstance(); . . .The network class loader subclass must define the methods
findClass
andloadClassData
to load a class from the network. Once it has downloaded the bytes that make up the class it should use the methoddefineClass
to create a class instance. A sample implementation is:class NetworkClassLoader extends ClassLoader { String host; int port; public Class findClass(String name) { byte[] b = loadClassData(name); return defineClass(name b 0 b.length); } private byte[] loadClassData(String name) { // load the class data from the connection . . . } }
@version 1.129 05142 02/1917/00 @see java.lang.Class @see java.lang.Class#newInstance() @see java.lang.ClassLoader#defineClass(byte[] int int) @see java.lang.ClassLoader#loadClass(java.lang.String boolean) @see java.lang.ClassLoader#resolveClass(java.lang.Class) @since JDK1.0
Creates a new class loader using the specified parent class loader for delegation.Class ClassLoader, Class defineClass(String, byte[], int, int, ProtectionDomain)If there is a security manager its
checkCreateClassLoader
method is called. This may result in a security exception. @throws SecurityException if a security manager exists and itscheckCreateClassLoader
method doesn't allow creation of a new class loader. @param parent the parent class loader @see java.lang.SecurityException @see java.lang.SecurityManager#checkCreateClassLoader() @sinceJDK11.2
Converts an array of bytes into an instance of class Class with an optional ProtectionDomain. If the domain isClass ClassLoader, Package definePackage(String, String, String, String, String, String, String, URL)null
then a default domain will be assigned to the class as specified in the documentation for byte[ int int)}. Before the class can be used it must be resolved.The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain. The set of certificates for a class is obtained from the
CodeSource
within theProtectionDomain
of the class. Any classes added to that package must contain the same set of certificates or aSecurityException
will be thrown. Note that if thename
argument is null this check is not performed. You should always pass in the name of the class you are defining as well as the bytes. This ensures that the class you are defining is indeed the class you think it is.The specified class name cannot begin with "java." since all classes in the java.* packages can only be defined by the bootstrap class loader. @exception ClassFormatError if the data did not contain a valid class @exception IndexOutOfBoundsException if either
off
orlen
is negative or ifoff+len
is greater thanb.length
. @exception SecurityException if an attempt is made to add this class to a package that contains classes that were signed by a different set of certificatesthenthan this class or if the class name begins with "java.". @param name the name of the class @param b the class bytes @param off the start offset of the class bytes @param len the length of the class bytes @param protectionDomain the ProtectionDomain of the class @return theClass
object created from the data and optional ProtectionDomain.
Defines a package by name in this ClassLoader. This allows class loaders to define the packages for their classes. Packages must be created before the class is defined and package names must be unique within a class loader and cannot be redefined or changed once created. @param name the package name @param specTitle the specification title @param specVersion the specification version @param specVendor the specification vendor @param implTitle the implementation title @param implVersion the implementation version @param implVendor the implementation vendor @param sealBase If not null then this package is sealed with respect to the given code source URL. Otherwise the package is not sealed. @return the newly definedClass ClassLoader, Class findClass(String)Package
object @exception IllegalArgumentException if package name duplicates an existing package either in this class loader or one of its ancestors @sinceJDK11.2
Finds the specified class. This method should be overridden by class loader implementations that follow the new delegation model for loading classes and will be called by theClass ClassLoader, String findLibrary(String)loadClass
method after checking the parent class loader for the requested class. The default implementation throwsClassNotFoundException
. @param name the name of the class @return the resultingClass
object @exception ClassNotFoundException if the class could not be found @sinceJDK11.2
Returns the absolute path name of a native library. The VM invokes this method to locate the native libraries that belong to classes loaded with this class loader. If this method returnsClass ClassLoader, URL findResource(String)null
the VM searches the library along the path specified as thejava.library.path
property. @param libname the library name @return the absolute path of the native library @see java.lang.System#loadLibrary(java.lang.String) @see java.lang.System#mapLibraryName(java.lang.String) @sinceJDK11.2
Finds the resource with the given name. Class loader implementations should override this method to specify where to find resources. @param name the resource name @return a URL for reading the resource orClass ClassLoader, Enumeration findResources(String)null
if the resource could not be found @sinceJDK11.2
Returns an Enumeration of URLs representing all the resources with the given name. Class loader implementations should override this method to specify where to load resources from. @param name the resource name @return an Enumeration of URLs for the resources @throws IOException if I/O errors occur @sinceClass ClassLoader, Class findSystemClass(String)JDK11.2
Finds a class with the specified name loading it if necessary.Class ClassLoader, Package getPackage(String)Prior to
JDK1.the Java 2 SDK this method loads a class from the local file system in a platform-dependent manner and returns a class object that has no associated class loader.Since
JDK1the Java 2 SDK v1.2 this method loads the class through the system class loader(see Clas objects returned might haveClassLoader
s associated with them. Subclasses ofClassLoader
need not usually call this method because most class loaders need to override just @separa#ClassLoader(ClassLoader) @see #getParent() @paramname the name of the class that is to be found @returnathesystemClass
class withobject for thegivenspecifiedname
@exception ClassNotFoundException if the class could not be found @see #ClassLoader(ClassLoader) @see #getParent()
Returns a Package that has been defined by this class loader or any of its ancestors. @param name the package name @return the Package corresponding to the given name or null if not found @sinceClass ClassLoader, Package[] getPackages()JDK11.2
Returns all of the Packages defined by this class loader and its ancestors. @return the array ofClass ClassLoader, ClassLoader getParent()Package
objects defined by thisClassLoader
@sinceJDK11.2
Returns the parent class loader for delegation. Some implementations may useClass ClassLoader, Enumeration getResources(String)null
to represent the bootstrap class loader. This method will returnnull
in such implementations if this class loader's parent is the bootstrap class loader.If a security manager is present and the caller's class loader is not null and is not an ancestor of this class loader then this method calls the security manager's
checkPermission
method with aRuntimePermission("getClassLoader")
permission to ensure it's ok to access the parent class loader. If not aSecurityException
will be thrown. @return the parentClassLoader
@throws SecurityException if a security manager exists and itscheckPermission
method doesn't allow access to this class loader's parent class loader. @see SecurityManager#checkPermission @see java.lang.RuntimePermission @sinceJDK11.2
Finds all the resources with the given name. A resource is some data (images audio text etc) that can be accessed by class code in a way that is independent of the location of the code.Class ClassLoader, ClassLoader getSystemClassLoader()The name of a resource is a "/"-separated path name that identifies the resource.
The search order is described in the documentation for @para name resource name @return an enumeration of URL to the resource. If no resources could be found the enumeration will be empty. Resources that the doesn't have access to will not be in the enumeration. @throws IOException if I/O errors occur @since
JDK11.2 @see #getResource @see #findResources
Returns the system class loader for delegation. This is the default delegation parent for newClass ClassLoader, URL getSystemResource(String)ClassLoader
instances and is typically the class loader used to start the application.If a security manager is present and the caller's class loader is not null and the caller's class loader is not the same as or an ancestor of the system class loader then this method calls the security manager's
checkPermission
method with aRuntimePermission("getClassLoader")
permission to ensure it's ok to access the system class loader. If not aSecurityException
will be thrown. @return the systemClassLoader
for delegation ornull
if none @throws SecurityException if a security manager exists and itscheckPermission
method doesn't allow access to the system class loader. @see SecurityManager#checkPermission @see java.lang.RuntimePermission @sinceJDK11.2
Find a resource of the specified name from the search path used to load classes.Class ClassLoader, Enumeration getSystemResources(String)In JDK1.1 the search path used is that of the virtual machine's built-in class loader.
Since
JDK1the Java 2 SDK v1.2 this method locates the resource through the system class loader (see @para name the resource name @return a URL for reading the resource ornull
if the resource could not be found @since JDK1.1
Finds all resources of the specified name from the search path used to load classes. The resources thus found are returned as anClass ClassLoader, Class loadClass(String, boolean)Enumeration
ofURL
objects.The search order is described in the documentation for #getSystemResource(String)
@param name the resource name @return an enumeration of resource URLs @throws IOException if I/O errors occur @since
JDK11.2
Loads the class with the specified name. The default implementation of this method searches for classes in the following order:
If the class was found using the above steps and the
- Call #findLoadedClass(String) to check if the class has already been loaded.
- Call the
loadClass
method on the parent class loader. If the parent isnull
the class loader built-in to the virtual machine is used instead.
- Call the #findClass(String) method to find the class.
resolve
flag is true this method will then call the #resolveClass(Class) method on the resulting class object.From
JDK1the Java 2 SDK v1.2 subclasses of ClassLoader are encouraged to override #findClass(String) rather than this method.@param name the name of the class @param resolve if
true
then resolve the class @return the resultingClass
object @exception ClassNotFoundException if the class could not be found
Thrown when an application tries to load in a class through its string name using:Class ClassNotFoundException, constructor ClassNotFoundException(String, Throwable)
- The
forName
method in classClass
.- The
findSystemClass
method in classClassLoader
.- The
loadClass
method in classClassLoader
.but no definition for the class with the specifed name could be found. @author unascribed @version 1.
8 0513 02/0402/9800 @see java.lang.Class#forName(java.lang.String) @see java.lang.ClassLoader#findSystemClass(java.lang.String) @see java.lang.ClassLoader#loadClass(java.lang.String boolean) @since JDK1.0
Constructs aClass ClassNotFoundException, Throwable getException()ClassNotFoundException
with the specified detail message and optional exception that was raised while loading the class. @param s the detail message @param ex the exception that was raised while loading the class @sinceJDK11.2
Returns the exception that was raised if an error occurred while attempting to load the class. Otherwise returns null. @return theException
that was raised while loading a class @sinceJDK11.2
Thrown to indicate that theclone
method in classObject
has been called to clone an object but that the object's class does not implement theCloneable
interface.Applications that override the
clone
method can also throw this exception to indicate that an object could not or should not be cloned. @author unascribed @version 1.6 098 02/2102/9800 @see java.lang.Cloneable @see java.lang.Object#clone() @since JDK1.0
A class implements theCloneable
interface to indicate to the java.lang.Object#clone() method that it is legal for that method to make a field-for-field copy of instances of that class.Attempts to clone instances that do not implement the
Cloneable
interface result in the exceptionCloneNotSupportedException
being thrown.The interface Cloneable declares no methods. @author unascribed @version 1.
8 0910 02/2102/9800 @see java.lang.CloneNotSupportedException @since JDK1.0
This interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class's natural ordering and the class's compareTo method is referred to as its natural comparison method.Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort). Objects that implement this interface can be used as keys in a sorted map or elements in a sorted set without the need to specify a comparator.
A class's natural ordering is said to be consistent with equals if and only if (e1.compareTo((Object)e2)==0) has the same boolean value as e1.equals((Object)e2) for every e1 and e2 of class C.
It is strongly recommended (though not required) that natural orderings be consistent with equals. This is so because sorted sets (and sorted maps) without explicit comparators behave "strangely" when they are used with elements (or keys) whose natural ordering is inconsistent with equals. In particular such a sorted set (or sorted map) violates the general contract for set (or map) which is defined in terms of the equals operation.
For example if one adds two keys a and b such that (a.equals((Object)b) && a.compareTo((Object)b) = 0) to a sorted set that does not use an explicit comparator the second add operation returns false (and the size of the sorted set does not increase) because a and b are equivalent from the sorted set's perspective.
Virtually all Java core classes that implement comparable have natural orderings that are consistent with equals. One exception is java.math.BigDecimal whose natural ordering equates BigDecimals with equal values and different precisions (such as 4.0 and 4.00).
For the mathematically inclined the relation that defines the natural ordering on a given class C is:
{(x y) such that x.compareTo((Object)y) <= 0}.The quotient for this total order is:{(x y) such that x.compareTo((Object)y) == 0}.It follows immediately from the contract for compareTo that the quotient is an equivalence relation on C and that the natural ordering is a total order on C. When we say that a class's natural ordering is consistent with equals we mean that the quotient for the natural ordering is the equivalence relation defined by the class's equals(Object) method:{(x y) such that x.equals((Object)y)}.@author Josh Bloch @version 1.9 0913 02/3002/9800 @see java.util.Comparator @see java.util.Collections#sort(java.util.List) @see java.util.Arrays#sort(Object[]) @see java.util.SortedSet @see java.util.SortedMap @see java.util.TreeSet @see java.util.TreeMap @sinceJDK11.2
TheCompiler
class is provided to support Java-to-native-code compilers and related services. By design theCompiler
class does nothing; it serves as a placeholder for a JIT compiler implementation.When the Java Virtual Machine first starts it determines if the system property
java.compiler
exists. (System properties are accessible throughgetProperty
and a method defined by theSystem
class.) If so it is assumed to be the name of a library (with a platform-dependent exact location and type); theloadLibrary
method in classSystem
is called to load that library. If this loading succeeds the function namedjava_lang_Compiler_start()
in that library is called.If no compiler is available these methods do nothing. @author Frank Yellin @version 1.
12 0615 02/2902/9800 @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String) @see java.lang.System#loadLibrary(java.lang.String) @since JDK1.0
The Double class wraps a value of the primitive typeClass Double, int compareTo(Double)double
in an object. An object of typeDouble
contains a single field whose type isdouble
.In addition this class provides several methods for converting a
double
to aString
and aString
to adouble
as well as other constants and methods useful when dealing with adouble
. @author Lee Boynton @author Arthur van Hoff @version 1.54 0963 02/1102/9800 @since JDK1.0
Compares two Doubles numerically. There are two ways in which comparisons performed by this method differ from those performed by the Java language numerical comparison operators (Class Double, int compareTo(Object)< <= == >= >
) when applied to primitive doubles:This ensures that Double.compareTo(Object) (which inherits its behavior from this method) obeys the general contract for Comparable.compareTo and that the natural order on Doubles is total. @param anotherDouble the
Double.NaN
is considered by this method to be equal to itself and greater than all other double values (includingDouble.POSITIVE_INFINITY
).0.0d
is considered by this method to be greater than-0.0d
.Double
to be compared. @return the value0
ifanotherDouble
is numerically equal to this Double; a value less than0
if this Double is numerically less thananotherDouble
; and a value greater than0
if this Double is numerically greater thananotherDouble
. @sinceJDK11.2 @see Comparable#compareTo(Object)
Compares this Double to another Object. If the Object is a Double this function behaves likeClass Double, int hashCode()compareTo(Double)
. Otherwise it throws aClassCastException
(as Doubles are comparable only to other Doubles). @param o theObject
to be compared. @return the value0
if the argument is a Double numerically equal to this Double; a value less than0
if the argument is a Double numerically greater than this Double; and a value greater than0
if the argument is a Double numerically less than this Double. @exceptionClassCastException
if the argument is not aDouble
. @see java.lang.Comparable @sinceJDK11.2
Returns a hashcode for thisClass Double, double longBitsToDouble(long)Double
object. The result is the exclusive OR of the two halves of the long integer bit representation exactly as produced by the method #doubleToLongBits(double) of the primitivedouble
value represented by thisDouble
object. That is the hashcode is the value of the expression:where(int)(v^(v>>>32))v
is defined by:@return along v = Double.doubleToLongBits(this.longValuedoubleValue());hash code
value for this object.
Returns the double-float corresponding to a given bit represention. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "double precision" bit layout. That floating-point value is returned as the result.Class Double, double parseDouble(String)If the argument is
0x7ff0000000000000L
the result is positive infinity.If the argument is
0xfff0000000000000L
the result is negative infinity.If the argument is any value in the range
0x7ff0000000000001L
through0x7fffffffffffffffL
or in the range0xfff0000000000001L
through0xffffffffffffffffL
the result is NaN. All IEEE 754 NaN values of typedouble
are in effect lumped together by the Java programming language into a single value called NaN. Distinct values of NaN are only accessible by use of theDouble.doubleToRawLongBits
method.In all other cases let s e and m be three values that can be computed from the argument:
Then the floating-point result equals the value of the mathematical expression s·m·2e-1075. @param bits anyint s = ((bits >> 63) == 0) 1 : -1; int e = (int)((bits >> 52) & 0x7ffL); long m = (e == 0) (bits & 0xfffffffffffffL) < 1 : (bits & 0xfffffffffffffL) | 0x10000000000000L;long
integer. @return thedouble
floating-point value with the same bit pattern.
Returns a new double initialized to the value represented by the specifiedClass Double, String toString(double)String
as performed by thevalueOf
method of classDouble
. @param s the string to be parsed. @return the double value represented by the string argument. @exception NumberFormatException if the string does not contain a parsable double. @see java.lang.Double#valueOf(String) @sinceJDK11.2
Creates a string representation of thedouble
argument. All characters mentioned below are ASCII characters.
- If the argument is NaN the result is the string "NaN".
- Otherwise the result is a string that represents the sign and magnitude (absolute value) of the argument. If the sign is negative the first character of the result is '
-
' ('-
'); if the sign is positive no sign character appears in the result. As for the magnitude m:- If m is infinity it is represented by the characters
"Infinity"
; thus positive infinity produces the result"Infinity"
and negative infinity produces the result"-Infinity"
.- If m is zero it is represented by the characters
"0.0"
; thus negative zero produces the result"-0.0"
and positive zero produces the result"0.0"
.- If m is greater than or equal to 10-3 but less than 107 then it is represented as the integer part of m in decimal form with no leading zeroes followed by
'.'
(.
) followed by one or more decimal digits representing the fractional part of m.- If m is less than 10-3 or not less than 107 then it is represented in so-called "computerized scientific notation." Let n be the unique integer such that 10n<=m<10n+1; then let a be the mathematically exact quotient of m and 10n so that 1<=a<10. The magnitude is then represented as the integer part of a as a single decimal digit followed by
'.'
(.
) followed by decimal digits representing the fractional part of a followed by the letter'E'
(E
) followed by a representation of n as a decimal integer as produced by the method Integer#toString(int)How many digits must be printed for the fractional part of m or a There must be at least one digit to represent the fractional part and beyond that as many but only as many more digits as are needed to uniquely distinguish the argument value from adjacent values of type
double
. That is suppose that x is the exact mathematical value represented by the decimal representation produced by this method for a finite nonzero argument d. Then d must be thedouble
value nearest to x; or if twodouble
values are equally close to x then d must be one of them and the least significant bit of the significand of d must be0
. @param d thedouble
to be converted. @return a string representation of the argument.
AnError
is a subclass ofThrowable
that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. TheThreadDeath
error though a "normal" condition is also a subclass ofError
because most applications should not try to catch it.A method is not required to declare in its
throws
clause any subclasses ofError
that might be thrown during the execution of the method but not caught since these errors are abnormal conditions that should never occur. @author Frank Yellin @version 1.10 0912 02/2102/9800 @see java.lang.ThreadDeath @since JDK1.0
The classException
and its subclasses are a form ofThrowable
that indicates conditions that a reasonable application might want to catch. @author Frank Yellin @version 1.25 0927 02/2102/9800 @see java.lang.Error @since JDK1.0
Signals that an unexpected exception has occurred in a static initializer. AnExceptionInInitializerError
is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable. @author Frank Yellin @version 1.9 0811 02/2502/9800 @since JDK1.1
The Float class wraps a value of primitive typeClass Float, int compareTo(Float)float
in an object. An object of typeFloat
contains a single field whose type isfloat
.In addition this class provides several methods for converting a
float
to aString
and aString
to afloat
as well as other constants and methods useful when dealing with afloat
. @author Lee Boynton @author Arthur van Hoff @version 1.48 0760 02/2302/9800 @since JDK1.0
Compares two Floats numerically. There are two ways in which comparisons performed by this method differ from those performed by the Java language numerical comparison operators (Class Float, int compareTo(Object)< <= == >= >
) when applied to primitive floats:This ensures that Float.compareTo(Object) (which inherits its behavior from this method) obeys the general contract for Comparable.compareTo and that the natural order on Floats is total. @param anotherFloat the
Float.NaN
is considered by this method to be equal to itself and greater than all other float values (includingFloat.POSITIVE_INFINITY
).0.0f
is considered by this method to be greater than-0.0f
.Float
to be compared. @return the value0
ifanotherFloat
is numerically equal to this Float; a value less than0
if this Float is numerically less thananotherFloat
; and a value greater than0
if this Float is numerically greater thananotherFloat
. @sinceJDK11.2 @see Comparable#compareTo(Object)
Compares this Float to another Object. If the Object is a Float this function behaves likeClass Float, boolean equals(Object)compareTo(Float)
. Otherwise it throws aClassCastException
(as Floats are comparable only to other Floats). @param o theObject
to be compared. @return the value0
if the argument is a Float numerically equal to this Float; a value less than0
if the argument is a Float numerically greater than this Float; and a value greater than0
if the argument is a Float numerically less than this Float. @exceptionClassCastException
if the argument is not aFloat
. @see java.lang.Comparable @sinceJDK11.2
Compares this object against some other object. The result isClass Float, float intBitsToFloat(int)true
if and only if the argument is notnull
and is aFloat
object that represents afloat
that has the identical bit pattern to the bit pattern of thefloat
represented by this object. For this purpose two float values are considered to be the same if and only if the method #floatToIntBits(float) returns the same int value when applied to each.Note that in most cases for two instances of class
Float
f1
andf2
the value off1.equals(f2)
istrue
if and only iff1.floatValue() == f2.floatValue()also has the value
true
. However there are two exceptions:This definition allows hashtables to operate properly. @param obj the object to be compared @return
- If
f1
andf2
both representFloat.NaN
then theequals
method returnstrue
even thoughFloat.NaN==Float.NaN
has the valuefalse
.- If
f1
represents+0.0f
whilef2
represents-0.0f
or vice versa theequal
test has the valuefalse
even though0.0f==-0.0f
has the valuetrue
.true
if the objects are the same;false
otherwise. @see java.lang.Float#floatToIntBits(float)
Returns the single-float corresponding to a given bit represention. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "single precision" bit layout.Class Float, float parseFloat(String)If the argument is
0x7f800000
the result is positive infinity.If the argument is
0xff800000
the result is negative infinity.If the argument is any value in the range
0x7f800001
through0x7fffffff
or in the range0xff800001
through0xffffffff
the result is NaN. All IEEE 754 NaN values of typefloat
are in effect lumped together by the Java programming language into a singlefloat
value called NaN. Distinct values of NaN are only accessible by use of theFloat.floatToRawIntBits
method.In all other cases let s e and m be three values that can be computed from the argument:
Then the floating-point result equals the value of the mathematical expression s·m·2e-150. @param bits an integer. @return the single-format floating-point value with the same bit pattern.int s = ((bits >> 31) == 0) 1 : -1; int e = ((bits >> 23) & 0xff); int m = (e == 0) (bits & 0x7fffff) < 1 : (bits & 0x7fffff) | 0x800000;
Returns a new float initialized to the value represented by the specifiedString
as performed by thevalueOf
method of classDouble
. @param s the string to be parsed. @return the float value represented by the string argument. @exception NumberFormatException if the string does not contain a parsable float. @see java.lang.Double#valueOf(String) @sinceJDK11.2
Thrown if an application attempts to access or modify a field or to call a method that it does not have access to.Normally this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed. @author unascribed @version 1.
11 0913 02/2102/9800 @since JDK1.0
Thrown when an application tries to load in a classthrough its string name using: The forName method in class Class. The findSystemClass method in class ClassLoader. The loadClass method in class ClassLoader.but the currently executing method does not have access to the definition of the specified class because the class is not public and in another package.An instance of this class can also be thrown when an application tries to create an instance of a class using the
newInstance
method in classClass
but the current method does not have access to the appropriate zero-argument constructor. @author unascribed @version 1.6 099 02/2102/9800 @see java.lang.Class#forName(java.lang.String) @see java.lang.Class#newInstance() @see java.lang.ClassLoader#findSystemClass(java.lang.String) @see java.lang.ClassLoader#loadClass(java.lang.String boolean) @since JDK1.0
Thrown to indicate that a method has been passed an illegal or inappropriate argument. @author unascribed @version 1.15 0917 02/2102/9800 @see java.lang.Thread#setPriority(int) @since JDK1.0
Thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's monitor without owning the specified monitor. @author unascribed @version 1.7 099 02/2102/9800 @see java.lang.Object#notify() @see java.lang.Object#notifyAll() @see java.lang.Object#wait() @see java.lang.Object#wait(long) @see java.lang.Object#wait(long int) @since JDK1.0
Signals that a method has been invoked at an illegal or inappropriate time. In other words the Java environment or Java application is not in an appropriate state for the requested operation. @author Jonni Kanerva @version 1.7 099 02/2102/9800 @since JDK1.1
Thrown to indicate that a thread is not in an appropriate state for the requested operation. See for example thesuspend
andresume
methods in classThread
. @author unascribed @version 1.16 0918 02/2102/9800 @see java.lang.Thread#resume() @see java.lang.Thread#suspend() @since JDK1.0
Thrown when an incompatible class change has occurred to some class definition. The definition of some class on which the currently executing method depends has since changed. @author unascribed @version 1.13 0915 02/2102/9800 @since JDK1.0
Thrown to indicate that an index of some sort (such as to an array to a string or to a vector) is out of range.Applications can subclass this class to indicate similar exceptions. @author Frank Yellin @version 1.
6 098 02/2102/9800 @since JDK1.0
This class extends ThreadLocal to provide inheritance of values from parent Thread to child Thread: when a child thread is created the child receives initial values for all InheritableThreadLocals for which the parent has values. Normally the child's values will be identical to the parent's; however the child's value can be made an arbitrary function of the parent's by overriding the childValue method in this class.Class InheritableThreadLocal, Object childValue(Object)
InheritableThreadLocal variables are used in preference to ordinary ThreadLocal variables when the per-thread-attribute being maintained in the variable (e.g. User ID Transaction ID) must be automatically transmitted to any child threads that are created. @author Josh Bloch @version 1.2 0610 02/2902/9800 @see ThreadLocal @sinceJDK11.2
Computes the child's initial value for this InheritableThreadLocal as a function of the parent's value at the time the child Thread is created. This method is called from within the parent thread before the child is started.This method merely returns its input argument and should be overridden if a different behavior is desired. @param parentValue the parent thread's value @return the child thread's initial value
Thrown when an application tries to use the Javanew
construct to instantiate an abstract class or an interface.Normally this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed. @author unascribed @version 1.
7 099 02/2102/9800 @since JDK1.0
Thrown when an application tries to create an instance of a class using thenewInstance
method in classClass
but the specified class object cannot be instantiated because it is an interface or is an abstract class. @author unascribed @version 1.12 0914 02/2102/9800 @see java.lang.Class#newInstance() @since JDK1.0
The Integer class wraps a value of the primitive typeClass Integer, int compareTo(Integer)int
in an object. An object of typeInteger
contains a single field whose type isint
.In addition this class provides several methods for converting an
int
to aString
and aString
to anint
as well as other constants and methods useful when dealing with anint
. @author Lee Boynton @author Arthur van Hoff @version 1.54 0862 02/2602/9800 @since JDK1.0
Compares two Integers numerically. @param anotherInteger theClass Integer, int compareTo(Object)Integer
to be compared. @return the value0
if the argument Integer is equal to this Integer; a value less than0
if this Integer is numerically less than the Integer argument; and a value greater than0
if this Integer is numerically greater than the Integer argument (signed comparison). @sinceJDK11.2
Compares this Integer to another Object. If the Object is a Integer this function behaves likeClass Integer, Integer decode(String)compareTo(Integer)
. Otherwise it throws aClassCastException
(as Integers are comparable only to other Integers). @param o theObject
to be compared. @return the value0
if the argument is a Integer numerically equal to this Integer; a value less than0
if the argument is a Integer numerically greater than this Integer; and a value greater than0
if the argument is a Integer numerically less than this Integer. @exceptionClassCastException
if the argument is not anInteger
. @see java.lang.Comparable @sinceJDK11.2
Decodes aClass Integer, Integer getInteger(String)String
into anInteger
. Accepts decimal hexadecimal and octal numbers in the following formats:[-] decimal constant [-] 0x hex constant [-] # hex constant [-] 0 octal constantThe constant following an (optional) negative sign and/or "radix specifier" is parsed as by theInteger.parseInt
method with the specified radix (10 8 or 16). This constant must be positive or a NumberFormatException will result. The result is made negative if first character of the specifiedString
is the negative sign. No whitespace characters are permitted in theString
. @param nm theString
to decode. @return theInteger
represented by the specified string. @exception NumberFormatException if theString
does not contain a parsable integer. @see java.lang.Integer#parseInt(String int)
Determines the integer value of the system property with the specified name.Class Integer, Integer getInteger(String, Integer)The first argument is treated as the name of a system property. System properties are accessible through the java.lang.System#getProperty(java.lang.String) method. The string value of this property is then interpreted as an integer value and an
Integer
object representing this value is returned. Details of possible numeric formats can be found with the definition ofgetProperty
.If there is no property with the specified name if the specified name is empty or null or if the property does not have the correct numeric format then
null
is returned. In other words this method returns anInteger
object equal to the value of:@param nm property name. @return thegetInteger(nm null)Integer
value of the property. @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String)
Returns the integer value of the system property with the specified name. The first argument is treated as the name of a system property. System properties are accessible throughClass Integer, Integer getInteger(String, int)getProperty
a method defined by theSystem
class. The string value of this property is then interpreted as an integer value as per theInteger.decode
method and anInteger
object representing this value is returned.
- If the property value begins with the two ASCII characters
0x
or the ASCII character#
not followed by a minus sign then the rest of it is parsed as a hexadecimal integer exactly as for the method int) with radix 16.- If the property value begins with the ASCII character
0
followed by another character it is parsed as an octal integer exactly as for the method int with radix 8.- Otherwise the property value is parsed as a decimal integer exactly as for the method int) with radix 10.
The second argument is the default value.
IfThe default value is returned if there is no property of the specified nameorif the property does not have the correct numeric formatthenor if thesecond argumentspecified name isreturnedempty or null. @param nm property name. @param val default value. @return theInteger
value of the property. @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String) @see java.lang.Integer#decode
Determines the integer value of the system property with the specified name.The first argument is treated as the name of a system property. System properties are accessible through
getProperty
a method defined by theSystem
class. The string value of this property is then interpreted as an integer value and anInteger
object representing this value is returned. Details of possible numeric formats can be found with the definition ofgetProperty
.
IfThe second argument is the default value. AnInteger
object that represents the value of the second argument is returned if there is no propertywithof the specified nameorif the property does not have the correct numeric formatthen an Integer object thatorrepresentsif thevalue ofspecifiedthe second argument is returnedname is empty or null.In other words this method returns an
Integer
object equal to the value of:but in practice it may be implemented in a manner such as:getInteger(nm new Integer(val))to avoid the unnecessary allocation of anInteger result = getInteger(nm null); return (result == null) new Integer(val) : result;Integer
object when the default value is not needed. @param nm property name. @param val default value. @return theInteger
value of the property. @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String)
Thrown to indicate some unexpected internal error has occurred in the Java Virtual Machine. @author unascribed @version 1.16 0918 02/2102/9800 @since JDK1.0
Thrown when a thread is waiting sleeping or otherwise paused for a long time and another thread interrupts it using theinterrupt
method in classThread
. @author Frank Yellin @version 1.10 0912 02/2102/9800 @see java.lang.Object#wait() @see java.lang.Object#wait(long) @see java.lang.Object#wait(long int) @see java.lang.Thread#sleep(long) @see java.lang.Thread#interrupt() @see java.lang.Thread#interrupted() @since JDK1.0
Subclasses ofLinkageError
indicate that a class has some dependency on another class; however the latter class has incompatibly changed after the compilation of the former class. @author Frank Yellin @version 1.8 0910 02/2102/9800 @since JDK1.0
The Long class wraps a value of the primitive typeClass Long, int compareTo(Long)long
in an object. An object of typeLong
contains a single field whose type islong
.In addition this class provides several methods for converting a
long
to aString
and aString
to along
as well as other constants and methods useful when dealing with along
. @author Lee Boynton @author Arthur van Hoff @version 1.42 0852 02/2602/9800 @since JDK1.0
Compares two Longs numerically. @param anotherLong theClass Long, int compareTo(Object)Long
to be compared. @return the value0
if the argument Long is equal to this Long; a value less than0
if this Long is numerically less than the Long argument; and a value greater than0
if this Long is numerically greater than the Long argument (signed comparison). @sinceJDK11.2
Compares this Long to another Object. If the Object is a Long this function behaves likeClass Long, Long decode(String)compareTo(Long)
. Otherwise it throws aClassCastException
(as Longs are comparable only to other Longs). @param o theObject
to be compared. @return the value0
if the argument is a Long numerically equal to this Long; a value less than0
if the argument is a Long numerically greater than this Long; and a value greater than0
if the argument is a Long numerically less than this Long. @exceptionClassCastException
if the argument is not aLong
. @see java.lang.Comparable @sinceJDK11.2
Decodes aClass Long, Long getLong(String)String
into aLong
. Accepts decimal hexadecimal and octal numbers in the following formats:[-] decimal constant [-] 0x hex constant [-] # hex constant [-] 0 octal constantThe constant following an (optional) negative sign and/or "radix specifier" is parsed as by theLong.parseLong
method with the specified radix (10 8 or 16). This constant must be positive or a NumberFormatException will result. The result is made negative if first character of the specifiedString
is the negative sign. No whitespace characters are permitted in theString
. @param nm theString
to decode. @return theLong
represented by the specified string. @exception NumberFormatException if theString
does not contain a parsable long. @see java.lang.Long#parseLong(String int)
Determines theClass Long, Long getLong(String, Long)long
value of the system property with the specified name.The first argument is treated as the name of a system property. System properties are accessible through the java.lang.System#getProperty(java.lang.String) method. The string value of this property is then interpreted as a long value and a
Long
object representing this value is returned. Details of possible numeric formats can be found with the definition ofgetProperty
.If there is no property with the specified name if the specified name is empty or null or if the property does not have the correct numeric format then
null
is returned.In other words this method returns a Long object equal to the value of:
@param nm property name. @return thegetLong(nm null)Long
value of the property. @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String)
Returns the long value of the system property with the specified name. The first argument is treated as the name of a system property. System properties are accessible through the java.lang.System#getProperty(java.lang.String) method. The string value of this property is then interpreted as a long value as per theClass Long, Long getLong(String, long)Long.decode
method and aLong
object representing this value is returned.
- If the property value begins with the two ASCII characters 0x or the ASCII character # not followed by a minus sign then the rest of it is parsed as a hexadecimal integer exactly as for the method int) with radix 16.
- If the property value begins with the character 0 followed by another character it is parsed as an octal integer exactly as for the method int) with radix 8.
- Otherwise the property value is parsed as a decimal integer exactly as for the method int) with radix 10.
Note that in every case neither L nor l is permitted to appear at the end of the property value as a type indicator as would be permitted in Java programming language source code.
The second argument is the default value.
IfThe default value is returned if there is no property of the specified nameorif the property does not have the correct numeric formatthenor if thesecond argumentspecified name isreturnedempty or null. @param nm property name. @param val default value. @return theLong
value of the property. @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String) @see java.lang.Long#decode
Determines theClass Long, String toString(long)long
value of the system property with the specified name.The first argument is treated as the name of a system property. System properties are accessible through the java.lang.System#getProperty(java.lang.String) method. The string value of this property is then interpreted as a long value and a
Long
object representing this value is returned. Details of possible numeric formats can be found with the definition ofgetProperty
.
IfThe second argument is the default value. ALong
object that represents the value of the second argument is returned if there is no propertywithof the specified nameorif the property does not have the correct numeric formatthen a Long object thatorrepresentsif thevalue ofspecifiedthe second argument is returnedname is empty or null.In other words this method returns a Long object equal to the value of:
but in practice it may be implemented in a manner such as:getLong(nm new Long(val))to avoid the unnecessary allocation of a Long object when the default value is not needed. @param nm property name. @param val default value. @return theLong result = getLong(nm null); return (result == null) new Long(val) : result;Long
value of the property. @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String)
Returns a new String object representing the specified integer. The argument is converted to signed decimal representation and returned as a string exactly as if the argument and the radix 10 were given as arguments to the int) method that takes two arguments. @param i a long
to be converted. @return a string representation of the argument in base 10.
The classClass Math, double IEEEremainder(double, double)Math
contains methods for performing basic numeric operations such as the elementary exponential logarithm square root and trigonometric functions.
To helpUnlike someensure portability of Java programs the definitions of manyof the numeric functionsin thisofpackageclassrequireStrictMath
that they produceall implementations of thesame results as certain published algorithms. These algorithms are available from theequivalentwell-knownfunctionsnetwork libraryof class
netlib as the package "Freely DistributableMathLibrary" (fdlibm). Thesealgorithms whicharewritten in the C programming language arenotthendefined tobe understood as executed with all floating-point operations followingreturn therules of Java floatingbit-point arithmetic. Thefor-bitnetworksamelibraryresults.may be foundThis relaxation permitsonbetter-performingthe World Wide Webimplementations where strict reproducibilityat:is nothttp://metalab.uncrequired.edu/
The Java math library isBy default many of thedefinedMath
withfunctions simplyrespectdelegate to theversionequivalentoffunctions in
fdlibmStrictMathdated Januaryfor4 1995their implementations.WhereCodefdlibmgeneratorsprovides more than oneare encouraged to usedefinitionplatform-specificfor a functionnative libraries or(suchmicroprocessorasinstructionsacos)whereuse theavailable to"IEEEprovide754higher-performancecoreimplementationsfunction"ofversionMath
(residingfunctions.inSuchahigher-performancefile whose name begins withimplementations still must conform to theletterspecification for
eMath). @author unascribed @version 1.39 0450 02/2202/9900 @since JDK1.0
Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. The remainder value is mathematically equal toClass Math, double abs(double)f1 - f2
× n where n is the mathematical integer closest to the exact mathematical value of the quotientf1/f2
and if two mathematical integers are equally close tof1/f2
then n is the integer that is even. If the remainder is zero its sign is the same as the sign of the first argument. Special cases:@param f1 the dividend. @param f2 the divisor. @return the remainder when
- If either argument is NaN or the first argument is infinite or the second argument is positive zero or negative zero then the result is NaN.
- If the first argument is finite and the second argument is infinite then the result is the same as the first argument.
f1
is divided byf2
.
Returns the absolute value of aClass Math, float abs(float)double
value. If the argument is not negative the argument is returned. If the argument is negative the negation of the argument is returned. Special cases:In other words the result is equal to the value of the expression:
- If the argument is positive zero or negative zero the result is positive zero.
- If the argument is infinite the result is positive infinity.
- If the argument is NaN the result is NaN.
Double.longBitsToDouble((Double.doubleToLongBits(a)<1)>>>1)@param a adouble
value. @return the absolute value of the argument.
Returns the absolute value of aClass Math, double acos(double)float
value. If the argument is not negative the argument is returned. If the argument is negative the negation of the argument is returned. Special cases:In other words the result is equal to the value of the expression:
- If the argument is positive zero or negative zero the result is positive zero.
- If the argument is infinite the result is positive infinity.
- If the argument is NaN the result is NaN.
Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))@param a afloat
value. @return the absolute value of the argument.
Returns the arc cosine of an angle in the range of 0.0 through pi. Special case:Class Math, double asin(double)
- If the argument is NaN or its absolute value is greater than 1 then the result is NaN.
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
@param a thedouble
value whose arc cosine is to be returned. @return the arc cosine of the argument.
Returns the arc sine of an angle in the range of -pi/2 through pi/2. Special cases:Class Math, double atan(double)
- If the argument is NaN or its absolute value is greater than 1 then the result is NaN.
- If the argument is positive zero then the result is positive zero; if the argument is negative zero then the result is negative zero.
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
@param a thedouble
value whose arc sine is to be returned. @return the arc sine of the argument.
Returns the arc tangent of an angle in the range of -pi/2 through pi/2. Special cases:Class Math, double atan2(double, double)
- If the argument is NaN then the result is NaN.
- If the argument is positive zero then the result is positive zero; if the argument is negative zero then the result is negative zero.
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
@param a thedouble
value whose arc tangent is to be returned. @return the arc tangent of the argument.
Converts rectangular coordinates (Class Math, double ceil(double)b
a
) to polar (r theta). This method computes the phase theta by computing an arc tangent ofa/b
in the range of -pi to pi. Special cases:
- If either argument is NaN then the result is NaN.
- If the first argument is positive zero and the second argument is positive or the first argument is positive and finite and the second argument is positive infinity then the result is positive zero.
- If the first argument is negative zero and the second argument is positive or the first argument is negative and finite and the second argument is positive infinity then the result is negative zero.
- If the first argument is positive zero and the second argument is negative or the first argument is positive and finite and the second argument is negative infinity then the result is the
double
value closest to pi.- If the first argument is negative zero and the second argument is negative or the first argument is negative and finite and the second argument is negative infinity then the result is the
double
value closest to -pi.- If the first argument is positive and the second argument is positive zero or negative zero or the first argument is positive infinity and the second argument is finite then the result is the
double
value closest to pi/2.- If the first argument is negative and the second argument is positive zero or negative zero or the first argument is negative infinity and the second argument is finite then the result is the
double
value closest to -pi/2.- If both arguments are positive infinity then the result is the
double
value closest to pi/4.- If the first argument is positive infinity and the second argument is negative infinity then the result is the
double
value closest to 3*pi/4.- If the first argument is negative infinity and the second argument is positive infinity then the result is the
double
value closest to -pi/4.- If both arguments are negative infinity then the result is the
double
value closest to -3*pi/4.A result must be within 2 ulps of the correctly rounded result. Results must be semi-monotonic.
@param a adouble
value. @param b adouble
value. @return the theta component of the point (r theta) in polar coordinates that corresponds to the point (b a) in Cartesian coordinates.
Returns the smallest (closest to negative infinity)Class Math, double cos(double)double
value that is not less than the argument and is equal to a mathematical integer. Special cases:Note that the value of
- If the argument value is already equal to a mathematical integer then the result is the same as the argument.
- If the argument is NaN or an infinity or positive zero or negative zero then the result is the same as the argument.
- If the argument value is less than zero but greater than -1.0 then the result is negative zero.
Math.ceil(x)
is exactly the value of-Math.floor(-x)
. @param a adouble
value. <--@return the value ⌈a
⌉.--> @return the smallest (closest to negative infinity)double
value that is not less than the argument and is equal to a mathematical integer.
Returns the trigonometric cosine of an angle. Special case:Class Math, double exp(double)
- If the argument is NaN or an infinity then the result is NaN.
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
@param a an angle in radians. @return the cosine of the argument.
Returns the exponential number e (i.e. 2.718...) raised to the power of aClass Math, double floor(double)double
value. Special cases:
- If the argument is NaN the result is NaN.
- If the argument is positive infinity then the result is positive infinity.
- If the argument is negative infinity then the result is positive zero.
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
@param a adouble
value. @return the value ea where e is the base of the natural logarithms.
Returns the largest (closest to positive infinity)Class Math, double log(double)double
value that is not greater than the argument and is equal to a mathematical integer.@paramSpecialacases:a@param a
- If
doublethe argument value is already equal to a mathematical integer then the result is the same as the argument.- If the argument is NaN or an infinity or positive zero or negative zero then the result is the same as the argument
.anaassigneddouble
value. <--@return the value ⌊a
⌋.--> @return the largest (closest to positive infinity)double
value that is not greater than the argument and is equal to a mathematical integer.
Returns the natural logarithm (base e) of aClass Math, double max(double, double)double
value. Special cases:
- If the argument is NaN or less than zero then the result is NaN.
- If the argument is positive infinity then the result is positive infinity.
- If the argument is positive zero or negative zero then the result is negative infinity.
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
@param a a number greater than0.0
. @return the value lna
the natural logarithm ofa
.
Returns the greater of twoClass Math, float max(float, float)double
values. That is the result is the argument closer to positive infinity. If the arguments have the same value the result is that same value. If either value isNaN
then the result isNaN
. Unlike the the numerical comparison operators this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero the result is positive zero. @param a adouble
value. @param b adouble
value. @return the larger ofa
andb
.
Returns the greater of twoClass Math, int max(int, int)float
values. That is the result is the argument closer to positive infinity. If the arguments have the same value the result is that same value. If either value isNaN
then the result isNaN
. Unlike the the numerical comparison operators this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero the result is positive zero. @param a afloat
value. @param b afloat
value. @return the larger ofa
andb
.
Returns the greater of twoClass Math, long max(long, long)int
values. That is the result is the argument closer to the value ofInteger.MAX_VALUE
. If the arguments have the same value the result is that same value. @param a anint
value. @param b anint
value. @return the larger ofa
andb
. @see java.lang.Long#MAX_VALUE
Returns the greater of twoClass Math, double min(double, double)long
values. That is the result is the argument closer to the value ofLong.MAX_VALUE
. If the argumens have the same value the result is that same value. @param a along
value. @param b along
value. @return the larger ofa
andb
. @see java.lang.Long#MAX_VALUE
Returns the smaller of twoClass Math, float min(float, float)double
values. That is the result is the value closer to negative infinity. If the arguments have the same value the result is that same value. If either value isNaN
then the result isNaN
. Unlike the the numerical comparison operators this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero the result is negative zero. @param a adouble
value. @param b adouble
value. @return the smaller ofa
andb
.
Returns the smaller of twoClass Math, int min(int, int)float
values. That is the result is the value closer to negative infinity. If the arguments have the same value the result is that same value. If either value isNaN
then the result isNaN
. Unlike the the numerical comparison operators this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero the result is negative zero. @param a afloat
value. @param b afloat
value. @return the smaller ofa
andb.
Returns the smaller of twoClass Math, long min(long, long)int
values. That is the result the argument closer to the value ofInteger.MIN_VALUE
. If the arguments have the same value the result is that same value. @param a anint
value. @param b anint
value. @return the smaller ofa
andb
. @see java.lang.Long#MIN_VALUE
Returns the smaller of twoClass Math, double pow(double, double)long
values. That is the result is the argument closer to the value ofLong.MIN_VALUE
. If the arguments have the same value the result is that same value. @param a along
value. @param b along
value. @return the smaller ofa
andb
. @see java.lang.Long#MIN_VALUE
Returns of value of the first argument raised to the power of the second argument. Special cases:Class Math, double random()
- If
(a ==the second argument is positive or negative zero then the result is 1.0.- If the second argument is 1.
0)thenbthemustresultbeis the same as the first argument.- If the second argument is NaN then
the result is NaN.- If the first argument is NaN and the second argument is nonzero then the result is NaN.
- If the absolute value of the first argument is
greater than01 and the second argument is positive infinity or the absolute value of the first argument is less than 1 and the second argument is negative infinity then the result is positive infinity.0;otherwise- If
anthe absolute value of the first argument is greater than 1 and the second argumentexceptionis negative infinity or the absolute value of the first argument is less than 1 and the second argument is positive infinity then the result isthrownpositive zero.An- If the
exception also will occur ifabsolute value of the first(a <= 0argument equals 1 and the second argument is infinite then the result is NaN.0)- If the first argument is
positive zero andbthe second argument is greater than zero or the first argument is positive infinity and the second argument is less than zero then the result is positive zero.- If the first argument is positive zero and the second argument is less than zero or the first argument is positive infinity and the second argument is greater than zero then the result is positive infinity.
- If the first argument
is negative zero and the second argument is greater than zero but notequalatofinite odd integer or the first argument is negative infinity and the second argument is less than zero but not awholefinite odd integernumberthen the result is positive zero.@param- If the first argument is negative zero and the second argument is a positive finite odd integer or the first argument is negative infinity and the second argument is a
doublenegativevaluefinite odd integer then the result is negative zero.@param- If
bthe first argument is negative zero and the second argument is less than zero but not adoublefinitevalueodd integer or the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer then the result is positive infinity.@return- If the
valuefirst argument is negative zero and the second argument is abnegative finite odd integer or the first argument is negative infinity and the second argument is a positive finite odd integer then the result is negative infinity.@exception- If the
ArithmeticException iffirst argument(is less than zero and the second argument is a== 0finite even integer then the result is equal to the result of raising the absolute value of the first argument to the power of the second argument.0)- If the first
argument is less than zero and(b <= 0the second argument is a finite odd integer then the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument.0)or- If the first argument is finite and less than zero and the second argument is finite and not an integer then the result is NaN.
- If both arguments are integers then the result is exactly equal to the mathematical result
of raising the first argument to the power of the second argument if(that result can in fact be represented exactly as a<= 0double value.0)(In the foregoing descriptions a floating-point value is considered to be an integer if
andbonly if it isnota fixed point of the method ceil or which is the same thing a fixed point of the method floor A value is a fixed point of a one-argument method if and only if the result of applying the method to the value is equal to the value.)A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic. @param
awholeadouble
value. @param b adouble
value. @return thenumbervalueab
.
Returns aClass Math, double rint(double)randomdouble
numbervalue with a positive sign greater than or equal to0.0
and less than1.0
. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.When this method is first called it creates a single new pseudorandom-number generator exactly as if by the expression
This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else.new java.util.RandomThis method is properly synchronized to allow correct use by more than one thread. However if many threads need to generate pseudorandom numbers at a great rate it may reduce contention for each thread to have its own pseudorandom-number generator. @return a pseudorandom
double
greater than or equal to0.0
and less than1.0
. @see java.util.Random#nextDouble()
Class Math, long round(double)returnsReturns theclosest integer to the argument. @param a adouble
value.@returnthattheis closestdoublein value toa
thatand is equal to a mathematical integer. If twodouble
values that are mathematical integers are equally close to the value of the argument the result is the integer value that is even. Special cases:@param a a
- If the argument value is already equal to a mathematical integer then the result is the same as the argument.
- If the argument is NaN or an infinity or positive zero or negative zero then the result is the same as the argument.
double
value. @return the closestdouble
value toa
that is equal to a mathematical integer.
Returns the closestClass Math, int round(float)long
to the argument. The result is rounded to an integer by adding 1/2 taking the floor of the result and casting the result to typelong
. In other words the result is equal to the value of the expression:(long)Math.floor(a + 0.5d)Special cases:
If the argument is negative infinity or any value less than or equal to the value of
- If the argument is NaN the result is 0.
Long.MIN_VALUE
the result is equal to the value ofLong.MIN_VALUE
.If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE
the result is equal to the value ofLong.MAX_VALUE
. @param a adouble
value. @return the value of the argument rounded to the nearestlong
value. @see java.lang.Long#MAX_VALUE @see java.lang.Long#MIN_VALUE
Returns the closestClass Math, double sin(double)int
to the argument. The result is rounded to an integer by adding 1/2 taking the floor of the result and casting the result to typeint
. In other words the result is equal to the value of the expression:(int)Math.floor(a + 0.5f)Special cases:
If the argument is negative infinity or any value less than or equal to the value of
- If the argument is NaN the result is 0.
Integer.MIN_VALUE
the result is equal to the value ofInteger.MIN_VALUE
.If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE
the result is equal to the value ofInteger.MAX_VALUE
. @param a afloat
value. @return the value of the argument rounded to the nearestint
value. @see java.lang.Integer#MAX_VALUE @see java.lang.Integer#MIN_VALUE
Returns the trigonometric sine of an angle. Special cases:Class Math, double sqrt(double)
- If the argument is NaN or an infinity then the result is NaN.
- If the argument is positive zero then the result is positive zero; if the argument is negative zero then the result is negative zero.
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
@param a an angle in radians. @return the sine of the argument.
Returns the correctly rounded positive square root of aClass Math, double tan(double)double
value. Special cases:Otherwise the result is the
- If the argument is NaN or less than zero then the result is NaN.
- If the argument is positive infinity then the result is positive infinity.
- If the argument is positive zero or negative zero then the result is the same as the argument.
double
value closest to the true mathetmatical square root of the argument value. @param a adouble
value. <--@return the value of √a
.--> @return the positive square root ofa
. If the argument is NaN or less than zero the result is NaN.
Returns the trigonometric tangent of an angle. Special cases:Class Math, double toDegrees(double)
- If the argument is NaN or an infinity then the result is NaN.
- If the argument is positive zero then the result is positive zero; if the argument is negative zero then the result is negative zero
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
@param a an angle in radians. @return the tangent of the argument.
Converts an angle measured in radians to the equivalent angle measured in degrees. @param angrad an angle in radians @return the measurement of the angleClass Math, double toRadians(double)angrad
in degrees. @sinceJDK11.2
Converts an angle measured in degrees to the equivalent angle measured in radians. @param angdeg an angle in degrees @return the measurement of the angleangdeg
in radians. @sinceJDK11.2
Thrown if an application tries to create an array with negative size. @author unascribed @version 1.14 0916 02/2102/9800 @since JDK1.0
Thrown if the Java Virtual Machine or a classloader tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using thenew
expression) and no definition of the class could be found.The searched-for class definition existed when the currently executing class was compiled but the definition can no longer be found. @author unascribed @version 1.
15 0917 02/2102/9800 @since JDK1.0
Thrown if an application tries to access or modify a specified field of an object and that object no longer has that field.Normally this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed. @author unascribed @version 1.
7 099 02/2102/9800 @since JDK1.0
Signals that the class doesn't have a field of a specified name. @author unascribed @version 1.Class NoSuchFieldException, constructor NoSuchFieldException(String)8 0911 02/2102/9800 @since JDK1.1
Constructor with a detail message. @param s the detail message
Thrown if an application tries to call a specified method of a class (either static or instance) and that class no longer has a definition of that method.Normally this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed. @author unascribed @version 1.
16 0918 02/2102/9800 @since JDK1.0
Thrown when a particular method cannot be found. @author unascribed @version 1.8 0910 02/2102/9800 @since JDK1.0
Thrown when an application attempts to usenull
in a case where an object is required. These include:
- Calling the instance method of a
null
object.- Accessing or modifying the field of a
null
object.- Taking the length of
null
as if it were an array.- Accessing or modifying the slots of
null
as if it were an array.- Throwing
null
as if it were aThrowable
value.Applications should throw instances of this class to indicate other illegal uses of the
null
object. @author unascribed @version 1.14 0916 02/2102/9800 @since JDK1.0
The abstract classNumber
is the superclass of classesByte
Double
Float
Integer
Long
andShort
.Subclasses of
Number
must provide methods to convert the represented numeric value tobyte
double
float
int
long
andshort
. @author Lee Boynton @author Arthur van Hoff @version 1.23 0925 02/2102/9800 @see java.lang.Byte @see java.lang.Double @see java.lang.Float @see java.lang.Integer @see java.lang.Long @see java.lang.Short @since JDK1.0
Thrown to indicate that the application has attempted to convert a string to one of the numeric types but that the string does not have the appropriate format. @author unascribed @version 1.14 0916 02/2102/9800 @see java.lang.Integer#toString() @since JDK1.0
ClassClass Object, void finalize()Object
is the root of the class hierarchy. Every class hasObject
as a superclass. All objects including arrays implement the methods of this class. @author unascribed @version 1.49 0454 02/2202/9900 @see java.lang.Class @since JDK1.0
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides theClass Object, String toString()finalize
method to dispose of system resources or to perform other cleanup.The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action including making this object available again to other threads; the usual purpose of finalize however is to perform cleanup actions before the object is irrevocably discarded. For example the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.
The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed however that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died including possible actions by other objects or classes which are ready to be finalized at which point the object may be discarded.
The finalize method is never invoked more than once by a Java virtual machine for any given object.
Any exception thrown by the
finalize
method causes the finalization of this object to be halted but is otherwise ignored. @throws Throwable theException
raised by this method
Returns a string representation of the object. In general theClass Object, void wait(long)toString
method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It isrecommendedthatrecommended that all subclasses override this method.The
toString
method for classObject
returns a string consisting of the name of the class of which the object is an instance the at-sign character `@
' and the unsigned hexadecimal representation of the hash code of the object. In other words this method returns a string equal to the value of:@return a string representation of the object.getClass().getName() + '@' + Integer.toHexString(hashCode())
Causes current thread to wait until either another thread invokes the java.lang.Object#notify() method or the java.lang.Object#notifyAll() method for this object or a specified amount of time has elapsed.Class Object, void wait(long, int)The current thread must own this object's monitor.
This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
The thread T is then removed from the wait set for this object and re-enabled for thread scheduling. It then competes in the usual manner with other threads for the right to synchronize on the object; once it has gained control of the object all its synchronization claims on the object are restored to the status quo ante - that is to the situation as of the time that the wait method was invoked. Thread T then returns from the invocation of the wait method. Thus on return from the wait method the synchronization state of the object and of thread T is exactly as it was when the wait method was invoked.
- Some other thread invokes the notify method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened.
- Some other thread invokes the notifyAll method for this object.
- Some other thread interrupts thread T.
- The specified amount of real time has elapsed more or less. If timeout is zero however then real time is not taken into consideration and the thread simply waits until notified.
If the current thread is interrupted by another thread while it is waiting then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
Note that the wait method as it places the current thread into the wait set for this object unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.
This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a description of the ways in which a thread can become the owner of a monitor. @param timeout the maximum time to wait in milliseconds. @exception IllegalArgumentException if the value of timeout is negative. @exception IllegalMonitorStateException if the current thread is not the owner of the object's monitor. @exception InterruptedException if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown. @see java.lang.Object#notify() @see java.lang.Object#notifyAll()
Causes current thread to wait until another thread invokes the java.lang.Object#notify() method or the java.lang.Object#notifyAll() method for this object or some other thread interrupts the current thread or a certain amount of real time has elapsed.This method is similar to the
wait
method of one argument but it allows finer control over the amount of time to wait for a notification before giving up. The amount of real time measured in nanoseconds is given by:1000000*millis+nanosIn all other respects this method does the same thing as the method #wait(long) of one argument. In particular wait(0 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:
- Another thread notifies threads waiting on this object's monitor to wake up either through a call to the
notify
method or thenotifyAll
method.- The timeout period specified by
timeout
milliseconds plusnanos
nanoseconds arguments has elapsed.The thread then waits until it can re-obtain ownership of the monitor and resumes execution
This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a description of the ways in which a thread can become the owner of a monitor. @param timeout the maximum time to wait in milliseconds. @paramnanonanos additional time in nanoseconds range 0-999999. @exception IllegalArgumentException if the value of timeout is negative or the value of nanos is not in the range 0-999999. @exception IllegalMonitorStateException if the current thread is not the owner of this object's monitor. @exception InterruptedException if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory and no more memory could be made available by the garbage collector. @author unascribed @version 1.16 0918 02/2102/9800 @since JDK1.0
Find a package by name in the callers classloader. The callers classloader is used to find the package instance corresponding to the named class. If the callers classloader is null then the set of packages loaded by the system classloader is searched to find the named package.Class Package, boolean isSealed(URL)Packages have attributes for versions and specifications only if the class loader created the package instance with the appropriate attributes. Typically those attributes are defined in the manifests that accompany the classes. @param
packageNamename a package name for example java.lang. @return the package of the requested name. It may be null if no package information is available from the archive or codebase.
Returns true if this package is sealed with respect to the specified code source url. @param url the code source url @return true if this package is sealed with respect to url
TheRuntime.exec
methods create a native process and return an instance of a subclass ofProcess
that can be used to control the process and obtain information about it. The classProcess
provides methods for performing input from the process performing output to the process waiting for the process to complete checking the exit status of the process and destroying (killing) the process.The
Runtime.exec
methods may not work well for special processes on certain native platforms such as native windowing processes daemon processes Win16/DOS processes on Win32 or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin stdout stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream()
Process.getInputStream()
Process.getErrorStream()
). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block and even deadlock.The subprocess is not killed when there are no more references to the
Process
object but rather the subprocess continues executing asynchronously.There is no requirement that a process represented by a
Process
object execute asynchronously or concurrently with respect to the Java process that owns theProcess
object. @author unascribed @version 1.15 0817 02/2602/9800 @see java.lang.Runtime#exec(java.lang.String) @see java.lang.Runtime#exec(java.lang.String java.lang.String[]) @see java.lang.Runtime#exec(java.lang.String[]) @see java.lang.Runtime#exec(java.lang.String[] java.lang.String[]) @since JDK1.0
TheRunnable
interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method of no arguments calledrun
.This interface is designed to provide a common protocol for objects that wish to execute code while they are active. For example
Runnable
is implemented by classThread
. Being active simply means that a thread has been started and has not yet been stopped.In addition
Runnable
provides the means for a class to be active while not subclassingThread
. A class that implementsRunnable
can run without subclassingThread
by instantiating aThread
instance and passing itself in as the target. In most cases theRunnable
interface should be used if you are only planning to override therun()
method and no otherThread
methods. This is important because classes should not be subclassed unless the programmer intends on modifying or enhancing the fundamental behavior of the class. @author Arthur van Hoff @version 1.19 0921 02/2102/9800 @see java.lang.Thread @since JDK1.0
Every Java application has a single instance of classClass Runtime, Process exec(String)Runtime
that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from thegetRuntime
method.An application cannot create its own instance of this class. @author unascribed @version 1.
48 0456 03/2620/00 @see java.lang.Runtime#getRuntime() @since JDK1.0
Executes the specified string command in a separate process.Class Runtime, Process exec(String, String[])The
command
argument is parsed into tokens and then executed as a command in a separate process. The token parsing is done by a java.util.StringTokenizer created by the call:with no further modifications of the character categories. This method has exactly the same effect asnew StringTokenizer(command)exec(command null)
. @param command a specified system command. @return aProcess
object for managing the subprocess. @exception SecurityException if a security manager exists and itscheckExec
method doesn't allow creation of a subprocess. @exception IOException if an I/O error occurs @see java.lang.Runtime#exec(java.lang.String java.lang.String[]) @see java.lang.SecurityManager#checkExec(java.lang.String)
Executes the specified string command in a separate process with the specified environment.Class Runtime, void exit(int)This method breaks the
command
string into tokens and creates a new arraycmdarray
containing the tokens in the order that they were produced by the string tokenizer; it then performs the callexec(cmdarray envp)
. The token parsing is done by a java.util.StringTokenizer created by the call:with no further modification of the character categories.new StringTokenizer(command)The environment variable settings are specified by envp. If envp is null the subprocess inherits the environment settings of the current process. @param
commandcmd a specified system command. @param envp array of strings each element of which has environment variable settings in format name=value. @return aProcess
object for managing the subprocess. @exception SecurityException if a security manager exists and itscheckExec
method doesn't allow creation of a subprocess. @exception IOException if an I/O error occurs @see java.lang.Runtime#exec(java.lang.String[]) @see java.lang.Runtime#exec(java.lang.String[] java.lang.String[]) @see java.lang.SecurityManager#checkExec(java.lang.String)
Terminates the currently running JavaClass Runtime, InputStream getLocalizedInputStream(InputStream)VirtualvirtualMachinemachine by initiating its shutdown sequence. This method never returns normally. The argument serves as a status code; by convention a nonzero status code indicates abnormal termination.
FirstThe virtual machine's shutdown sequence constists of two phases. In the first phase all registered shutdow hooks} if any are started in some unspecified order and allowed to run concurrently until they finish. In the second phase all uninvoked finalizers are run iftherefinalization-on-exit has been enabled. Once this isa security manager itsdone the virtual machinecheckExithaltsIf this method is
called withinvoked after thestatusvirtualasmachine has begun itsargument.shutdownThis may result in asequence then if shutdown hookssecurityare being run this method willexceptionblock indefinitely.The argument serves as a statusIf shutdown hooks have already been runcode;andbyon-exitconvention afinalization hasnonzerobeen enabled then this method halts the virtual machine with the given status codeindicates abnormalif theterminationstatus is nonzero; otherwise it blocks indefinitely.The
method{@link System#exit(int) System.exit} method is the conventional and convenient means of invoking this method.@param status
exitTermination status. By convention a nonzero status code indicates abnormal termination. @throws SecurityExceptionifIf a security managerexistsis present and its {@link SecurityManager#checkExit checkExit} methoddoesn'tdoesallownotexitpermit exiting with the specified status.@see java.lang.SecurityException @see java.lang.SecurityManager#checkExit(int) @see #addShutdownHook @see #removeShutdownHook @see #runFinalizersOnExit @see #halt(int)
Creates a localized version of an input stream. This method takes anClass Runtime, OutputStream getLocalizedOutputStream(OutputStream)InputStream
and returns anInputStream
equivalent to the argument in all respects except that it is localized: as characters in the local character set are read from the stream they are automatically converted from the local character set to Unicode.If the argument is already a localized stream it may be returned as the result. @param in InputStream to localize @return a localized input stream @see java.io.InputStream @see java.io.BufferedReader#BufferedReader(java.io.Reader) @see java.io.InputStreamReader#InputStreamReader(java.io.InputStream) @deprecated As of JDK 1.1 the preferred way translate a byte stream in the local encoding into a character stream in Unicode is via the
InputStreamReader
andBufferedReader
classes.@return a localized input stream. @see java.io.InputStream @see java.io.BufferedReader#BufferedReader(java.io.Reader) @see java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
Creates a localized version of an output stream. This method takes anClass Runtime, void runFinalizersOnExit(boolean)OutputStream
and returns anOutputStream
equivalent to the argument in all respects except that it is localized: as Unicode characters are written to the stream they are automatically converted to the local character set.If the argument is already a localized stream it may be returned as the result. @deprecated As of JDK 1.1 the preferred way to translate a Unicode character stream into a byte stream in the local encoding is via the
OutputStreamWriter
BufferedWriter
andPrintWriter
classes. @param out OutputStream to localize @return a localized output stream.@see java.io.OutputStream @see java.io.BufferedWriter#BufferedWriter(java.io.Writer) @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream) @see java.io.PrintWriter#PrintWriter(java.io.OutputStream)
Enable or disable finalization on exit; doing so specifies that the finalizers of all objects that have finalizers that have not yet been automatically invoked are to be run before the Java runtime exits. By default finalization on exit is disabled.If there is a security manager its
checkExit
method is first called with 0 as its argument to ensure the exit is allowed. This could result in a SecurityException. @param value true to enable finalization on exit false to disable @deprecated This method is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects resulting in erratic behavior or deadlock. @throws SecurityException if a security manager exists and itscheckExit
method doesn't allow the exit. @see java.lang.Runtime#exit(int) @see java.lang.Runtime#gc() @see java.lang.SecurityManager#checkExit(int) @since JDK1.1
RuntimeException
is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.A method is not required to declare in its
throws
clause any subclasses ofRuntimeException
that might be thrown during the execution of the method but not caught. @author Frank Yellin @version 1.7 099 02/2102/9800 @since JDK1.0
This class is for runtime permissions. A RuntimePermission contains a name (also referred to as a "target name") but no actions list; you either have the named permission or you don't.The target name is the name of the runtime permission (see below). The naming convention follows the hierarchical property naming convention. Also an asterisk may appear at the end of the name following a "." or by itself to signify a wildcard match. For example: "loadLibrary.*" or "*" is valid "*loadLibrary" or "a*b" is not valid.
The following table lists all the possible RuntimePermission target names and for each provides a description of what the permission allows and a discussion of the risks of granting code the permission.
@see java.security.BasicPermission @see java.security.Permission @see java.security.Permissions @see java.security.PermissionCollection @see java.lang.SecurityManager @version 1.
Permission Target Name What the Permission Allows Risks of Allowing this Permission createClassLoader Creation of a class loader This is an extremely dangerous permission to grant. Malicious applications that can instantiate their own class loaders could then load their own rogue classes into the system. These newly loaded classes could be placed into any protection domain by the class loader thereby automatically granting the classes the permissions for that domain. getClassLoader Retrieval of a class loader (e.g. the class loader for the calling class) This would grant an attacker permission to get the class loader for a particular class. This is dangerous because having access to a class's class loader allows the attacker to load other classes available to that class loader. The attacker would typically otherwise not have access to those classes. setContextClassLoader Setting of the context class loader used by a thread The context class loader is used by system code and extensions when they need to lookup resources that might not exist in the system class loader. Granting setContextClassLoader permission would allow code to change which context class loader is used for a particular thread including system threads. setSecurityManager Setting of the security manager (possibly replacing an existing one) The security manager is a class that allows applications to implement a security policy. Granting the setSecurityManager permission would allow code to change which security manager is used by installing a different possibly less restrictive security manager thereby bypassing checks that would have been enforced by the original security manager. createSecurityManager Creation of a new security manager This gives code access to protected sensitive methods that may disclose information about other classes or the execution stack. exitVM Halting of the Java Virtual Machine This allows an attacker to mount a denial-of-service attack by automatically forcing the virtual machine to halt. shutdownHooks Registration and cancellation of virtual-machine shutdown hooks This allows an attacker to register a malicious shutdown hook that interferes with the clean shutdown of the virtual machine. setFactory Setting of the socket factory used by ServerSocket or Socket or of the stream handler factory used by URL This allows code to set the actual implementation for the socket server socket stream handler or RMI socket factory. An attacker may set a faulty implementation which mangles the data stream. setIO Setting of System.out System.in and System.err This allows changing the value of the standard system streams. An attacker may change System.in to monitor and steal user input or may set System.err to a "null" OutputSteam which would hide any error messages sent to System.err. modifyThread Modification of threads e.g. via calls to Thread stop
suspend
resume
setPriority
andsetName
methodsThis allows an attacker to start or suspend any thread in the system. stopThread Stopping of threads via calls to the Thread stop
methodThis allows code to stop any thread in the system provided that it is already granted permission to access that thread. This poses as a threat because that code may corrupt the system by killing existing threads. modifyThreadGroup modification of thread groups e.g. via calls to ThreadGroup destroy
getParent
resume
setDaemon
setMaxPriority
stop
andsuspend
methodsThis allows an attacker to create thread groups and set their run priority. getProtectionDomain Retrieval of the ProtectionDomain for a class This allows code to obtain policy information for a particular code source. While obtaining policy information does not compromise the security of the system it does give attackers additional information such as local file names for example to better aim an attack. readFileDescriptor Reading of file descriptors This would allow code to read the particular file associated with the file descriptor read. This is dangerous if the file contains confidential data. writeFileDescriptor Writing to file descriptors This allows code to write to a particular file associated with the descriptor. This is dangerous because it may allow malicous code to plant viruses or at the very least fill up your entire disk. loadLibrary.{library name} Dynamic linking of the specified library It is dangerous to allow an applet permission to load native code libraries because the Java security architecture is not designed to and does not prevent malicious behavior at the level of native code. accessClassInPackage.{package name} Access to the specified package via a class loader's loadClass
method when that class loader calls the SecurityManagercheckPackageAcesss
methodThis gives code access to classes in packages to which it normally does not have access. Malicious code may use these classes to help in its attempt to compromise security in the system. defineClassInPackage.{package name} Definition of classes in the specified package via a class loader's defineClass
method when that class loader calls the SecurityManagercheckPackageDefinition
method.This grants code permission to define a class in a particular package. This is dangerous because malicious code with this permission may define rogue classes in trusted packages like java.security
orjava.lang
for example.accessDeclaredMembers Access to the declared members of a class This grants code permission to query a class for its public protected default (package) access and private fields and/or methods. Although the code would have access to the private and protected field and method names it would not have access to the private/protected field data and would not be able to invoke any private methods. Nevertheless malicious code may use this information to better aim an attack. Additionally it may invoke any public methods and/or access public fields in the class. This could be dangerous if the code would normally not be able to invoke those methods and/or access the fields because it can't cast the object to the class/interface with those methods and fields. queuePrintJob Initiation of a print job request This could print sensitive information to a printer or simply waste paper. 33 9937 00/0402/2202 @author Marianne Mueller @author Roland Schemers
Thrown by the security manager to indicate a security violation. @author unascribed @version 1.9 0911 02/2102/9800 @see java.lang.SecurityManager @since JDK1.0
The security manager is a class that allows applications to implement a security policy. It allows an application to determine before performing a possibly unsafe or sensitive operation what the operation is and whether it is being attempted in a security context that allows the operation to be performed. The application can allow or disallow the operation.Class SecurityManager, void checkAccept(String, int)The
SecurityManager
class contains many methods with names that begin with the wordcheck
. These methods are called by various methods in the Java libraries before those methods perform certain potentially sensitive operations. The invocation of such acheck
method typically looks like this:SecurityManager security = System.getSecurityManager(); if (security = null) { security.checkXXX(argument . . . ); }The security manager is thereby given an opportunity to prevent completion of the operation by throwing an exception. A security manager routine simply returns if the operation is permitted but throws a
SecurityException
if the operation is not permitted. The only exception to this convention ischeckTopLevelWindow
which returns aboolean
value.The current security manager is set by the
setSecurityManager
method in classSystem
. The current security manager is obtained by thegetSecurityManager
method.The special method SecurityManager#checkPermission(java.security.Permission) determines whether an access request indicated by a specified permission should be granted or denied. The default implementation calls
AccessController.checkPermission(perm);If a requested access is allowed
checkPermission
returns quietly. If denied aSecurityException
is thrown.As of
JDKJava12 SDK v1.2 the default implementation of each of the othercheck
methods inSecurityManager
is to call theSecurityManager checkPermission
method to determine if the calling thread has permission to perform the requested operation.Note that the
checkPermission
method with just a single permission argument always performs security checks within the context of the currently executing thread. Sometimes a security check that should be made within a given context will actually need to be done from within a different context (for example from within a worker thread). The getSecurityContext method and the java.lang.Object checkPermission} method that includes a context argument are provided for this situation. ThegetSecurityContext
method returns a "snapshot" of the current calling context. (The default implementation returns an AccessControlContext object.) A sample call is the following:Object context = null; SecurityManager sm = System.getSecurityManager(); if (sm = null) context = sm.getSecurityContext();The
checkPermission
method that takes a context object in addition to a permission makes access decisions based on that context rather than on that of the current execution thread. Code within a different context can thus call that method passing the permission and the previously-saved context object. A sample call using the SecurityManagersm
obtained as in the previous example is the following:if (sm = null) sm.checkPermission(permission context);Permissions fall into these categories: File Socket Net Security Runtime Property AWT Reflect and Serializable. The classes managing these various permission categories are
java.io.FilePermission
java.net.SocketPermission
java.net.NetPermission
java.security.SecurityPermission
java.lang.RuntimePermission
java.util.PropertyPermission
java.awt.AWTPermission
java.lang.reflect.ReflectPermission
andjava.io.SerializablePermission
.All but the first two (FilePermission and SocketPermission) are subclasses of
java.security.BasicPermission
which itself is an abstract subclass of the top-level class for permissions which isjava.security.Permission
. BasicPermission defines the functionality needed for all permissions that contain a name that follows the hierarchical property naming convention (for example "exitVM" "setFactory" "queuePrintJob" etc). An asterisk may appear at the end of the name following a "." or by itself to signify a wildcard match. For example: "a.*" or "*" is valid "*a" or "a*b" is not valid.FilePermission and SocketPermission are subclasses of the top-level class for permissions (
java.security.Permission
). Classes like these that have a more complicated name syntax than that used by BasicPermission subclass directly from Permission rather than from BasicPermission. For example for ajava.io.FilePermission
object the permission name is the pathname of a file (or directory).Some of the permission classes have an "actions" list that tells the actions that are permitted for the object. For example for a
java.io.FilePermission
object the actions list (such as "read write") specifies which actions are granted for the specified file (or for files in the specified directory).Other permission classes are for "named" permissions - ones that contain a name but no actions list; you either have the named permission or you don't.
Note: There is also a
java.security.AllPermission
permission that implies all permissions. It exists to simplify the work of system administrators who might need to perform multiple tasks that require all (or numerous) permissions.See Permissions in
JDK1.the Java 2 SDK for permission-related information. This document includes for example a table listing the various SecurityManagercheck
methods and the permission(s) the default implementation of each such method requires. It also contains a table of all theJDKversion 1.2 methods that require permissions and for each such method tells which permission it requires.For more information about
SecurityManager
changes made inJDKthe1.Java 2 SDK and advice regarding porting of 1.1-style security managers see thereleasesecurity documentationat http://java.sun.com/products/jdk/1.2/docs/guide/security/index.html. @author Arthur van Hoff @author Roland Schemers @version 1.107 04121 02/2202/9900 @see java.lang.ClassLoader @see java.lang.SecurityException @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object) checkTopLevelWindow @see java.lang.System#getSecurityManager() getSecurityManager @see java.lang.System#setSecurityManager(java.lang.SecurityManager) setSecurityManager @see java.security.AccessController AccessController @see java.security.AccessControlContext AccessControlContext @see java.security.AccessControlException AccessControlException @see java.security.Permission @see java.security.BasicPermission @see java.io.FilePermission @see java.net.SocketPermission @see java.util.PropertyPermission @see java.lang.RuntimePermission @see java.awt.AWTPermission @see java.security.Policy Policy @see java.security.SecurityPermission SecurityPermission @see java.security.ProtectionDomain @since JDK1.0
Throws aClass SecurityManager, void checkAccess(Thread)SecurityException
if the calling thread is not permitted to accept a socket connection from the specified host and port number.This method is invoked for the current security manager by the
accept
method of classServerSocket
.This method calls
checkPermission
with theSocketPermission(host+":"+port "accept")
permission.If you override this method then you should make a call to
super.checkAccept
at the point the overridden method would normally throw an exception. @param host the host name of the socket connection. @param port the port number of the socket connection. @exception SecurityException if the calling thread does not have permission to accept the connection. @exception NullPointerException if thehost
argument isnull
. @see java.net.ServerSocket#accept() @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkAccess(ThreadGroup)SecurityException
if the calling thread is not allowed to modify the thread argument.This method is invoked for the current security manager by the
stop
suspend
resume
setPriority
setName
andsetDaemon
methods of classThread
.If the thread argument is a system thread (belongs to the thread group with a
null
parent) then this method callscheckPermission
with theRuntimePermission("modifyThread")
permission. If the thread argument is not a system thread this method just returns silently.Applications that want a stricter policy should override this method. If this method is overridden the method that overrides it should additionally check to see if the calling thread has the
RuntimePermission("modifyThread")
permission and if so return silently. This is to ensure that code granted that permission (such as theJDKSDK itself) is allowed to manipulate any thread.If this method is overridden then
super.checkAccess
should be called by the first statement in the overridden method or the equivalent security check should be placed in the overridden method. @param t the thread to be checked. @exception SecurityException if the calling thread does not have permission to modify the thread. @exception NullPointerException if the thread argument isnull
. @see java.lang.Thread#resume() resume @see java.lang.Thread#setDaemon(boolean) setDaemon @see java.lang.Thread#setName(java.lang.String) setName @see java.lang.Thread#setPriority(int) setPriority @see java.lang.Thread#stop() stop @see java.lang.Thread#suspend() suspend @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkConnect(String, int)SecurityException
if the calling thread is not allowed to modify the thread group argument.This method is invoked for the current security manager when a new child thread or child thread group is created and by the
setDaemon
setMaxPriority
stop
suspend
resume
anddestroy
methods of classThreadGroup
.If the thread group argument is the system thread group ( has a
null
parent) then this method callscheckPermission
with theRuntimePermission("modifyThreadGroup")
permission. If the thread group argument is not the system thread group this method just returns silently.Applications that want a stricter policy should override this method. If this method is overridden the method that overrides it should additionally check to see if the calling thread has the
RuntimePermission("modifyThreadGroup")
permission and if so return silently. This is to ensure that code granted that permission (such as theJDKSDK itself) is allowed to manipulate any thread.If this method is overridden then
super.checkAccess
should be called by the first statement in the overridden method or the equivalent security check should be placed in the overridden method. @param g the thread group to be checked. @exception SecurityException if the calling thread does not have permission to modify the thread group. @exception NullPointerException if the thread group argument isnull
. @see java.lang.ThreadGroup#destroy() destroy @see java.lang.ThreadGroup#resume() resume @see java.lang.ThreadGroup#setDaemon(boolean) setDaemon @see java.lang.ThreadGroup#setMaxPriority(int) setMaxPriority @see java.lang.ThreadGroup#stop() stop @see java.lang.ThreadGroup#suspend() suspend @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkConnect(String, int, Object)SecurityException
if the calling thread is not allowed to open a socket connection to the specified host and port number.A port number of
-1
indicates that the calling method is attempting to determine the IP address of the specified host name.This method calls
checkPermission
with theSocketPermission(host+":"+port "connect")
permission if the port is not equal to -1. If the port is equal to -1 then it callscheckPermission
with theSocketPermission(host "resolve")
permission.If you override this method then you should make a call to
super.checkConnect
at the point the overridden method would normally throw an exception. @param host the host name port to connect to. @param port the protocol port to connect to. @exception SecurityException if the calling thread does not have permission to open a socket connection to the specifiedhost
andport
. @exception NullPointerException if thehost
argument isnull
. @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkDelete(String)SecurityException
if the specified security context is not allowed to open a socket connection to the specified host and port number.A port number of
-1
indicates that the calling method is attempting to determine the IP address of the specified host name.If
context
is not an instance ofAccessControlContext
then aSecurityException
is thrown.Otherwise the port number is checked. If it is not equal to -1 the
context
'scheckPermission
method is called with aSocketPermission(host+":"+port "connect")
permission. If the port is equal to -1 then thecontext
'scheckPermission
method is called with aSocketPermission(host "resolve")
permission.If you override this method then you should make a call to
super.checkConnect
at the point the overridden method would normally throw an exception. @param host the host name port to connect to. @param port the protocol port to connect to. @param context a system-dependent security context. @exception SecurityException if the specified security context is not an instance ofAccessControlContext
(e.g. isnull
) or does not have permission to open a socket connection to the specifiedhost
andport
. @exception NullPointerException if thehost
argument isnull
. @see java.lang.SecurityManager#getSecurityContext() @see java.security.AccessControlContext#checkPermission(java.security.Permission)
Throws aClass SecurityManager, void checkExec(String)SecurityException
if the calling thread is not allowed to delete the specified file.This method is invoked for the current security manager by the
delete
method of classFile
.This method calls
checkPermission
with theFilePermission(file "delete")
permission.If you override this method then you should make a call to
super.checkDelete
at the point the overridden method would normally throw an exception. @param file the system-dependent filename. @exception SecurityException if the calling thread does not have permission to delete the file. @exception NullPointerException if thefile
argument isnull
. @see java.io.File#delete() @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkLink(String)SecurityException
if the calling thread is not allowed to create a subprocess.This method is invoked for the current security manager by the
exec
methods of classRuntime
.This method calls
checkPermission
with theFilePermission(cmd "execute")
permission if cmd is an absolute path otherwise it callscheckPermission
withFilePermission("<<ALL FILES>>" "execute")
.If you override this method then you should make a call to
super.checkExec
at the point the overridden method would normally throw an exception. @param cmd the specified system command. @exception SecurityException if the calling thread does not have permission to create a subprocess. @exception NullPointerException if thecmd
argument isnull
. @see java.lang.Runtime#exec(java.lang.String) @see java.lang.Runtime#exec(java.lang.String java.lang.String[]) @see java.lang.Runtime#exec(java.lang.String[]) @see java.lang.Runtime#exec(java.lang.String[] java.lang.String[]) @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkMemberAccess(Class, int)SecurityException
if the calling thread is not allowed to dynamic link the library code specified by the string argument file. The argument is either a simple library name or a complete filename.This method is invoked for the current security manager by methods
load
andloadLibrary
of classRuntime
.This method calls
checkPermission
with theRuntimePermission("loadLibrary."+lib)
permission.If you override this method then you should make a call to
super.checkLink
at the point the overridden method would normally throw an exception. @param lib the name of the library. @exception SecurityException if the calling thread does not have permission to dynamically link the library. @exception NullPointerException if thelib
argument isnull
. @see java.lang.Runtime#load(java.lang.String) @see java.lang.Runtime#loadLibrary(java.lang.String) @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkMulticast(InetAddress)SecurityException
if the calling thread is not allowed to access members.The default policy is to allow access to PUBLIC members as well as access to classes that have the same class loader as the caller. In all other cases this method calls
checkPermission
with theRuntimePermission("accessDeclaredMembers")
permission.If this method is overridden then a call to
super.checkMemberAccess
cannot be made as the default implementation ofcheckMemberAccess
relies on the code being checked being at a stack depth of 4. @param clazz the class that reflection is to be performed on. @param which type of access PUBLIC or DECLARED. @exception SecurityException if the caller does not have permission to access members. @exception NullPointerException if theclazz
argument isnull
. @see java.lang.reflect.Member @since JDK1.1 @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkMulticast(InetAddress, byte)SecurityException
if the calling thread is not allowed to use (join/leave/send/receive) IP multicast.This method calls
checkPermission
with thejava.net.SocketPermission(maddr.getHostAddress() "accept connect")
permission.If you override this method then you should make a call to
super.checkMulticast
at the point the overridden method would normally throw an exception. @param maddr Internet group address to be used. @exception SecurityException if the calling thread is not allowed to use (join/leave/send/receive) IP multicast. @exception NullPointerException if the address argument isnull
. @since JDK1.1 @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkPackageAccess(String)SecurityException
if the calling thread is not allowed to use (join/leave/send/receive) IP multicast.This method calls
checkPermission
with thejava.net.SocketPermission(maddr.getHostAddress() "accept connect")
permission.If you override this method then you should make a call to
super.checkMulticast
at the point the overridden method would normally throw an exception. @param maddr Internet group address to be used. @param ttl value in use if it is multicast send. Note: this particular implementation does not use the ttl parameter. @exception SecurityException if the calling thread is not allowed to use (join/leave/send/receive) IP multicast. @exception NullPointerException if the address argument isnull
. @since JDK1.1 @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkPermission(Permission)SecurityException
if the calling thread is not allowed to access the package specified by the argument.This method is used by the
loadClass
method of class loaders.This method first gets a list of restricted packages by obtaining a comma-separated list from a call to
java.security.Security.getProperty("package.access")
and checks to see ifpkg
starts with or equals any of the restricted packages. If it does thencheckPermission
gets called with theRuntimePermission("accessClassInPackage."+pkg)
permission.If this method is overridden then
super.checkPackageAccess
should be called as the first line in the overridden method. @param pkg the package name. @exception SecurityException if the calling thread does not have permission to access the specified package. @exception NullPointerException if the package name argument isnull
. @see java.lang.ClassLoader#loadClass(java.lang.String boolean) loadClass @see java.security.Security#getProperty getProperty @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkPermission(Permission, Object)SecurityException
if the requested access specified by the given permission is not permitted based on the security policy currently in effect.This method calls
AccessController.checkPermission
with the given permission. @param perm the requested permission. @exception SecurityException if access is not permitted based on the current security policy. @exception NullPointerException if the permission argument isnull
. @sinceJDK11.2
Throws aClass SecurityManager, void checkPropertyAccess(String)SecurityException
if the specified security context is denied access to the resource specified by the given permission. The context must be a security context returned by a previous call togetSecurityContext
and the access control decision is based upon the configured security policy for that security context.If
context
is an instance ofAccessControlContext
then theAccessControlContext.checkPermission
method is invoked with the specified permission.If
context
is not an instance ofAccessControlContext
then aSecurityException
is thrown. @param perm the specified permission @param context a system-dependent security context. @exception SecurityException if the specified security context is not an instance ofAccessControlContext
(e.g. isnull
) or is denied access to the resource specified by the given permission. @exception NullPointerException if the permission argument isnull
. @see java.lang.SecurityManager#getSecurityContext() @see java.security.AccessControlContext#checkPermission(java.security.Permission) @sinceJDK11.2
Throws aClass SecurityManager, void checkRead(FileDescriptor)SecurityException
if the calling thread is not allowed to access the system property with the specifiedkey
name.This method is used by the
getProperty
method of classSystem
.This method calls
checkPermission
with thePropertyPermission(key "read")
permission.
If you override this method then you should make a call to
super.checkPropertyAccess
at the point the overridden method would normally throw an exception. @param key a system property key. @exception SecurityException if the calling thread does not have permission to access the specified system property. @exception NullPointerException if thekey
argument isnull
. @exception IllegalArgumentException ifkey
is empty. @see java.lang.System#getProperty(java.lang.String) @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkRead(String)SecurityException
if the calling thread is not allowed to read from the specified file descriptor.This method calls
checkPermission
with theRuntimePermission("readFileDescriptor")
permission.If you override this method then you should make a call to
super.checkRead
at the point the overridden method would normally throw an exception. @param fd the system-dependent file descriptor. @exception SecurityException if the calling thread does not have permission to access the specified file descriptor. @exception NullPointerException if the file descriptor argument isnull
. @see java.io.FileDescriptor @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkRead(String, Object)SecurityException
if the calling thread is not allowed to read the file specified by the string argument.This method calls
checkPermission
with theFilePermission(file "read")
permission.If you override this method then you should make a call to
super.checkRead
at the point the overridden method would normally throw an exception. @param file the system-dependent file name. @exception SecurityException if the calling thread does not have permission to access the specified file. @exception NullPointerException if thefile
argument isnull
. @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkSecurityAccess(String)SecurityException
if the specified security context is not allowed to read the file specified by the string argument. The context must be a security context returned by a previous call togetSecurityContext
.If
context
is an instance ofAccessControlContext
then theAccessControlContext.checkPermission
method will be invoked with theFilePermission(file "read")
permission.If
context
is not an instance ofAccessControlContext
then aSecurityException
is thrown.If you override this method then you should make a call to
super.checkRead
at the point the overridden method would normally throw an exception. @param file the system-dependent filename. @param context a system-dependent security context. @exception SecurityException if the specified security context is not an instance ofAccessControlContext
(e.g. isnull
) or does not have permission to read the specified file. @exception NullPointerException if thefile
argument isnull
. @see java.lang.SecurityManager#getSecurityContext() @see java.security.AccessControlContext#checkPermission(java.security.Permission)
Determines whether the permission with the specified permission target name should be granted or denied.Class SecurityManager, boolean checkTopLevelWindow(Object)If the requested permission is allowed this method returns quietly. If denied a SecurityException is raised.
This method creates a
SecurityPermission
object for the given permission target name and callscheckPermission
with it.See the documentation for
{@link java.security.SecurityPermission}
for a list of possible permission target names.If you override this method then you should make a call to
super.checkSecurityAccess
at the point the overridden method would normally throw an exception. @param target the target name of theSecurityPermission
. @exception SecurityException if the calling thread does not have permission for the requested access. @exception NullPointerException iftarget
is null. @exception IllegalArgumentException iftarget
is empty. @since JDK1.1 @see #checkPermission(java.security.Permission) checkPermission
ReturnsClass SecurityManager, void checkWrite(FileDescriptor)false
if the calling thread is not trusted to bring up the top-level window indicated by thewindow
argument. In this case the caller can still decide to show the window but the window should include some sort of visual warning. If the method returnstrue
then the window can be shown without any special restrictions.See class
Window
for more information on trusted and untrusted windows.This method calls
checkPermission
with theAWTPermission("showWindowWithoutWarningBanner")
permission and returnstrue
if a SecurityException is not thrown otherwise it returnsfalse
.If you override this method then you should make a call to
super.checkTopLevelWindow
at the point the overridden method would normally returnfalse
and the value ofsuper.checkTopLevelWindow
should be returned. @param window the new window that is being created. @returntrue
if the calling thread is trusted to put up top-level windows;false
otherwise. @exception SecurityException if creation is disallowed entirely. @exception NullPointerException if thewindow
argument isnull
. @see java.awt.Window @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, void checkWrite(String)SecurityException
if the calling thread is not allowed to write to the specified file descriptor.This method calls
checkPermission
with theRuntimePermission("writeFileDescriptor")
permission.If you override this method then you should make a call to
super.checkWrite
at the point the overridden method would normally throw an exception. @param fd the system-dependent file descriptor. @exception SecurityException if the calling thread does not have permission to access the specified file descriptor. @exception NullPointerException if the file descriptor argument isnull
. @see java.io.FileDescriptor @see #checkPermission(java.security.Permission) checkPermission
Throws aClass SecurityManager, ThreadGroup getThreadGroup()SecurityException
if the calling thread is not allowed to write to the file specified by the string argument.This method calls
checkPermission
with theFilePermission(file "write")
permission.If you override this method then you should make a call to
super.checkWrite
at the point the overridden method would normally throw an exception. @param file the system-dependent filename. @exception SecurityException if the calling thread does not have permission to access the specified file. @exception NullPointerException if thefile
argument isnull
. @see #checkPermission(java.security.Permission) checkPermission
Returns the thread group into which to instantiate any new thread being created at the time this is being called. By default it returns the thread group of the current thread. This should be overridden by a specific security manager to return the appropriate thread group. @return ThreadGroup that new threads are instantiated into @since JDK1.1 @see java.lang.ThreadGroup
The Short class is the standard wrapper for short values. @author Nakul Saraiya @version 1.Class Short, int compareTo(Object)15 0822 02/0302/9800 @see java.lang.Number @since JDK1.1
Compares this Short to another Object. If the Object is a Short this function behaves likeClass Short, int compareTo(Short)compareTo(Short)
. Otherwise it throws aClassCastException
(as Shorts are comparable only to other Shorts). @param o theObject
to be compared. @return the value0
if the argument is a Short numerically equal to this Short; a value less than0
if the argument is a Short numerically greater than this Short; and a value greater than0
if the argument is a Short numerically less than this Short. @exceptionClassCastException
if the argument is not aShort
. @see java.lang.Comparable @sinceJDK11.2
Compares two Shorts numerically. @param anotherShort theClass Short, Short decode(String)Short
to be compared. @return the value0
if the argument Short is equal to this Short; a value less than0
if this Short is numerically less than the Short argument; and a value greater than0
if this Short is numerically greater than the Short argument (signed comparison). @sinceJDK11.2
Decodes aClass Short, short parseShort(String)String
into aShort
. Accepts decimal hexadecimal and octal numbers in the following formats:[-] decimal constant [-] 0x hex constant [-] # hex constant [-] 0 octal constantThe constant following an (optional) negative sign and/or "radix specifier" is parsed as by theShort.parseShort
method with the specified radix (10 8 or 16). This constant must be positive or a NumberFormatException will result. The result is made negative if first character of the specifiedString
is the negative sign. No whitespace characters are permitted in theString
. @param nm theString
to decode. @return theShort
represented by the specified string. @exception NumberFormatException if theString
does not contain a parsable short. @see java.lang.Short#parseShort(String int)
Assuming the specified String represents a short returns that short's value. Throws an exception if the String cannot be parsed as a short. The radix is assumed to be 10. @param s the String containing the short @return short the value represented by the specified string @exception NumberFormatException If the string does not contain a parsable short.Class Short, short parseShort(String, int)
Assuming the specified String represents a short returns that short's value. Throws an exception if the String cannot be parsed as a short. @param s the String containing the short @param radix the radix to be used @return The short value represented by the specified string in the specified radix. @exception NumberFormatException If the String does not contain a parsable short.Class Short, String toString(short)
Returns a new String object representing the specified Short. The radix is assumed to be 10. @param s the short to be converted @return The String that represents the specified short in radix 10.Class Short, Short valueOf(String)
Assuming the specified String represents a short returns a new Short object initialized to that value. Throws an exception if the String cannot be parsed as a short. @param s the String containing the integer @return Short of the value represented by the specified string in radix 10. @exception NumberFormatException If the String does not contain a parsable short.Class Short, Short valueOf(String, int)
Assuming the specified String represents a short returns a new Short object initialized to that value. Throws an exception if the String cannot be parsed as a short. @param s the String containing the integer @param radix the radix to be used @return The Short value represented by the specified string in the specified radix. @exception NumberFormatException If the String does not contain a parsable short.
Thrown when a stack overflow occurs because an application recurses too deeply. @author unascribed @version 1.16 0918 02/2102/9800 @since JDK1.0
TheClass String, constructor String(byte[], String)String
class represents character strings. All string literals in Java programs such as"abc"
are implemented as instances of this class.Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example:
String str = "abc";is equivalent to:
char data[] = {'a' 'b' 'c'}; String str = new String(data);Here are some more examples of how strings can be used:
System.out.println("abc"); String cde = "cde"; System.out.println("abc" + cde); String c = "abc".substring(2 3); String d = cde.substring(1 2);The class
String
includes methods for examining individual characters of the sequence for comparing strings for searching strings for extracting substrings and for creating a copy of a string with all characters translated to uppercase or to lowercase.The Java language provides special support for the string concatentation operator ( + ) and for conversion of other objects to strings. String concatenation is implemented through the
StringBuffer
class and itsappend
method. String conversions are implemented through the methodtoString
defined byObject
and inherited by all classes in Java. For additional information on string concatenation and conversion see Gosling Joy and Steele The Java Language Specification. @author Lee Boynton @author Arthur van Hoff @version 1.114 04121 10/2206/99 @see java.lang.Object#toString() @see java.lang.StringBuffer @see java.lang.StringBuffer#append(boolean) @see java.lang.StringBuffer#append(char) @see java.lang.StringBuffer#append(char[]) @see java.lang.StringBuffer#append(char[] int int) @see java.lang.StringBuffer#append(double) @see java.lang.StringBuffer#append(float) @see java.lang.StringBuffer#append(int) @see java.lang.StringBuffer#append(long) @see java.lang.StringBuffer#append(java.lang.Object) @see java.lang.StringBuffer#append(java.lang.String) @see Character encodings @since JDK1.0
Construct a newClass String, constructor String(byte[], int, int, String)String
by converting the specified array of bytes using the specified character encoding. The length of the newString
is a function of the encoding and hence may not be equal to the length of the byte array. @param bytes The bytes to be converted into characters @param encAThe name of a supported character-encodingnameencoding @exception UnsupportedEncodingException If the named encoding is not supported @since JDK1.1
Construct a newClass String, int compareTo(Object)String
by converting the specified subarray of bytes using the specified character encoding. The length of the newString
is a function of the encoding and hence may not be equal to the length of the subarray. @param bytes The bytes to be converted into characters @param offset Index of the first byte to convert @param length Number of bytes to convert @param enc The name of a supported character encoding @exceptionthrows UnsupportedEncodingExceptionIfif the named encoding is not supported @throws IndexOutOfBoundsException if theoffset
andcount
arguments index characters outside the bounds of thevalue
array. @since JDK1.1
Compares this String to another Object. If the Object is a String this function behaves likeClass String, int compareToIgnoreCase(String)compareTo(String)
. Otherwise it throws aClassCastException
(as Strings are comparable only to other Strings). @param o theObject
to be compared. @return the value0
if the argument is a string lexicographically equal to this string; a value less than0
if the argument is a string lexicographically greater than this string; and a value greater than0
if the argument is a string lexicographically less than this string. @exceptionClassCastException
if the argument is not aString
. @see java.lang.Comparable @sinceJDK11.2
Compares two strings lexicographically ignoring case considerations. This method returns an integer whose sign is that ofClass String, boolean equalsIgnoreCase(String)this.toUpperCase().toLowerCase().compareTo( str.toUpperCase().toLowerCase())
.Note that this method does not take locale into account and will result in an unsatisfactory ordering for certain locales. The java.text package provides collators to allow locale-sensitive ordering. @param str the
String
to be compared. @return a negative integer zero or a positive integer as the the specified String is greater than equal to or less than this String ignoring case considerations. @see java.text.Collator#compare(String String) @sinceJDK11.2
Compares thisClass String, byte[] getBytes(String)String
to anotherString
ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case.Two characters
c1
andc2
are considered the same ignoring case if at least one of the following is true:@param anotherString the
- The two characters are the same (as compared by the
==
operator).- Applying the method java.lang.Character#
toUppercasetoUpperCase(char) to each character produces the same result.- Applying the method
tjava.lang.Character#toLowerCase(char) to each character produces the same result.String
to compare thisString
against. @returntrue
if the argument is notnull
and theString
s are equal ignoring case;false
otherwise. @see #equals(Object) @see java.lang.Character#toLowerCase(char) @see java.lang.Character#toUpperCase(char)
Convert thisClass String, String toLowerCase()String
into bytes according to the specified character encoding storing the result into a new byte array. @param encAThe name of a supported character-encodingnameencoding @return The resultant byte array @exception UnsupportedEncodingException If the named encoding is not supported @since JDK1.1
Converts all of the characters in thisClass String, String toLowerCase(Locale)String
to lower case using the rules of the default locale which is returned byLocale.getDefault
.If no character in the string has a different lowercase version based on calling the
toLowerCase
method defined byCharacter
then the original string is returned.Otherwise this method creates a new
String
object that represents a character sequence identical in length to the character sequence represented by this String object with every character equal to the result of applying the methodCharacter.toLowerCase
to the corresponding character of thisString
object.Examples:
@return the string converted to lowercase. @see java.lang.Character#toLowerCase(char) @see java.lang.String#"French Fries".toLowerCase() returns "french fries" "".toLowerCase() returns "
"
toUpperCasetoLowerCase(Locale)
Converts all of the characters in thisClass String, String toUpperCase()String
to lower case using the rules of the givenLocale
. Usually the characters are converted by callingCharacter.toLowerCase
. Exceptions to this rule are listed in the following table:
@param locale use the case transformation rules for this locale @return the String converted to lowercase. @see java.lang.Character#toLowerCase(char) @see java.lang.String#toUpperCase(Locale) @since JDK1.1
Language Code of Locale Upper Case Lower Case Description tr (Turkish) \u0130 \u0069 capital letter I with dot above -> small letter i tr (Turkish) \u0049 \u0131 capital letter I -> small letter dotless i
Converts all of the characters in thisClass String, String toUpperCase(Locale)String
to upper case using the rules of the default locale which is returned byLocale.getDefault
.If no character in this string has a different uppercase version based on calling the
toUpperCase
method defined byCharacter
then the original string is returned.Otherwise this method creates a new
String
object representing a character sequence identical in length to the character sequence represented by thisString
object and with every character equal to the result of applying the methodCharacter.toUpperCase
to the corresponding character of thisString
object.Examples:
@return the string converted to uppercase. @see java.lang.Character#toUpperCase(char) @see java.lang.String#"Fahrvergnügen".toUpperCase() returns "FAHRVERGNÜGEN" "Visit Ljubinje ".toUpperCase() returns "VISIT LJUBINJE "toLowerCasetoUpperCase(Locale)
Converts all of the characters in thisClass String, Comparator CASE_INSENSITIVE_ORDERString
to upper case using the rules of the given locale. Usually the characters are converted by callingCharacter.toUpperCase
. Exceptions to this rule are listed in the following table:
@param locale use the case transformation rules for this locale @return the String converted to uppercase. @see java.lang.Character#toUpperCase(char) @see java.lang.String#toLowerCase(
Language Code of Locale Lower Case Upper Case Description tr (Turkish) \u0069 \u0130 small letter i -> capital letter I with dot above tr (Turkish) \u0131 \u0049 small letter dotless i -> capital letter I (all) \u00df \u0053 \u0053 small letter sharp s -> two letters: SS charLocale) @since JDK1.1
Returns a Comparator that ordersString
objects as bycompareToIgnoreCase
. This comparator is serializable.Note that this Comparator does not take locale into account and will result in an unsatisfactory ordering for certain locales. The java.text package provides Collators to allow locale-sensitive ordering. @return Comparator for case insensitive comparison of strings @see java.text.Collator#compare(String String) @since
JDK11.2
A string buffer implements a mutable sequence of characters. A string buffer is like a String but can be modified. At any point in time it contains some particular sequence of characters but the length and content of the sequence can be changed through certain method calls.Class StringBuffer, StringBuffer append(char)String buffers are safe for use by multiple threads. The methods are synchronized where necessary so that all the operations on any particular instance behave as if they occur in some serial order that is consistent with the order of the method calls made by each of the individual threads involved.
String buffers are used by the compiler to implement the binary string concatenation operator
+
. For example the code:x = "a" + 4 + "c"is compiled to the equivalent of:
which creates a new string buffer (initially empty) appends the string representation of each operand to the string buffer in turn and then converts the contents of the string buffer to a string. Overall this avoids creating many temporary strings.x = new StringBuffer().append("a").append(4).append("c") .toString()The principal operations on a
StringBuffer
are theappend
andinsert
methods which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string buffer. Theappend
method always adds these characters at the end of the buffer; theinsert
method adds the characters at a specified point.For example if
z
refers to a string buffer object whose current contents are "start
" then the method callz.append("le")
would cause the string buffer to contain "startle
" whereasz.insert(4 "le")
would alter the string buffer to contain "starlet
".In general if sb refers to an instance of a
StringBuffer
thensb.append(x)
has the same effect assb.insert(sb.length() x)
.Every string buffer has a capacity. As long as the length of the character sequence contained in the string buffer does not exceed the capacity it is not necessary to allocate a new internal buffer array. If the internal buffer overflows it is automatically made larger. @author Arthur van Hoff @version 1.
45 1062 04/2721/9800 @see java.io.ByteArrayOutputStream @see java.lang.String @since JDK1.0
Appends the string representation of theClass StringBuffer, StringBuffer delete(int, int)char
argument to this string buffer.The argument is appended to the contents of this string buffer. The length of this string buffer increases by
1
.The overall effect is exactly as if the argument were converted to a string by the method String#valueOf(char) and the character in that string were then appended to this
StringBuffer
object. @paramchc achar
. @return a reference to thisStringBuffer
object.
Removes the characters in a substring of thisClass StringBuffer, StringBuffer deleteCharAt(int)StringBuffer
. The substring begins at the specifiedstart
and extends to the character at indexend - 1
or to the end of theStringBuffer
if no such character exists. Ifstart
is equal toend
no changes are made. @param start The beginning index inclusive. @param end The ending index exclusive. @return This string buffer. @exception StringIndexOutOfBoundsException ifstart
is negative greater thanlength()
or greater thanend
. @sinceJDK11.2
Removes the character at the specified position in thisClass StringBuffer, void getChars(int, int, char[], int)StringBuffer
(shortening theStringBuffer
by one character). @param index Index of character to remove @return This string buffer. @exception StringIndexOutOfBoundsException if theindex
is negative or greater than or equal tolength()
. @sinceJDK11.2
Characters are copied from this string buffer into the destination character arrayClass StringBuffer, StringBuffer insert(int, Object)dst
. The first character to be copied is at indexsrcBegin
; the last character to be copied is at indexsrcEnd-1
. The total number of characters to be copied issrcEnd-srcBegin
. The characters are copied into the subarray ofdst
starting at indexdstBegin
and ending at index:@param srcBegin start copying at this offset in the string buffer. @param srcEnd stop copying at this offset in the string buffer. @param dst the array to copy the data into. @param dstBegin offset intodstbegin + (srcEnd-srcBegin) - 1dst
. @exception NullPointerException ifdst
isnull
. @exception IndexOutOfBoundsException if any of the following is true:
srcBegin
is negativedstBegin
is negative- the
argument is greater than the
srcBeingsrcBeginsrcEnd
argument.srcEnd
is greater thanthis.length()
the current length of this string buffer.dstBegin+srcEnd-srcBegin
is greater thandst.length
Inserts the string representation of theClass StringBuffer, StringBuffer insert(int, char)Object
argument into this string buffer.The second argument is converted to a string as if by the method
String.valueOf
and the characters of that string are then inserted into this string buffer at the indicated offset.The offset argument must be greater than or equal to
0
and less than or equal to the length of this string buffer. @param offset the offset. @parambobj anObject
. @return a reference to thisStringBuffer
object. @exception StringIndexOutOfBoundsException if the offset is invalid. @see java.lang.String#valueOf(java.lang.Object) @see java.lang.StringBuffer#insert(int java.lang.String) @see java.lang.StringBuffer#length()
Inserts the string representation of theClass StringBuffer, StringBuffer insert(int, char[])char
argument into this string buffer.The second argument is inserted into the contents of this string buffer at the position indicated by
offset
. The length of this string buffer increases by one.The overall effect is exactly as if the argument were converted to a string by the method String#valueOf(char) and the character in that string were then String inserted} into this
StringBuffer
object at the position indicated byoffset
.The offset argument must be greater than or equal to
0
and less than or equal to the length of this string buffer. @param offset the offset. @paramchc achar
. @return a reference to thisStringBuffer
object. @exceptionStringIndexOutOfBoundsExceptionIndexOutOfBoundsException if the offset is invalid. @see java.lang.StringBuffer#length()
Inserts the string representation of theClass StringBuffer, StringBuffer insert(int, char[], int, int)char
array argument into this string buffer.The characters of the array argument are inserted into the contents of this string buffer at the position indicated by
offset
. The length of this string buffer increases by the length of the argument.The overall effect is exactly as if the argument were converted to a string by the method String#valueOf(char[]) and the characters of that string were then String inserted} into this
StringBuffer
object at the position indicated byoffset
. @param offset the offset. @paramchstr a character array. @return a reference to thisStringBuffer
object. @exception StringIndexOutOfBoundsException if the offset is invalid.
Inserts the string representation of a subarray of theClass StringBuffer, StringBuffer insert(int, double)str
array argument into this string buffer. The subarray begins at the specifiedoffset
and extendslen
characters. The characters of the subarray are inserted into this string buffer at the position indicated byindex
. The length of thisStringBuffer
increases bylen
characters. @param index position at which to insert subarray. @param str A character array. @param offset the index of the first character in subarray to to be inserted. @param len the number of characters in the subarray to to be inserted. @return This string buffer. @exception StringIndexOutOfBoundsException ifindex
is negative or greater thanlength()
oroffset
orlen
are negative or(offset+len)
is greater thanstr.length
. @sinceJDK11.2
Inserts the string representation of theClass StringBuffer, StringBuffer insert(int, float)double
argument into this string buffer.The second argument is converted to a string as if by the method
String.valueOf
and the characters of that string are then inserted into this string buffer at the indicated offset.The offset argument must be greater than or equal to
0
and less than or equal to the length of this string buffer. @param offset the offset. @parambd adouble
. @return a reference to thisStringBuffer
object. @exception StringIndexOutOfBoundsException if the offset is invalid. @see java.lang.String#valueOf(double) @see java.lang.StringBuffer#insert(int java.lang.String) @see java.lang.StringBuffer#length()
Inserts the string representation of theClass StringBuffer, StringBuffer insert(int, int)float
argument into this string buffer.The second argument is converted to a string as if by the method
String.valueOf
and the characters of that string are then inserted into this string buffer at the indicated offset.The offset argument must be greater than or equal to
0
and less than or equal to the length of this string buffer. @param offset the offset. @parambf afloat
. @return a reference to thisStringBuffer
object. @exception StringIndexOutOfBoundsException if the offset is invalid. @see java.lang.String#valueOf(float) @see java.lang.StringBuffer#insert(int java.lang.String) @see java.lang.StringBuffer#length()
Inserts the string representation of the secondClass StringBuffer, StringBuffer insert(int, long)int
argument into this string buffer.The second argument is converted to a string as if by the method
String.valueOf
and the characters of that string are then inserted into this string buffer at the indicated offset.The offset argument must be greater than or equal to
0
and less than or equal to the length of this string buffer. @param offset the offset. @parambi anint
. @return a reference to thisStringBuffer
object. @exception StringIndexOutOfBoundsException if the offset is invalid. @see java.lang.String#valueOf(int) @see java.lang.StringBuffer#insert(int java.lang.String) @see java.lang.StringBuffer#length()
Inserts the string representation of theClass StringBuffer, StringBuffer replace(int, int, String)long
argument into this string buffer.The second argument is converted to a string as if by the method
String.valueOf
and the characters of that string are then inserted into this string buffer at the position indicated byoffset
.The offset argument must be greater than or equal to
0
and less than or equal to the length of this string buffer. @param offset the offset. @parambl along
. @return a reference to thisStringBuffer
object. @exception StringIndexOutOfBoundsException if the offset is invalid. @see java.lang.String#valueOf(long) @see java.lang.StringBuffer#insert(int java.lang.String) @see java.lang.StringBuffer#length()
Replaces the characters in a substring of thisClass StringBuffer, String substring(int)StringBuffer
with characters in the specifiedString
. The substring begins at the specifiedstart
and extends to the character at indexend - 1
or to the end of theStringBuffer
if no such character exists. First the characters in the substring are removed and then the specifiedString
is inserted atstart
. (TheStringBuffer
will be lengthened to accommodate the specified String if necessary.) @param start The beginning index inclusive. @param end The ending index exclusive. @param str String that will replace previous contents. @return This string buffer. @exception StringIndexOutOfBoundsException ifstart
is negative greater thanlength()
or greater thanend
. @sinceJDK11.2
Returns a newClass StringBuffer, String substring(int, int)String
that contains a subsequence of characters currently contained in thisStringBuffer
.The substring begins at the specified index and extends to the end of theStringBuffer
. @param start The beginning index inclusive. @return The new string. @exception StringIndexOutOfBoundsException ifstart
is less than zero or greater than the length of thisStringBuffer
. @sinceJDK11.2
Returns a newString
that contains a subsequence of characters currently contained in thisStringBuffer
. The substring begins at the specifiedstart
and extends to the character at indexend - 1
. An exception is thrown if @param start The beginning index inclusive. @param end The ending index exclusive. @return The new string. @exception StringIndexOutOfBoundsException ifstart
orend
are negative or greater thanlength()
orstart
is greater thanend
. @sinceJDK11.2
Thrown by thecharAt
method in classString
and by otherString
methods to indicate that an index is either negative or greater than or equal to the size of the string. @author unascribed @version 1.16 0918 02/2102/9800 @see java.lang.String#charAt(int) @since JDK1.0
TheClass System, void arraycopy(Object, int, Object, int, int)System
class contains several useful class fields and methods. It cannot be instantiated.Among the facilities provided by the
System
class are standard input standard output and error output streams; access to externally defined "properties"; a means of loading files and libraries; and a utility method for quickly copying a portion of an array. @author Arthur van Hoff @version 1.100 03111 02/0802/00 @since JDK1.0
Copies an array from the specified source array beginning at the specified position to the specified position of the destination array. A subsequence of array components are copied from the source array referenced byClass System, Properties getProperties()src
to the destination array referenced bydst
. The number of components copied is equal to thelength
argument. The components at positionssrcOffset
throughsrcOffset+length-1
in the source array are copied into positionsdstOffset
throughdstOffset+length-1
respectively of the destination array.If the
src
anddst
arguments refer to the same array object then the copying is performed as if the components at positionssrcOffset
throughsrcOffset+length-1
were first copied to a temporary array withlength
components and then the contents of the temporary array were copied into positionsdstOffset
throughdstOffset+length-1
of the destination array.If
dst
isnull
then aNullPointerException
is thrown.If
src
isnull
then aNullPointerException
is thrown and the destination array is not modified.Otherwise if any of the following is true an
ArrayStoreException
is thrown and the destination is not modified:
- The
src
argument refers to an object that is not an array.- The
dst
argument refers to an object that is not an array.- The
src
argument anddst
argument refer to arrays whose component types are different primitive types.- The
src
argument refers to an array with a primitive component type and thedst
argument refers to an array with a reference component type.- The
src
argument refers to an array with a reference component type and thedst
argument refers to an array with a primitive component type.Otherwise if any of the following is true an
IndexOutOfBoundsException
is thrown and the destination is not modified:
- The
srcOffset
argument is negative.- The
dstOffset
argument is negative.- The
length
argument is negative.srcOffset+length
is greater thansrc.length
the length of the source array.dstOffset+length
is greater thandst.length
the length of the destination array.Otherwise if any actual component of the source array from position
srcOffset
throughsrcOffset+length-1
cannot be converted to the component type of the destination array by assignment conversion anArrayStoreException
is thrown. In this case let k be the smallest nonnegative integer less than length such thatsrc[srcOffset+
k]
cannot be converted to the component type of the destination array; when the exception is thrown source array components from positionssrcOffset
throughsrcOffset+
k-1
will already have been copied to destination array positionsdstOffset
throughdstOffset+
k-1
and no other positions of the destination array will have been modified. (Because of the restrictions already itemized this paragraph effectively applies only to the situation where both arrays have component types that are reference types.) @param src:the source array. @paramsrcpossrc_position start position in the source array. @paramdestdst the destination array. @paramdestposdst_position pos start position in the destination data. @param length the number of array elements to be copied. @exception IndexOutOfBoundsException if copying would cause access of data outside array bounds. @exception ArrayStoreException if an element in thesrc
array could not be stored into thedest
array because of a type mismatch. @exception NullPointerException if eithersrc
ordst
isnull
.
Determines the current system properties.Class System, String getProperty(String)First if there is a security manager its
checkPropertiesAccess
method is called with no arguments. This may result in a security exception.The current set of system properties for use by the #getProperty(String) method is returned as a
Properties
object. If there is no current set of system properties a set of system properties is first created and initialized. This set of system properties always includes values for the following keys:
Key Description of Associated Value java.version
Java Runtime Environment version java.vendor
Java Runtime Environment vendor java.vendor.url
Java vendor URL java.home
Java installation directory java.vm.specification.version
Java Virtual Machine specification version java.vm.specification.vendor
Java Virtual Machine specification vendor java.vm.specification.name
Java Virtual Machine specification name java.vm.version
Java Virtual Machine implementation version java.vm.vendor
Java Virtual Machine implementation vendor java.vm.name
Java Virtual Machine implementation name java.specification.version
Java Runtime Environment specification version java.specification.vendor
Java Runtime Environment specification vendor java.specification.name
Java Runtime Environment specification name java.class.version
Java class format version number java.class.path
Java class path java.ext.dirs
Path of extension directory or directories os.name
Operating system name os.arch
Operating system architecture os.version
Operating system version file.separator
File separator ("/" on UNIX) path.separator
Path separator (":" on UNIX) line.separator
Line separator ("\n" on UNIX) user.name
User's account name user.home
User's home directory user.dir
User's current working directory Note that even if the security manager does not permit the
getProperties
operation it may choose to permit the #getProperty(String) operation. @return the system properties @exception SecurityException if a security manager exists and itscheckPropertiesAccess
method doesn't allow access to the system properties. @see #setProperties @see java.lang.SecurityException @see java.lang.SecurityManager#checkPropertiesAccess() @see java.util.Properties
Gets the system property indicated by the specified key.Class System, String getProperty(String, String)First if there is a security manager its
checkPropertyAccess
method is called with the key as its argument. This may result in a SecurityException.If there is no current set of system properties a set of system properties is first created and initialized in the same manner as for the
getProperties
method. @param key the name of the system property. @return the string value of the system property ornull
if there is no property with that key. @exception SecurityException if a security manager exists and itscheckPropertyAccess
method doesn't allow access to the specified system property. @exception NullPointerException ifkey
isnull
. @exception IllegalArgumentException ifkey
is empty. @see #setProperty @see java.lang.SecurityException @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) @see java.lang.System#getProperties()
Gets the system property indicated by the specified key.Class System, SecurityManager getSecurityManager()First if there is a security manager its
checkPropertyAccess
method is called with thekey
as its argument.If there is no current set of system properties a set of system properties is first created and initialized in the same manner as for the
getProperties
method. @param key the name of the system property. @param def a default value. @return the string value of the system property or the default value if there is no property with that key. @exception SecurityException if a security manager exists and itscheckPropertyAccess
method doesn't allow access to the specified system property. @exception NullPointerException ifkey
isnull
. @exception IllegalArgumentException ifkey
is empty. @see #setProperty @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) @see java.lang.System#getProperties()
Gets the system security interface. @return if a security manager has already been established for the current application then that security manager is returned; otherwise null
is returned. @see #setSecurityManager
Class System, String getenv(String)Gets an environment variable. An environment variable is a system-dependent external variable that has a string value. @deprecated The preferred way to extract system-dependent information is the system properties of theClass System, int identityHashCode(Object)java.lang.System.getProperty
methods and the correspondingget
TypeName methods of theBoolean
Integer
andLong
primitive types. For example:@paramString classPath = System.getProperty("java.class.path" ".");
if (Boolean.getBoolean("myapp.exper.mode")) enableExpertCommands();thename of the environment variable.@return the value of the variable ornull
if the variable is not defined. @see java.lang.Boolean#getBoolean(java.lang.String) @see java.lang.Integer#getInteger(java.lang.String) @see java.lang.Integer#getInteger(java.lang.String int) @see java.lang.Integer#getInteger(java.lang.String java.lang.Integer) @see java.lang.Long#getLong(java.lang.String) @see java.lang.Long#getLong(java.lang.String long) @see java.lang.Long#getLong(java.lang.String java.lang.Long) @see java.lang.System#getProperties() @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String)
Returns the same hashcode for the given object as would be returned by the default method hashCode() whether or not the given object's class overrides hashCode(). The hashcode for the null reference is zero. @param x object for which the hashCode is to be calculated @return the hashCode @since JDK1.1Class System, String mapLibraryName(String)
Maps a library name into a platform-specific string representing a native library. @param libname the name of the library. @return a platform-dependent native library name. @see java.lang.System#loadLibrary(java.lang.String) @see java.lang.ClassLoader#findLibrary(java.lang.String) @sinceClass System, void runFinalizersOnExit(boolean)JDK11.2
Enable or disable finalization on exit; doing so specifies that the finalizers of all objects that have finalizers that have not yet been automatically invoked are to be run before the Java runtime exits. By default finalization on exit is disabled.Class System, void setErr(PrintStream)If there is a security manager its
checkExit
method is first called with 0 as its argument to ensure the exit is allowed. This could result in a SecurityException. @deprecated This method is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects resulting in erratic behavior or deadlock. @param value indicating enabling or disabling of finalization @throws SecurityException if a security manager exists and itscheckExit
method doesn't allow the exit. @see java.lang.Runtime#exit(int) @see java.lang.Runtime#gc() @see java.lang.SecurityManager#checkExit(int) @since JDK1.1
Reassigns the "standard" error output stream.Class System, void setOut(PrintStream)First if there is a security manager its
checkPermission
method is called with aRuntimePermission("setIO")
permission to see if it's ok to reassign the "standard" error output stream. @paramouterr the new standard error output stream. @throws SecurityException if a security manager exists and itscheckPermission
method doesn't allow reassigning of the standard error output stream. @see SecurityManager#checkPermission @see java.lang.RuntimePermission @since JDK1.1
Reassigns the "standard" output stream.Class System, void setProperties(Properties)First if there is a security manager its
checkPermission
method is called with aRuntimePermission("setIO")
permission to see if it's ok to reassign the "standard" output stream. @param out the new standard output stream.@throws SecurityException if a security manager exists and itscheckPermission
method doesn't allow reassigning of the standard output stream. @see SecurityManager#checkPermission @see java.lang.RuntimePermission @since JDK1.1
Sets the system properties to theClass System, String setProperty(String, String)Properties
argument.First if there is a security manager its
checkPropertiesAccess
method is called with no arguments. This may result in a security exception.The argument becomes the current set of system properties for use by the #getProperty(String) method. If the argument is
null
then the current set of system properties is forgotten. @param props the new system properties. @exception SecurityException if a security manager exists and itscheckPropertiesAccess
method doesn't allow access to the system properties. @see #getProperties @see java.langutil.Properties @see java.lang.SecurityException @see java.lang.SecurityManager#checkPropertiesAccess()
Sets the system property indicated by the specified key.Class System, void setSecurityManager(SecurityManager)First if a security manager exists its
SecurityManager.checkPermission
method is called with aPropertyPermission(key "write")
permission. This may result in a SecurityException being thrown. If no exception is thrown the specified property is set to the given value.@param key the name of the system property. @param value the value of the system property. @return the previous value of the system property or
null
if it did not have one. @exception SecurityException if a security manager exists and itscheckPermission
method doesn't allow setting of the specified property. @exception NullPointerException ifkey
isnull
. @exception IllegalArgumentException ifkey
is empty. @see #getProperty @see java.lang.System#getProperty(java.lang.String) @see java.lang.System#getProperty(java.lang.String java.lang.String) @see java.util.PropertyPermission @see SecurityManager#checkPermission @sinceJDK11.2
Sets the System security.If there is a security manager already installed this method first calls the security manager's
checkPermission
method with aRuntimePermission("setSecurityManager")
permission to ensure it's ok to replace the existing security manager. This may result in throwing aSecurityException
.Otherwise the argument is established as the current security manager. If the argument is
null
and no security manager has been established then no action is taken and the method simply returns. @param s the security manager. @exception SecurityException if the security manager has already been set and itscheckPermission
method doesn't allow it to be replaced. @see #getSecurityManager @see SecurityManager#checkPermission @see java.lang.RuntimePermission
A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.Class Thread, void checkAccess()Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. Each thread may or may not also be marked as a daemon. When code running in some thread creates a new
Thread
object the new thread has its priority initially set equal to the priority of the creating thread and is a daemon thread if and only if the creating thread is a daemon.When a Java Virtual Machine starts up there is usually a single non-daemon thread (which typically calls the method named
main
of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs:
- The
exit
method of classRuntime
has been called and the security manager has permitted the exit operation to take place.- All threads that are not daemon threads have died either by returning from the call to the
run
method or by throwing an exception that propagates beyond therun
method.There are two ways to create a new thread of execution. One is to declare a class to be a subclass of
Thread
. This subclass should override therun
method of classThread
. An instance of the subclass can then be allocated and started. For example a thread that computes primes larger than a stated value could be written as follows:class PrimeThread extends Thread { long minPrime; PrimeThread(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } }
The following code would then create a thread and start it running:
PrimeThread p = new PrimeThread(143); p.start();The other way to create a thread is to declare a class that implements the
Runnable
interface. That class then implements therun
method. An instance of the class can then be allocated passed as an argument when creatingThread
and started. The same example in this other style looks like the following:class PrimeRun implements Runnable { long minPrime; PrimeRun(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } }
The following code would then create a thread and start it running:
PrimeRun p = new PrimeRun(143); new Thread(p).start();Every thread has a name for identification purposes. More than one thread may have the same name. If a name is not specified when a thread is created a new name is generated for it. @author unascribed @version 1.
97 11106 02/0502/9800 @see java.lang.Runnable @see java.lang.Runtime#exit(int) @see java.lang.Thread#run() @see java.lang.Thread#stop() @since JDK1.0
Determines if the currently running thread has permission to modify this thread.Class Thread, int enumerate(Thread[])If there is a security manager its
checkAccess
method is called with this thread as its argument. This may result in throwing aSecurityException
.Note: This method was mistakenly non-final in JDK 1.1. It has been made final in
JDKthe1.Java 2 Platform. @exception SecurityException if the current thread is not allowed to access this thread. @see java.lang.SecurityManager#checkAccess(java.lang.Thread)
Copies into the specified array every active thread in this thread's thread group and its subgroups. This method simply calls theClass Thread, ClassLoader getContextClassLoader()enumerate
method of this thread's thread group with the array argument.First if there is a security manager that
enumerate
method calls the security manager'scheckAccess
method with the thread group as its argument. This may result in throwing aSecurityException
. @param tarray an array of Thread objects to copy to @return the number of threads put into the array.@exception SecurityException if a security manager exists and itscheckAccess
method doesn't allow the operation. @see java.lang.ThreadGroup#enumerate(java.lang.Thread[]) @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup)
Returns the context ClassLoader for this Thread. The context ClassLoader is provided by the creator of the thread for use by code running in this thread when loading classes and resources. If not set the default is the ClassLoader context of the parent Thread. The context ClassLoader of the primordial thread is typically set to the class loader used to load the application.Class Thread, String getName()First if there is a security manager and the caller's class loader is not null and the caller's class loader is not the same as or an ancestor of the context class loader for the thread whose context class loader is being requested then the security manager's
checkPermission
method is called with aRuntimePermission("getClassLoader")
permission to see if it's ok to get the context ClassLoader.. @return the context ClassLoader for this Thread @throws SecurityException if a security manager exists and itscheckPermission
method doesn't allow getting the context ClassLoader. @see #setContextClassLoader @see SecurityManager#checkPermission @see java.lang.RuntimePermission @sinceJDK11.2
Returns this thread's name. @return this thread's name. @see #setName @see java.lang.Thread#setName(java.lang.String)Class Thread, int getPriority()
Returns this thread's priority. @return this thread's name. @see #setPriority @see java.lang.Thread#setPriority(int)Class Thread, void resume()
Resumes a suspended thread.Class Thread, void setContextClassLoader(ClassLoader)First the
checkAccess
method of this thread is called with no arguments. This may result in throwing aSecurityException
(in the current thread).If the thread is alive but suspended it is resumed and is permitted to make progress in its execution. @exception SecurityException if the current thread cannot modify this thread. @see #checkAccess @see java.lang.Thread#suspend() @deprecated This method exists solely for use with #suspend which has been deprecated because it is deadlock-prone. For more information see Why are Thread.stop Thread.suspend and Thread.resume Deprecated .
Sets the context ClassLoader for this Thread. The context ClassLoader can be set when a thread is created and allows the creator of the thread to provide the appropriate class loader to code running in the thread when loading classes and resources.Class Thread, void setName(String)First if there is a security manager its
checkPermission
method is called with aRuntimePermission("setContextClassLoader")
permission to see if it's ok to set the context ClassLoader.. @param cl the context ClassLoader for this Thread @exception SecurityException if the current thread cannot set the context ClassLoader. @see #getContextClassLoader @see SecurityManager#checkPermission @see java.lang.RuntimePermission @sinceJDK11.2
Changes the name of this thread to be equal to the argumentClass Thread, void setPriority(int)name
.First the
checkAccess
method of this thread is called with no arguments. This may result in throwing aSecurityException
. @param name the new name for this thread. @exception SecurityException if the current thread cannot modify this thread. @see #getName @see java.lang.Thread#checkAccess() @see java.lang.Thread#getName()
Changes the priority of this thread.Class Thread, void stop()First the
checkAccess
method of this thread is called with no arguments. This may result in throwing aSecurityException
.Otherwise the priority of this thread is set to the smaller of the specified
newPriority
and the maximum permitted priority of the thread's thread group. @param newPriority priority to set this thread to @exception IllegalArgumentException If the priority is not in the rangeMIN_PRIORITY
toMAX_PRIORITY
. @exception SecurityException if the current thread cannot modify this thread. @see #getPriority @see java.lang.Thread#checkAccess() @see java.lang.Thread#getPriority() @see java.lang.Thread#getThreadGroup() @see java.lang.Thread#MAX_PRIORITY @see java.lang.Thread#MIN_PRIORITY @see java.lang.ThreadGroup#getMaxPriority()
Forces the thread to stop executing.Class Thread, void stop(Throwable)If there is a security manager installed its
checkAccess
method is called withthis
as its argument. This may result in aSecurityException
being raised (in the current thread).If this thread is different from the current thread (that is the current thread is trying to stop a thread other than itself) the security manager's
checkPermission
method (with aRuntimePermission("stopThread")
argument) is called in addition. Again this may result in throwing aSecurityException
(in the current thread).The thread represented by this thread is forced to stop whatever it is doing abnormally and to throw a newly created
ThreadDeath
object as an exception.It is permitted to stop a thread that has not yet been started. If the thread is eventually started it immediately terminates.
An application should not normally try to catch
ThreadDeath
unless it must do some extraordinary cleanup operation (note that the throwing ofThreadDeath
causesfinally
clauses oftry
statements to be executed before the thread officially dies). If acatch
clause catches aThreadDeath
object it is important to rethrow the object so that the thread actually dies.The top-level error handler that reacts to otherwise uncaught exceptions does not print out a message or otherwise notify the application if the uncaught exception is an instance of
ThreadDeath
. @exception SecurityException if the current thread cannot modify this thread. @see java.lang.Thread#interrupt() @see java.lang.Thread#checkAccess() @see java.lang.Thread#run() @see java.lang.Thread#start() @see java.lang.ThreadDeath @see java.lang.ThreadGroup#uncaughtException(java.lang.Thread java.lang.Throwable) @see SecurityManager#checkAccess(Thread) @see SecurityManager#checkPermission @deprecated This method is inherently unsafe. Stopping a thread with Thread.stop causes it to unlock all of the monitors that it has locked (as a natural consequence of the uncheckedThreadDeath
exception propagating up the stack). If any of the objects previously protected by these monitors were in an inconsistent state the damaged objects become visible to other threads potentially resulting in arbitrary behavior. Many uses ofstop
should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly and return from its run method in an orderly fashion if the variable indicates that it is to stop running. If the target thread waits for long periods (on a condition variable for example) theinterrupt
method should be used to interrupt the wait. For more information see Why are Thread.stop Thread.suspend and Thread.resume Deprecated .
Forces the thread to stop executing.Class Thread, void suspend()If there is a security manager installed the
checkAccess
method of this thread is called which may result in aSecurityException
being raised (in the current thread).If this thread is different from the current thread (that is the current thread is trying to stop a thread other than itself) or
obj
is not an instance ofThreadDeath
the security manager'scheckPermission
method (with theRuntimePermission("stopThread")
argument) is called in addition. Again this may result in throwing aSecurityException
(in the current thread).If the argument
obj
is null aNullPointerException
is thrown (in the current thread).The thread represented by this thread is forced to complete whatever it is doing abnormally and to throw the
Throwable
objectobj
as an exception. This is an unusual action to take; normally thestop
method that takes no arguments should be used.It is permitted to stop a thread that has not yet been started. If the thread is eventually started it immediately terminates. @param obj the Throwable object to be thrown. @exception SecurityException if the current thread cannot modify this thread. @see java.lang.Thread#interrupt() @see java.lang.Thread#checkAccess() @see java.lang.Thread#run() @see java.lang.Thread#start() @see java.lang.Thread#stop() @see SecurityManager#checkAccess(Thread) @see SecurityManager#checkPermission @deprecated This method is inherently unsafe. See #stop (with no arguments) for details. An additional danger of this method is that it may be used to generate exceptions that the target thread is unprepared to handle (including checked exceptions that the thread could not possibly throw were it not for this method). For more information see Why are Thread.stop Thread.suspend and Thread.resume Deprecated .
Suspends this thread.First the
checkAccess
method of this thread is called with no arguments. This may result in throwing aSecurityException
(in the current thread).If the thread is alive it is suspended and makes no further progress unless and until it is resumed. @exception SecurityException if the current thread cannot modify this thread. @see #checkAccess @deprecated This method has been deprecated as it is inherently deadlock-prone. If the target thread holds a lock on the monitor protecting a critical system resource when it is suspended no thread can access this resource until the target thread is resumed. If the thread that would resume the target thread attempts to lock this monitor prior to calling
resume
deadlock results. Such deadlocks typically manifest themselves as "frozen" processes. For more information see Why are Thread.stop Thread.suspend and Thread.resume Deprecated .
An instance ofThreadDeath
is thrown in the victim thread when thestop
method with zero arguments in classThread
is called.An application should catch instances of this class only if it must clean up after being terminated asynchronously. If
ThreadDeath
is caught by a method it is important that it be rethrown so that the thread actually dies.The top-level error handler does not print out a message if
ThreadDeath
is never caught.The class
ThreadDeath
is specifically a subclass ofError
rather thanException
even though it is a "normal occurrence" because many applications catch all occurrences ofException
and then discard the exception. @author unascribed @version 1.10 0912 02/2102/9800 @see java.lang.Thread#stop() @since JDK1.0
A thread group represents a set of threads. In addition a thread group can also include other thread groups. The thread groups form a tree in which every thread group except the initial thread group has a parent.Class ThreadGroup, boolean allowThreadSuspension(boolean)A thread is allowed to access information about its own thread group but not to access information about its thread group's parent thread group or any other thread groups. @author unascribed @version 1.
45 0451 02/2202/9900 @since JDK1.0
Used by VM to control lowmem implicit suspension. @param b boolean to allow or disallow suspension @return true on success @since JDK1.1 @deprecated The definition of this call depends on #suspend which is deprecated. Further the behavior of this call was never specified.Class ThreadGroup, int getMaxPriority()
Returns the maximum priority of this thread group. Threads that are part of this group cannot have a higher priority than the maximum priority. @return the maximum priority that a thread in this thread group can have. @see #setMaxPriority @since JDK1.0Class ThreadGroup, ThreadGroup getParent()
Returns the parent of this thread group.Class ThreadGroup, void interrupt()First if the parent is not
null
thecheckAccess
method of the parent thread group is called with no arguments; this may result in a security exception. @return the parent of this thread group. The top-level thread group is the only thread group whose parent isnull
. @exception SecurityException if the current thread cannotaccessmodifythe parentthis thread group. @see java.lang.ThreadGroup#checkAccess() @see java.lang.SecurityException @see java.lang.RuntimePermission @since JDK1.0
Interrupts all threads in this thread group.Class ThreadGroup, boolean isDestroyed()First the
checkAccess
method of this thread group is called with no arguments; this may result in a security exception.This method then calls the
interrupt
method on all the threads in this thread group and in all of its subgroups. @exception SecurityException if the current thread is not allowed to access this thread group or any of the threads in the thread group. @see java.lang.Thread#interrupt() @see java.lang.SecurityException @see java.lang.ThreadGroup#checkAccess() @sinceJDK11.2
Tests if this thread group has been destroyed. @return true if this object is destroyed @since JDK1.1Class ThreadGroup, void setMaxPriority(int)
Sets the maximum priority of the group.First the
checkAccess
method of this thread group is called with no arguments; this may result in a security exception.Threads in the thread group that already have a higher priority are not affected. @param pri the new priority of the thread group. @exception SecurityException if the current thread cannot modify this thread group. @see #getMaxPriority @see java.lang.SecurityException @see java.lang.ThreadGroup#checkAccess() @since JDK1.0
This class provides ThreadLocal variables. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own independently initialized copy of the variable. ThreadLocal objects are typically private static variables in classes that wish to associate state with a thread (e.g. a user ID or Transaction ID).Class ThreadLocal, Object get()
Each thread holds an implicit reference to its copy of a ThreadLocal as long as the thread is alive and the ThreadLocal object is accessible; after a thread goes away all of its copies of ThreadLocal variables are subject to garbage collection (unless other references to these copies exist). @author Josh Bloch @version 1.8 0716 02/0802/9800 @sinceJDK11.2
Returns the value in the calling thread's copy of this ThreadLocal variable. Creates and initializes the copy if this is the first time the thread has called this method. @return the value of this ThreadLocalClass ThreadLocal, Object initialValue()
Returns the calling thread's initial value for this ThreadLocal variable. This method will be called once per accessing thread for each ThreadLocal the first time each thread accesses the variable with get or set. If the programmer desires ThreadLocal variables to be initialized to some value other than null ThreadLocal must be subclassed and this method overridden. Typically an anonymous inner class will be used. Typical implementations of initialValue will call an appropriate constructor and return the newly constructed object. @return the initial value for this ThreadLocal
TheClass Throwable, constructor Throwable(String)Throwable
class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or of one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Javathrow
statement. Similarly only this class or one of its subclasses can be the argument type in acatch
clause.Instances of two subclasses java.lang.Error and java.lang.Exception are conventionally used to indicate that exceptional situations have occurred. Typically these instances are freshly created in the context of the exceptional situation so as to include relevant information (such as stack trace data).
By convention class
Throwable
and its subclasses have two constructors one that takes no arguments and one that takes aString
argument that can be used to produce an error message.A
Throwable
class contains a snapshot of the execution stack of its thread at the time it was created. It can also contain a message string that gives more information about the error.Here is one example of catching an exception:
@author unascribed @version 1.try { int a[] = new int[2]; a[4]; } catch (ArrayIndexOutOfBoundsException e) { System.out.println("exception: " + e.getMessage()); e.printStackTrace(); }31 0144 02/2602/9700 @since JDK1.0
Constructs a newClass Throwable, Throwable fillInStackTrace()Throwable
with the specified error message. Also the method@#fillInStackTrace() is called for this object. @param message the error message. The error message is saved for later retrieval by the@#getMessage() method.
Fills in the execution stack trace. This method records within thisClass Throwable, String getLocalizedMessage()Throwable
object information about the current state of the stack frames for the current thread. This method is useful when an application is re-throwing an error or exception. For example:@return thistry { a = b / c; } catch(ArithmeticThrowable e) { a =NumberDouble.MAX_VALUE; throw e.fillInStackTrace(); }Throwable
object. @see java.lang.Throwable#printStackTrace()
Creates a localized description of thisClass Throwable, String getMessage()Throwable
. Subclasses may override this method in order to produce a locale-specific message. For subclasses that do not override this method the default implementation returns the same result asgetMessage()
. @return The localized description of thisThrowable
. @since JDK1.1
Returns theClass Throwable, void printStackTrace(PrintStream)errorterror message string of this throwable object. @return the error message string of thisThrowable
object if it was created with an error message string; ornull
if it was created with no error message.
Prints thisClass Throwable, void printStackTrace(PrintWriter)Throwable
and its backtrace to the specified print stream. @param sPrintStream
to use for output
Prints thisThrowable
and its backtrace to the specified print writer. @param sPrintWriter
to use for output @since JDK1.1
Thrown when an unknown but serious exception has occurred in the Java Virtual Machine. @author unascribed @version 1.8 0910 02/2102/9800 @since JDK1.0
Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declarednative
. @author unascribed @version 1.16 0918 02/2102/9800 @see java.lang.Runtime @since JDK1.0
Thrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported. @sinceJDK11.2
Thrown to indicate that the requested operation is not supported. @author Josh Bloch @version 1.Class UnsupportedOperationException, constructor UnsupportedOperationException(String)7 0912 02/2102/9800 @sinceJDK11.2
Constructs an UnsupportedOperationException with the specified detail message. @param message the detail message
Thrown when the "verifier" detects that a class file though well formed contains some sort of internal inconsistency or security problem. @author unascribed @version 1.8 0910 02/2102/9800 @since JDK1.0
Thrown to indicate that the Java Virtual Machine is broken or has run out of resources necessary for it to continue operating. @author Frank Yellin @version 1.9 0911 02/2102/9800 @since JDK1.0
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void. @author unascribed @version 1.6 098 02/2102/9800 @since JDK1.1