Found 9150 Articles for Object Oriented Programming

What is Scanner class in Java? when was it introduced?

Maruthi Krishna
Updated on 01-Aug-2019 14:03:58

530 Views

Until Java 1.5 to read data from the user programmers used to depend on the character stream classes and byte stream classes.From Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) token by token using regular expressions.By default, whitespace is considered as the delimiter (to break the data into tokens).To read various datatypes from the source using the nextXXX() methods provided by this class namely, nextInt(), nextShort(), nextFloat(), nextLong(), nextBigDecimal(), nextBigInteger(), nextLong(), nextShort(), nextDouble(), nextByte(), nextFloat(), next().Example − Reading data from ... Read More

How can we read from standard input in Java?

Vivek Verma
Updated on 29-May-2025 19:05:27

38K+ Views

The standard input (stdin) can be represented by System.in in Java. The System.in is an instance of the InputStream class. It means that all its methods work on bytes, not Strings. To read any data from a keyboard, we can use either the Reader class or the Scanner class. Using Reader Class In Java, the Reader class is an abstract class belonging to the java.io package that is used for reading character streams. It is the superclass of all character input streams, such as "BufferedReader", "InputStreamReader", "FileReader", etc. Subclasses of Reader To use the functionality of the Reader class, use its ... Read More

What is the necessity of byte streams and character streams in Java?

Maruthi Krishna
Updated on 01-Aug-2019 14:00:08

765 Views

Java provides I/O Streams to read and write data where, a Stream represents an input source or an output destination which could be a file, i/o devise, other program etc.Based on the data they handle there are two types of streams −Byte StreamsThese handle data in bytes (8 bits) i.e., the byte stream classes read/write data of 8 bits. Using these you can store characters, videos, audios, images etc.The InputStream and OutputStream classes (abstract) are the super classes of all the input/output stream classes: classes that are used to read/write a stream of bytes. Following are the byte array stream ... Read More

How to create a new directory by using File object in Java?

Maruthi Krishna
Updated on 01-Aug-2019 13:54:30

6K+ Views

The class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.Creating a new directoryThe mkdir() method of this class creates a directory with the path represented by the current object.Therefore, to create a directory −Instantiate the File class by passing the path of the directory you need to create, as a parameter (String).Invoke the mkdir() method using the above created file object.ExampleFollowing Java example reads the path and name of the directory to be created, from the user, and creates it.import java.io.File; ... Read More

How to read data from a file using FileInputStream?

Maruthi Krishna
Updated on 01-Aug-2019 13:48:45

4K+ Views

The FileInputStream class reads the data from a specific file (byte by byte). It is usually used to read the contents of a file with raw bytes, such as images.To read the contents of a file using this class −First of all, you need to instantiate this class by passing a String variable or a File object, representing the path of the file to be read.FileInputStream inputStream = new FileInputStream("file_path"); or, File file = new File("file_path"); FileInputStream inputStream = new FileInputStream(file);Then read the contents of the specified file using either of the variants of read() method −int read() − This ... Read More

What is the use of FileInputStream and FileOutputStream in classes in Java?

Maruthi Krishna
Updated on 01-Aug-2019 13:42:15

17K+ Views

Java provides I/O Streams to read and write data where, a Stream represents an input source or an output destination which could be a file, i/o devise, other program etc.There are two types of streams available −InputStream − This is used to read (sequential) data from a source.OutputStream − This is used to write data to a destination.FileInputStreamThis class reads the data from a specific file (byte by byte). It is usually used to read the contents of a file with raw bytes, such as images.To read the contents of a file using this class −First of all, you need ... Read More

How to convert InputStream object to a String in Java?

Maruthi Krishna
Updated on 01-Aug-2019 13:32:40

11K+ Views

Java provides I/O Streams to read and write data where, a Stream represents an input source or an output destination which could be a file, i/o devise, other program etc.There are two types of streams available −InputStream − This is used to read (sequential) data from a source.OutputStream − This is used to write data to a destination.FileInputStreamThis class reads the data from a specific file (byte by byte). It is usually used to read the contents of a file with raw bytes, such as images.Converting an InputStream object to StringYou can convert an InputStream Object int to a String ... Read More

How to access 'this' keyword inside an arrow function in JavaScript?

vineeth.mariserla
Updated on 01-Aug-2019 14:12:25

568 Views

"this" keyword in an arrow functionThe JavaScript 'this' keyword refers to the object it belongs to. In an arrow function, 'this' belongs to a global object. Inside a simple function, there might be chances that 'this' keyword can result in undefined but in an arrow function it results in an exact value.ExampleLive Demo    function Student(fname, grade) {       this.fname = fname;       this.grade = grade;       this.details = function() {          return () => {             document.write(`Hi, I'm ${this.fname} from ${this.grade} grade`);          };       }    } let info = new Student('picaso', 'seventh'); let printInfo = info.details(); printInfo(); OutputHi, I'm picaso from seventh grade

Difference between the byte stream and character stream classes in Java?

Maruthi Krishna
Updated on 02-Jul-2020 10:37:19

5K+ Views

Java provides I/O Streams to read and write data where, a Stream represents an input source or an output destination which could be a file, i/o devise, other program etc.Based on the data they handle there are two types of streams −Byte Streams − These handle data in bytes (8 bits) i.e., the byte stream classes read/write data of 8 bits. Using these you can store characters, videos, audios, images etc.Character Streams − These handle data in 16 bit Unicode. Using these you can read and write text data only.The Reader and Writer classes (abstract) are the super classes of ... Read More

What is a Stream and what are the types of Streams and classes in Java?

Maruthi Krishna
Updated on 01-Aug-2019 13:22:47

29K+ Views

Java provides I/O Streams to read and write data where, a Stream represents an input source or an output destination which could be a file, i/o devise, other program etc.In general, a Stream will be an input stream or, an output stream.InputStream − This is used to read data from a source.OutputStream − This is used to write data to a destination.Based on the data they handle there are two types of streams −Byte Streams − These handle data in bytes (8 bits) i.e., the byte stream classes read/write data of 8 bits. Using these you can store characters, videos, ... Read More

Advertisements