Advanced Java Unit 4
Advanced Java Unit 4
• The Matcher class is used to invoke the regex engine with the intention of
performing match operations.
• Pattern Class
• Purpose: Represents a compiled regular expression. Once compiled, the pattern can
be reused multiple times for matching operations.
• Methods:compile(String regex): Compiles the given regular expression into a
pattern.matcher(CharSequence input): Creates a matcher that can be used to
perform matching operations on the given input sequence.
Matcher Class
Methods:find(): Attempts to find the next subsequence of the input sequence that matches the pattern.
matches(): Attempts to match the entire input sequence against the pattern.
replaceAll(String replacement): Replaces every subsequence that matches the pattern with the given replacement
string.split(CharSequence input): Splits the input sequence around matches of the pattern.
SERIALIZATION
❑ Serialization is a process of converting an object into a sequence of bytes which can be
persisted to a disk or database or can be sent through streams. The reverse process of
creating object from sequence of bytes is called deserialization
❑ The java object is serializable if its class or any of its subclasses implements
java.io.serializable or its sub interface java.io.externalizable interface.
Advantages of Serialization
1.To save/persist the state of an object.
2.It is mainly used to travel the object’s state on the network (which is known as marshaling).
Serialization.java
Steps to Serialize an object:
Step1: java objects become Serializable only when the class of that object implement the java.io.Serializable marker
interface.
The readObject() method of ObjectInputStream class is used to read an object from the objectinputstream. It
reads the class of the object, the signature of the class, static, non-static fields and supertype.
Serialization.java
Pipes in IO provides a link between two threads running in JVM at the same time. So, Pipes are used both as
source or destination.
•PipedInputStream is also piped with PipedOutputStream. So, data can be written using PipedOutputStream
and can be written using PipedInputStream.But, using both threads at the same time will create a deadlock
for the threads.
•A pipe is said to be broken if a thread that was providing data bytes to the connected piped output stream is
no longer alive.
Methods:
Java.io.PipedOutputStream Class in Java
• The Java SequenceInputStream combines two or more other InputStream's into one.
• First the SequenceInputStream will read all bytes from the first InputStream, then all bytes from the second
InputStream.
• That is the reason it is called a SequenceInputStream, since the InputStream instances are read in sequence.
Sequence
PushbackInputStream