Sie sind auf Seite 1von 20

A tour of new features

By: Saba Chaudhary

java.lang Overview
Object Math The wrapper classes Thread, ThreadGroup and Runnable String

StringBuffer
Class Class Loader Interfaces
CharSequence Interface Comparable Interface

Java.lang (Non-Objectives)
Clone() & Cloneable Interface

The Cloneable interface defines no members. It is used to indicate that a class allows a bitwise copy of an object(i.e, a clone) to be made.If you try to call clone() on a class that doesnt implement Cloneable,a CloneNotSuppprtedException is thrown.Const. for an obj being cloned is not called.

Security Manager

Exception s

The security manager is a class that your classes can subclass to to create a security manager.

The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.

java.lang (Non-Objectives)
Errors

ClassLoade r The class ClassLoader is an abstract

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions

class. Applications can create subclasses that extend ClassLoader in order to load classes in some way other than the way they are normally loaded by the Java run-time System .

java.lang.Object
Class Object is the root of the class

hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
If a class doesnt extend another

Methods provided by Object

class:
clone() equals() finalize()

class, then compiler extends it from Object. For instance:


public class MyName { // stuff }

is created by the compiler as:


public class MyName extends Object{ // stuff}

Thread control - wait(), notify(), notifyAll() General - equals(), toString() Not tested -finalize(), hashCode(), clone(), getClass() public boolean equals( Object object ) - should be overrided - provides deep comparison - not the same as ==! == checks to see if the two objects are actually the same object equals() compares the relevant instance variables of the two objects public String toString() should be overrided returns a textual representation of the object useful for debugging

class
Class encapsulates the runtime state of an object/interface. Objects of Class type are created automatically when classes are loaded. The getClass() mathod is used to obtain a class object. Class is a generic type declared as class Class<T> T is the class/interface represented.
Commonly used methods defined by Class : forName() getClass() getSuperClass() getClassLoader() and many more.. Usage Class<?> clobj; Clobj =x.getClass() ; //get Class reference SOP(x is object of type: +clobj.getName());

classloader
This class is the abstract superclass of objects that

know how to load Java classes into a Java VM. Given a ClassLoader object, you can dynamically load a class by calling the public loadClass() method, specifying the full name of the desired class. You can obtain a resource associated with a class by calling getResource(), getResources(), and getResourceAsStream(). Many applications do not need to use ClassLoader directly; these applications use the Class.forName() and Class.getResource() methods to dynamically load classes and resources using the ClassLoader object that loaded the application itself.

Transcendental Functions
The following methods accept a double parameter for an angle in radians and return the result of their respective transcendental function: static double sin(double arg) Returns the sine of the angle specified by arg in radians. cos(),tan(),asin(),acos(),atan() static double atan2(double x, double y) returns the angle whose tangent is x/y. sinh(),cosh(),tanh()

Exponential Functions
Math defines the following exponential methods: static double cbrt(double arg) Returns the cube root of arg. static double exp(double arg) Returns e to the arg. static double expm1(double arg) Returns e to the arg1 static double log(double arg) Returns the natural logarithm of arg.

Rounding Functions
The Math class defines several methods that provide various types of rounding operations. static int abs(int arg) static int max(int x,int y), static double floor(double arg), static double ceil(double arg), min(),max(),round() many more

In addition to the methods just shown, Math defines several other methods, which are: copySign(), IEEEremainder(), hypot(), random(), toDegrees(), toRadians()

Thread, ThreadGroup and Runnable


The Runnable interface and the Thread and ThreadGroup classes support multithreaded programming. Runnable: This interface must be implemented by any class that will initiate a separate thread of execution. It defines only one abst. method, void run() ,which is the entry point to the thread. Thread: It creates a new thread of execution.
It defines the foll commonly used constructors:
Thread( ) Thread(Runnable threadOb) Thread(Runnable threadOb, String threadName) Thread(String threadName) Thread(ThreadGroup groupOb, Runnable threadOb) Thread(ThreadGroup groupOb, Runnable threadOb, String threadName) Thread(ThreadGroup groupOb, String threadName)

threadOb is an instance of a class that implements the Runnable interface and defines where execution of the thread will begin. The name of the thread is specified by threadName. When a name is not specified, one is created by the Java Virtual Machine. groupOb specifies the thread group to which the new thread will belong. When no thread group is specified, the new thread belongs to the same group as the parent thread.

The following constants are defined by Thread: MAX_PRIORITY MIN_PRIORITY NORM_PRIORITY They specify the maximum, minimum, and default thread priorities. Methods defined by Thread:
static int activeCount() :returns no. of threads in group to which the thread

belongs.
static Thread currentThread() : returns a Thread object that encapsulates the thread that calls this method. final String getname() long getID() final int getPriority() void interrupt() void start() many more

ThreadGroup: It creates a group of threads. It defines these two constructors: ThreadGroup(String groupName) ThreadGroup(ThreadGroup parentOb, String groupName) groupName specifies the name of the thread group. The first version creates a new group that has the current thread as its parent. In the second form, the parent is specified by parentOb They offer a convenient way to manage groups of threads as a unit. eg: useful when u want to suspend & resume a no. of related threads. Methods: int activeCount() int activeGroupCount() //returns no. of groups for which invoking thread is a parent. final void destroy() .

ThreadLocal and InheritableThreadLocal


Java defines two additional threadrelated classes in java.lang: ThreadLocal Used to create thread local variables. Each thread will have its own copy of a thread local variable.

Throwable
The Throwable class supports Javas exception-handling system and is the class from which all exception classes are derived.

Enum
All enumerations automatically inherit Enum. Enum is a generic class that is declared as : class Enum<E extends Enum<E>>

InheritableThreadLocal Creates thread local variables that may be inherited.

Here, E stands for the enumeration type. Enum has no public constructors.
clone() , comopareTo(), equals() are some of the methods it provides.

The CharSequence Interface


It defines methods that grant readonly access to a sequence of characters. This interface is implemented by String, StringBuffer, and StringBuilder. It is also implemented by CharBuffer, which is in the java.nio package

The Comparable Interface


Objects of classes that implement Comparable can be ordered. In other words, classes that implement Comparable contain objects that can be compared in some meaningful manner. Comparable is generic and is declared like this: interface Comparable<T> Here, T represents the type of objects being compared. The Comparable interface declares one method that is used to determine what Java calls the natural ordering of instances of a class. The signature of the method is shown here: int compareTo(T obj) Methods provided : charAt(), length(), toString(), subSequence() .

java.lang.ref java.lang.reflect

java.lang.ref
The garbage collection facilities in Java automatically determine when no references exist to an object. The object is then assumed to be no longer needed and its memory is reclaimed. The classes in the java.lang.ref package provide more flexible control over the garbage collection process. For example, assume that your program has created numerous objects that you want to reuse at some later time. You can continue to hold references to these objects, but that may require too much memory. Instead, you can define soft references to these objects. An object that is softly reachable can be reclaimed by the garbage collector, if available memory runs low. In that case, the garbage collector sets the soft references to that object to null. Otherwise, the garbage collector saves the object for possible future use. Aprogrammer has the ability to determine whether a softly reachable object has been reclaimed. If it has been reclaimed, it can be re-created. Otherwise, the object is still available for reuse. You may also create weak and phantom references to objects.

Java.Lang.Reflect
Reflection is the ability of a program to analyze itself. The java.lang.reflect package provides the ability to obtain information about the fields, constructors, methods, and modifiers of a class. Among other reasons, you need this information to build software tools that enable you to work with Java Beans components. The tools use reflection to determine dynamically the characteristics of a component. java.lang.reflect defines several classes, including Method, Field, and Constructor. It also defines several interfaces, including AnnotatedElement, Member, and Type. In addition, the java.lang.reflect package includes the Array class that enables you to create and access arrays dynamically.

Thank s!

Content Taken from the book Complete Reference Java 7th Edition by Herbert Schildt

Das könnte Ihnen auch gefallen