You are on page 1of 11

Class: StringBuilder

Package: java.lang Objects of this class are mutable Return Type Name StringBuilder() StringBuilder(String str) StringBuilder append(boolean b) append(char c) append(char [] str) append(double d) append(int i) append(float f) append(long lng) append(String str) append(Object obj) append(StringBuffer sb) char charAt(int index) int String length() substring(int start) Description Appends the string representation of the type of the passed argument. Type Constructor Method

String

substring(int start, int end)

int int int int StringBuilder

indexOf(String str) indexOf(String str, int fromIndex) lastIndexOf(String str) lastIndexOf(String str,int fromIndex) insert(int offset, boolean b) insert(int offset, long lng) insert(int offset, char c) insert(int offset, char [] str) insert(int offset, double d) insert(int offset, float f) insert(int offset, int i) insert(int offset, Object obj) insert(int offset, String b)

Returns the char in the sequence at the specified index. Returns the length of the sequence. Returns a new string from a sequence starting from the specified index till the end of the sequence. Returns a new string from a sequence starting from the specified start index and ends at the specified end index. Returns the index of the first occurrence of the string. Returns the index of the first occurrence of the string starting search from the specified index. Returns the last index of the specified string. Returns the last index of the specified string starting search from the specified index. Inserts the string of the second argument representation into the sequqnce.

Method Method Method

Method

Method Method Method Method Method

1

Class: File Package: java.io
It's a class that concerned with file and directory manipulation. Return Type Name Description File(String filename) File(File parent,String child) boolean boolean boolean boolean boolean boolean boolean boolean String [] canRead() canWrite() canExecute() exists() mkdir() isFile() isDirectory() createNewFile() list() Type

Creates a new file instance given Constructor the file path name. Creates a new child file instance Constructor from the specified parent file. Returns true if the file is allowed Method for execution. Returns true if the file is allowed Method for writing. Returns true if the file is allowed for reading. Returns true if the file exits. Creates a new directory. Returns true if a specified file denoted by the abstract pathname is normal file. Returns true if a specified file denoted by the abstract pathname is normal directory. Creates an empty file named by the abstract pathname if it doesn’t exist. Returns an array of strings containing the files and directories names denoted by the abstract pathname. Returns an array of abstract pathname denoting (referring to) the files in the directory denoted by this abstract pathname.
2

Method Method Method Method Method

Method

File []

listFiles()

Method

Long

length()

Gets the file size

Method

3

Class: ObjectOutputStream Package: java.io.OutputStream
Serializes (writes) object state to an Output Stream. Return Name Description Type Type ObjectOutputStream() Creates an object output stream Constructor ObjectOutputStream(OutputStream out) that writes to the specified output ObjectOutputStream(FileOutputStream stream. out) void writeObject(Object obj) Writes the specified object to the Method ObjectOutputStream

Class: ObjectInputStream Package: java.io.InputStream
Deserializes a serialized object from an Input Stream. Return Name Description Type Type ObjectInputStream() Creates an object intput stream Constructor ObjectInputStream(InStream out) that reads from the specified ObjectInputStream(FileInputStream out) input stream. Object readObject() reads an object from the Method ObjectInputStream

Class: Consol Package: java.io
Provides for system input and output data streams, serialization and file system. Return Type Name Description Consol String Char[] Type

format(String fmt, Object…args) Writes the formatted string to the Method printf(String format, Object…args) consol's output stream readLine() [Provides formatted prompt,] Method readLine(String fmt,Object…args) reads a single line of text from consol. readPassword() [provides formatted prompt,] Method readPassword(String fmt, Object… reads password from the consol args) with echoingdisabled.

4

Class: PrintWriter Package: java.io.Writer
This class prints formatted presentation of objects to text output stream. Return Type Name Description PrintWriter(File file) PrintWriter(OutputStream out) PrintWriter void append(char c) append(CharSequence csn) close() Type

Creates a new printwriter for the Constructor specified file (without automatic flushing). Creates a new printwriter for the Constructor specified output stream (without automatic flushing). Appends the specified character Method or character sequences to this writer. Closes the stream and releases Method any system resources associated to it. Flushes the stream. Method Method

void

flush()

PrintWriter format(String format, Object…args) Writes a formatted string to the printf(String format,Object…args) writer using the specified string and args.

Class: NumberFormat
Package: java.text Return Type Name static getInstance() final NumberFormat static getInstance(Local loc) NumberFormat static getNumberInstance() final NumberFormat static getNumberInstance(Local loc) NumberFormat static final NumberFormat getCurrencyInstance() Description Returns the default number format for the current default local. Returns the number format of the specified local. Formats and parses the default numbers format in the default local one. Formats and parses the number format in the specified local one. Returns the currency format in the default local one. Type Method Method Method Method Method

5

static NumberFormat static final NumberFormat static NumberFormat static final NumberFormat static NumberFormat final String number

Examples on parse

