Micro-Scholarship, What it is, How can it help me.pdf
Fileoperations.pptx
1. Difference between constructor and method in
Java
Java Constructor Java Method
A constructor is used to initialize the
state of an object.
A method is used to expose the behavior
of an object.
A constructor must not have a return
type.
A method must have a return type.
The constructor is invoked implicitly. The method is invoked explicitly.
The Java compiler provides a default
constructor if you don't have any
constructor in a class.
The method is not provided by the
compiler in any case.
The constructor name must be same as
the class name.
The method name may or may not be
same as the class name.
2. STRING BUFFER
Java StringBuffer class is used to create mutable (modifiable) String objects.
The StringBuffer class in Java is the same as String class except it is mutable
i.e. it can be changed.
What is a mutable String?
A String that can be modified or changed is known as mutable String.
StringBuffer and StringBuilder classes are used for creating mutable
strings.
3. Method Description
append(String s) It is used to append the specified string with this
string. The append() method is overloaded like
append(char), append(boolean), append(int),
append(float), append(double) etc.
insert(int offset, String s) It is used to insert the specified string with this string
at the specified position. The insert() method is
overloaded like insert(int, char), insert(int, boolean),
insert(int, int), insert(int, float), insert(int, double)
etc.
replace(int startIndex, int
endIndex, String str)
It is used to replace the string from specified
startIndex and endIndex.
STRING BUFFER METHODS
4. Method Description
delete(int startIndex, int endIndex) It is used to delete the string from
specified startIndex and endIndex.
reverse() is used to reverse the string.
capacity() It is used to return the current capacity.
ensureCapacity(int minimumCapacity) It is used to ensure the capacity at
least equal to the given minimum.
6. File Operations
A named location used to store related information is known as a File.
Stream:A series of data is referred to as a stream.
In Java, Stream is classified into two types,
i.e., Byte Stream and Character Stream.
Byte Stream is mainly involved with byte data
A file handling process with a byte stream is a process in which an
input is provided and executed with the byte data.
Character Stream is mainly involved with character data.
A file handling process with a character stream is a process in which
an input is provided and executed with the character data.