Category Archives: Java

Java.io.CharArrayWriter class in Java | Set 2

CharArrayWriter class in Java | Set 1 Methods: append (char Sw) : java.io.CharArrayWriter.append(char Sw) appends a single character to the Writer. Syntax: public CharArrayWriter append(char Sw) Parameters : Sw : character to be append Return : CharArrayWriter append (CharSequence char_sq) : java.io.CharArrayWriter.append(CharSequence char_sq) appends specified character sequence to the Writer. Syntax: public CharArrayWriter append(CharSequence char_sq)… Read More »

Java.io.CharArrayWriter class in Java | Set 1

java.io.CharArrayWriter class creates a character buffer that can be used as a writer. The buffer automatically grows when data is written to the stream. The data can be retrieved using toCharArray() and toString(). Declaration: public class CharArrayWriter extends Writer Constructor : CharArrayWriter() : Creating a CharArrayWriter from a specified character array. CharArrayWriter(int size) : Creating… Read More »

Java.io.FileInputStream Class in Java

FileInputStream is useful to read data from a file in the form of sequence of bytes. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. Constructor and Description FileInputStream(File file) :Creates an input file stream to read from the specified File object. FileInputStream(FileDescriptor… Read More »

java.io.CharArrayReader Class in Java

java.io.CharArrayReader class creates a character buffer using a character array. Declaration: public class CharArrayReader extends Reader Constructor : CharArrayReader(char[] char_array) : Creates a CharArrayReader from a specified character array. CharArrayReader(char[] char_array, int offset, int maxlen) : Creates a CharArrayReader from a specified part of character array. Methods: read() : java.io.CharArrayReader.read() reads a single character and… Read More »

java.io.FilterOutputStream Class in Java

Java.io.FilterOutputStream class is the superclass of all those classes which filters output streams. The write() method of FilterOutputStream Class filters the data and write it to the underlying stream, filtering which is done depending on the Streams. Declaration : public class FilterOutputStream extends OutputStream Constructors : FilterOutputStream(OutputStream geekout) : Creates an output stream filter. Methods:… Read More »

NaN (Not a Number) in Java

Can You guess the output of following code fragment: Yes, You guessed it right: ArithmeticException Output: Exception in thread “main” java.lang.ArithmeticException: / by zero at traps.Test.main(Test.java:3) Now guess the Output of : Did you guessed it right ? Output: NaN What is NaN? “NaN” stands for “not a number”. “Nan” is produced if a floating… Read More »

getproperty() and getproperties() methods of System Class in Java

The System class in Java has two methods used to read system properties: getProperty: The System class has two different versions of getProperty. Both retrieve the value of the property named in the argument list. The simpler of the two getProperty methods takes a single argument. getProperties: The java.lang.System.getProperties() method determines the current system properties. Description… Read More »

Constructors in Java

Constructors are used to initialize the object’s state. Like methods, a constructor also contains collection of statements(i.e. instructions) that are executed at time of Object creation. When is a Constructor called ? Each time an object is created using new() keyword at least one constructor (it could be default constructor) is invoked to assign initial… Read More »

Java.io.InputStream Class in Java

InputStream class is the superclass of all the io classes i.e. representing an input stream of bytes. It represents input stream of bytes. Applications that are defining subclass of InputStream must provide method, returning the next byte of input. A reset() method is invoked which re-positions the stream to the recently marked position. Declaration :… Read More »

Java.io.Console class in Java

The Java.io.Console class provides methods to access the character-based console device, if any, associated with the current Java virtual machine. The Console class was added to java.io by JDK 6. Important Points: It is used to read from and write to the console, if one exists. Console is primarily a convenience class because most of… Read More »

Java.io.StreamTokenizer Class in Java | Set 2

StringTokenizer Class in Java | Set 1 Methods: parseNumbers() : java.io.StreamTokenizer.parseNumbers() specifies that the number in StreamTokenizer is parsed, so that each character – ” 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ” has a numeric attribute. When the parser encounters a word token that has the format of a double precision… Read More »