getCurrencyInstance(Local loc) Returns the currency format in the specified local one. getIntegerInstance() Formats and parses the number integer format of the default local. Floating point numbers are rounded. getIntegerInstance(Local loc) Returns the integer numbers in the specified local format. getPercentInstance() Formats and parses the percentages in the default local one. getPercentInstance(Local loc) Returns a percentage format of the specified local. format(long number) Returns number into string format(double number) format parse(String s) -Parses a string into number. - Throws ParseException. -parses the beginning of string and stops till it reaches to a character. - it’s also used for parsing currency NumberFormat nf = new NumberFormat.getInstance(); String one = “456abs”; String two = “-2.5165e10”; String one = “x85.3”; System.out.println(nf.parse(one)); === 456 System.out.println(nf.parse(two)); === -2.165 System.out.println(nf.parse(three)); === throws ParseException

Method Method

Method Method Method Method Method

6

Class: NumberFormat
- Subclass of NumberFormat class Adds more features for formatting floating point number, specifying precisions, leading and trailing zeros, and prefixes and suffixes. DecimalFormat can be obtained in 2 ways: 1-Inistantiate a new DecimalFormat from one of its constructors, which is useful when using default local. 2-Using getInstance() method and cast the return type to DecimalFormat, this’s useful when using speicified local settings. Symbol Location Localized? Meaning 0 Number Yes Digit # Number Yes Digit, zero shows as absent . Number Yes Decimal separator or monetary decimal separator Number Yes Minus sign , Number Yes Grouping separator E Number Yes Separates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix. ; Subpattern Yes Separates positive and negative subpatterns boundary % Prefix or Yes Multiply by 100 and show as percentage suffix \u2030 Prefix or Yes Multiply by 1000 and show as per mille suffix ¤ (\u00A4) Prefix or No Currency sign, replaced by currency symbol. If doubled, suffix replaced by international currency symbol. If present in a pattern, the monetary decimal separator is used instead of the decimal separator. ' Prefix or No Used to quote special characters in a prefix or suffix, for suffix example, "'#'#" formats 123 to "#123". To create a single quote itself, use two in a row: "# o''clock". Examples double d = 1234567.437 DecimalForamt one = new DeciamlFormat(“###,###,###”); DecimalForamt two = new DeciamlFormat(“000,000,000.00000”); DecimalForamt three = new DeciamlFormat(“$#,###,###.##”); Output of the following: One: 1,234,567.437 two: 001,234,567.43700 three: $1,234,567.44

7

Class: DateFormat Package: java.text
It's an abstract class that formates and parses dates and times for a specific local. Return Type Name Description static final DateFormat static final DateFormate static final DateFormat static final DateFormat static final DateFormat static final DateFormat final String Date getDateInstance() Returns dates in formate of the default local. Type Method

getDateInstance(int style,Local loc) -Returns date in style and format Method of the specified local. -Available formatting style: FULL,LONG,MEDIUM,SHORT getTimeInstance() Returns time in default local format Method

getTimeInstance(int style,Local loc) -Returns time in format and style Method of the specified local. -Available formatting style: FULL,LONG,MEDIUM,SHORT geetDatTimeInstance() Returns date and time in format Method of local default. getDateTimeInstance(int style,Local -Returns date and time in format Method loc) and style of the specified local. -Available formatting style: FULL,LONG,MEDIUM,SHORT format(Date date) Represents time in milliseconds Method parse(String source) Returns string into date format Method

8

Class: Scanner Package: java.util
It's a text scanner that parses primitive types and strings into tokens. (token is a group of characters).
Delimiters for tokens are whitespace or a regular expression.

Return Type

Name public Scanner(File source) throws FileNotFound public Scanner(InputStream source) public Scanner(String source)

Description

Type Constructor Constructor Constructor

boolean boolean boolean String String String Scanner Scanner

hasNext() hasNext(Pattern pattern) hasNext(String pattern) next() next(Pattern pattern) next(String pattern) useDelimiter(Pattern pattern) useDelimiter(String pattern)

Returns true if there's another token in the scanner input Returns true if the next complete token matches the specified pattern Returns true if the next token matches the pattern constructed from the specified string. Finds and returns the next complete token from this scanner Returns the next token if it matches the specified pattern Returns the next token if it matches the pattern constructed from the specified string Sets the scanner's delimiter to the specified pattern Sets the scanner's delimiter to the pattern constructed from the specified string

Method Method Method Method Method Method Method Method

9

Package: java.util.regex Class: Pattern
Pattern object is a compiled representation of the regular expression. It has no public constructor and it's a final
class

Return Type static pattern Matcher

Name compile(String regex)

Description

Type

Compile the given regular Method expression into pattern Matcher(CharSequence input) Creates a matcher that will match Method the given input against the pattern static matches(String regex, -Compiles the given regex. Method boolean CharSequence input) -matches the compiles regex against the given input . String pattern() Returns the regex in which the Method pattern was compiled String[] split(CharSequence input) Splits the given input sequence Method from the pattern. String[] split(CharSequence input, int limit) Splits the given input sequence Method from the pattern "limit" times. Class: Matcher An engine that performs match operation on the character sequence by interpreting a pattern. Return Type Name Description Type int end() Returns the index of the last Method matched character, plus one. int first() Returns the index of the first character matched, plus one. Method

Metacharacters of Regular Expressions Metacharacter . * + ? \d \s Description Any character Match the preceding character any number of times Match the previous character one or more times Match the previous character 0 or one time Digit 0-9 Whitespace character

10

\w [] ()

Word character (letters, numbers and underscore) Match anything inside the brackets for one character position once Use parentheses for grouping together search expressions

11