Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Language Package.

Similar presentations


Presentation on theme: "The Language Package."— Presentation transcript:

1 The Language Package

2 Object The Object class sits at the top of the class hierarchy tree in the Java development environment. Every class in the Java system is a descendent (direct or indirect) of the Object class . The only constructor supported by this class is :Object()

3 Methods are : class getClass() Returns the runtime class of an object
is a final method Class object for a variety of information about the class, such as its name, its superclass, and the names of the interfaces that it implements. E.g. void PrintClassName(Object obj) { System.out.println("The Object's class is " + obj.getClass().getName()); }

4  int hashCode()           Returns a hash code value for the object.
boolean equals(Object obj)           compare two objects for equality. e.g Integer one = new Integer(1), anotherOne = new Integer(1); if (one.equals(anotherOne)) System.out.println("objects are equal");

5 The toString() Method Object's toString method returns a String representation of the object. You can use toString to display an object.

6 clone() clone() is a method in the Java programming language for object duplication . Only classes that implement the Cloneable interface can be cloned If you try to call clone( ) on a class that does not implement Cloneable, a CloneNotSupportedException is thrown. The finalize() Method The Object class provides a callback method, finalize(), that may be invoked on an object when it becomes garbage. Object's implementation of finalize() does nothing—you can override finalize() to do cleanup,

7 Class public final class Class extends Object
Instances of the class Class represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as a Class object The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.

8 void printClassName(Object obj) { System. out
void printClassName(Object obj) { System.out.println("The class of " + obj + " is " + obj.getClass().getName()); } static Class forName(String className)           Returns the Class object associated with the class or interface with the given string name.

9  Class getClass()           Returns the runtime class of an object.
Boolean equals(Object obj)           Indicates whether some other object is "equal to" this one. int hashCode()           Returns a hash code value for the object.

10 protected void finalize() throws Throwable
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

11 provide object methods for the eight primitive types

12 Boolean booleanbooleanValue()           Returns the value of this Boolean object as a boolean primitive.  boolean equals(Object obj)           Returns true if and only if the argument is not null and is a Boolean object that represents the same boolean value as this object static booleangetBoolean(String name)           Returns true if and only if the system property named by the argument exists and is equal to the string "true". 

13 Int hashCode()           Returns a hash code for this Boolean object.
 String toString()           Returns a String object representing this Boolean's value. static Boolean valueOf(String s)           Returns a Boolean with a value represented by the specified String.

14  char charValue()           Returns the value of this Character object .
Int compareTo(Character anotherCharacter)           Compares two Characters numerically. static boolean isDigit(char ch)           Determines if the specified character is a digit. static boolean isLowerCase(char ch)           Determines if the specified character is a lowercase character. static boolean isTitleCase(char ch)           Determines if the specified character is a titlecase character.

15 static boolean isUpperCase(char ch)           Determines if the specified character is an uppercase character.
static boolean isWhitespace(char ch)           Determines if the specified character is white space according to Java. static char toLowerCase(char ch)           The given character is mapped to its lowercase equivalent; if the character has no lowercase equivalent, the character itself is returned.  String toString()           Returns a String object representing this character's value. static char toTitleCase(char ch)           Converts the character argument to titlecase.

16

17 As an argument of a method that expects an object (often used when manipulating collections of numbers). To use constants defined by the class, such as MIN_VALUE and MAX_VALUE, that provide the upper and lower bounds of the data type. To use class methods for converting values to and from other primitive types, for converting to and from strings, and for converting between number systems

18 public String toString();
public boolean equals(Object obj); public int hashCode(); public int intValue(); public static String toString(int i); public static String toString(int i, int radix); public static String toHexString(long i); public static String toOctalString(long i); public static String toBinaryString(long i); public static int parseInt(String s) throws NumberFormatException;

19 Integer Class static int parseInt(String s) Returns an integer
String toString() Returns a String object representing the value of this Integer static Integer valueOf(String s) Returns an Integer object holding the value of the specified string representation.

20 byte byteValue() short shortValue() int intValue() long longValue() float floatValue() double doubleValue() int compareTo(Float anotherFloat) Converts the value of this Number object to the primitive data type returned. Compares this Number object to the argument.

21 Math abs(int) ceil(double) exp(double) floor(double) log(double)
Returns the absolute integer value of a. ceil(double) This method returns the next whole number up that is an integer. exp(double) Returns the exponential number e( ) raised to the power of a. floor(double) Returns the "floor" or largest whole number less than or equal to a. log(double) Returns the natural logarithm (base e) of a. max(int, int) Takes two int values, a and b, and returns the greater number of the two. sqrt(double) Returns the square root of a.

22 min(double, double) /(int,int)
Takes two double values, a and b, and returns the smallest number of the two. pow(double, double) Returns the number a raised to the power of b. random() Generates a random number between 0.0 and 1.0. round(double) Rounds off a double value by first adding 0.5 to it and then returning the largest integer that is less than or equal to this new value. sin(double) Returns the trigonometric sine of an angle. cos(double) Returns the trigonometric cosine of an angle. tan(double) Returns the trigonometric tangent of an angle.

23 The java.lang.ref package defines classes that allow Java programs to interact with the Java garbage collector. Cache can be implemented that grows and shrinks in size according to the amount of available system memory. java.lang.reflect Provides classes and interfaces for obtaining reflective information about classes and objects

24 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 SecurityManager class contains many methods with names that begin with the word check . checkPermission(Permission perm)


Download ppt "The Language Package."

Similar presentations


Ads by Google