Package
- This encapsulates the version data associate with a package.
- This package version information is important as there are multiple packages and java program may want to know the version of the package that currently using.
- It have methods like
static packages[] getPackages() - which gets all the packages about the aware of the invoking java program.
String getName()- Returns the name of the invoking package.
String getImplementationTitle()- Returns the title of the invoking package.
String getImplementationVendor()- Returns the name of the inventor of the invoking package.
String getImplementationVersion()- Returns the version of the invoking package.
// Demonstrate Package
public class PkgTest
{
public static void main(String args[]) {
Package pkgs[];
pkgs = Package.getPackages();
for(int i=0; i < pkgs.length; i++)
System.out.println(
pkgs[i].getName() + " " +
pkgs[i].getImplementationTitle() + " " +
pkgs[i].getImplementationVendor() + " " +
pkgs[i].getImplementationVersion()
);
}
}
Output:
sun.reflect Java Runtime Environment Oracle Corporation 1.8.0_121
java.util Java Runtime Environment Oracle Corporation 1.8.0_121
RuntimePermission
- It is relates to the java security mechanism.
Throwable
- It supports the exception handling system and the class where all the exception classes are derived.
SecurityManager
- It supports the Java's security system where we can get the current security manager by calling getSecurityManager() which is defined by the System class.
StackTraceElement
- It defines the individual element of a stack trace when an exception occurs which is called as stack frame.
- Each stack frame represents the execution point which describes the name of the class, methods, file and the source code line number.
- It has one constructor as follows.
StackTraceElement(String className, String methName, string fileName, int line)
- An array of stack trace elements can be get by getStackTrace() method.
- It have methods like getClassName(), getMethodName(), getFileName() and getLineNumber() to return name of the class, method, file and the source code line number.
- hashCode() returns the hash code of the stack trace element.
Enum
- An Enum is a generic class where all the enumerations created by inheriting that.
class Enum< E extends Enum <E>>
- E stands for the enumeration type.
- Enum has no public constructors.
ClassValue
It is a generic type which is used to associate a value with a type.
Class ClassValue<T>
The CharSequence Interface
- This is a interface which defines methods to grant read-only access to a sequence of characters.
- This is implemented by Sting, StringBuffer, StringBuilder.
The Comparable Interface
- A class that implement Comparable have objects in a meaningful manner.
It is generic which is defined as follows:
interface Comparable<T>
int compareTo(T obj) is a method which is used to determine what Java calls the natural ordering of instances of a class.
The Appendable Interface
Objects of a class that implements Appendable have a character or character sequences appended to it.
It defines the following methods.
Appendable append(char ch) throws IOException //append character to the invoking object.
Appendable append(CharSequence chars) throws IOException //append character sequence to the invoking object.
Appendable append(CharSequence chars, int begin, int end) throws IOException //specifies the start and end of the character sequence.
The Iterable Interface
- It is an interface which must be implement by the class to use the for-each version of the for loop.
It is a generic of the form as follows
interface Iterable<T>
T is the type of the object being iterated.
The Readable Interface
- It indicates that an object can be used as a source for characters.
int read(CharBuffer buf ) throws IOException
- This method reads characters into buf. It returns the number of characters read, or –1 if an EOF is encountered.
The AutoCloseable Interface
- It supports try-with-resources statement which is some times refer as automatic resource management (ARM).
- It releases the resources when it is no longer needed.
- It defines only close() method as follows:
void close( ) throws Exception
- This method closes the invoking object, releasing any resources that it may hold.
The Thread.UncaughtExceptionHandler Interface
- The classes implement this interface to handle uncaught exceptions.
It declares only one method as follows:
void uncaughtException(Thread thrd, Throwable exc)
thrd is a reference to the thread that generated the exception and exc is a reference to the exception.