You are on page 1of 20

Package and Some Classes

Declaration of Package Usage of Package Package of Java Language

What is Package ?

Way to group a related class and interface into one unit


To resolve the name conflicts between class names

Declaration of Package
package PackageName ;

Declare at the beginning of source file

[Print1.java], [Print2.java]

MyTest

Prints
Print1.class Print2.class

Usage of Package

Use of absolute path name


Declare to describe the full package name To resolve conflicts between class names
MyTest.Prints.Print1 m1; MyTest.Prints.Print2 m2;

[AbsolutePath.java]

Use of import Statement


import packageName.className ;

Include all the classes in package

import packageName.*;
import MyTest.Prints.*;

[ImportTest.java]

java.lang Package

Basic class to enlarge the function of Java Provide classes according to primitive type (wrapper class)

Integer class, Double class,. ..

java.lang Class
Object
System

Wrapper Class Number

Character
Integer Long Float Double Boolean

String StringBuffer

Object Class

Super class of all classes All classes are to inherit the methods of Object class Method

Object clone() : To copy the object equally boolean equals(Object obj) :

Compare the object as parameter with the object which calls this method

int hashCode() : Calculate the hash code value of the object Class getClass() : To get Class object corresponding to object String toString() : Convert the object into string

[Ex 8.5]

wait(), notify() : To control the status of thread

Wrapper Class
Classes correspond to primitive type int -> Integer, char -> Character, double -> Double

Reasons

Role of home for constants and methods for each type When we need to deal with primitive type as object

Number Class
Abstract Class Super Class of Integer, Long, Float, Double

Method

abstract int intValue() : Convert into int type abstract long longValue() : Convert into long type abstract float floatValue() : Convert into float type abstract double doubleValue() : Convert into double type

Integer Class

Constant

public static final int MAX_VALUE = 2147483647 public static final int MIN_VALUE = -2147483648
static int parseInt(String s) :

Method

Convert a Number in String into int type Convert a number in String into int type with radix Convert into binary string form Convert into hexadecimal string form

static int parseInt(String s , int radix) :

static String toBinaryString(int i) :

static String toHexString(int i) :

Interger Class

[IntegerClass.java]

Interger.parseInt(s); Interger.toBinaryString(i); ...

As it is static method...

Double Class

Constant

public static final double MAX_VALUE =1.79769313486231570e+308 public static final double MIN_VALUE = 4.94065645841246544e-308 public static final double NaN = 0.0 / 0.0 public static final double NEGATIVE_INFINITY = -1.0 / 0.0 public static final double POSITIVE_INFINITY = 1.0 / 0.0

Double Class

the parameter is NaN or not.


static boolean isInfinite(double v) :

Check whether the parameter is infinite or not.

static Double valueOf(String s) : Method static long doubleToLongBits(double value) :

Convert the bits represented by double type into long type bit pattern

static boolean isNaN(double v) :


Check whether Convert String into Double type

Boolean Class

Constant

public static final Boolean TRUE = new Boolean(true) public static final Boolean FALSE = new Boolean(false) Boolean(boolean b) :

Method

Constructor to create boolean object receiving the initial value b Constructor to receive the string value "true or "false Return the boolean value of object Return the boolean value of system attribute Return the Boolean value correspond to string s

Boolean(String s) :

boolean booleanValue() :

static boolean getBoolean(String name) :

static Boolean valueOf(String s) :

Character Class

Constant

public static final int MAX_RADIX = 36 public static final char MAX_VALUE =\ffff public static final int MIN_RADIX = 2 public static final char MIN_VALUE =\0000

Method

Character(char value) : Constructor to initialize the object as value char charValue() : Convert into char type static boolean isDigit(char ch) : Test whether is digit? static boolean isLetter(char ch) : Test whether is letter? static boolean isLetterOrDigit(char ch) : Return when it is letter or digit.

[CharacterClass.java]

String Class

Method

char charAt(int index) :

Return the character at specific position in string Return the length of string Convert the string into upper character Convert the string into lower character Remove the white space before/after string Make the sub string from beginIndex to the end of the string

int length() :

String toUpperCase() :

String toLowerCase() :

String trim() :

String substring(int beginIndex) :

StringBuffer Class
Provide the string sequence operation Method

StringBuffer append(Type obj) :

Append the obj(to be changed into string) to string Insert obj(to be changed into string) into specified position

StringBuffer insert(int offset, Type obj) :

Object boolean long

String char float

char[] int double

StringBuffer Class

String now = new java.util.Date().toString(); StringBuffer strbuf = new StringBuffer(now); strbuf.append(" : ").append(now.length).append('.'); System.out.println(strbuf.toString());

System Class

Class for Java Virtual Machine and the control and security for OS system Define the standard input and output Field public static InputStream in :

Stream to read data from standard input device Stream to output data to standard output device Standard Error Stream to output error message

public static PrintStream out :

public static PrintStream err :

You might also like