Found 7442 Articles for Java

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

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

What is the use of in flush() and close() methods of BufferedWriter class in Java?

Maruthi Krishna
Updated on 01-Aug-2019 13:17:24

2K+ Views

The BufferedWriter class of Java is used to write stream of characters to the specified destination (character-output stream). It initially stores all the characters in a buffer and pushes the contents of the buffer to the destination, making the writing of characters, arrays and Strings efficient.You can specify the required size of the buffer at the time of instantiating this class.The flush() methodWhile you are trying to write data to a Stream using the BufferedWriter object, after invoking the write() method the data will be buffered initially, nothing will be printed.The flush() method is used to push the contents of ... Read More

Guidelines to be followed while implementing equals method in Java?

Maruthi Krishna
Updated on 02-Jul-2020 10:25:05

218 Views

To compare two objects, the Object class provides a method with name equals(), this method accepts an object and compares it with the current object.If the references of these two objects are equal, then it returns true else this method returns false.But this method returns true only if both references points to the same object. In fact, it should return true id the contents of the both objects are equal.Exampleclass Employee {    private String name;    private int age;    Employee(String name, int age){       this.name = name;       this.age = age;    } } ... Read More

How can we convert a hexadecimal value to a byte in Java?

Vivek Verma
Updated on 29-May-2025 19:03:15

305 Views

This article will discuss how to convert a hexadecimal value to a byte value in Java. Before converting it to a byte, let's first understand what hexadecimal and byte values are. Hexadecimal Value In Java, a hexadecimal number is a base-16 number represented using the digits 0-9 and the letters A-F or a-f, where A-F represent the decimal values 10-15 respectively. The hexadecimal values are: 0x1A 0xFF 0x0A Byte Value In Java, a byte is a data type that can store whole numbers between the ... Read More

How to convert String to StringBuilder and vice versa Java?

Maruthi Krishna
Updated on 02-Jul-2020 10:32:03

22K+ Views

The String type is a class in Java, it is used to represent a set of characters. Strings in Java are immutable, you cannot change the value of a String once created.Since a String is immutable, if you try to reassign the value of a String. The reference of it will be pointed to the new String object leaving an unused String in the memory.Java provides StringBuffer class as a replacement of Strings in places where there is a necessity to make a lot of modifications to Strings of characters.You can modify/manipulate the contents of a StringBuffer over and over again ... Read More

Why String class is popular key in a HashMap in Java?

Maruthi Krishna
Updated on 02-Jul-2020 10:32:54

3K+ Views

A map is a collection in Java which stores key value pairs. The keys of this must not be null and each key should point to only one value. It is represented by the Map interface of java.util package. There are various classes which provides implementation to this interface.The HashMap is a class which implements the Map interface. It is based on the Hash table. It allows null values and null keys.In short, you can store key value pairs in the HashMap object. Once you do so you can retrieve the values of the respective keys but, the values we ... Read More

Is it possible to synchronize the string type in Java?

Maruthi Krishna
Updated on 02-Jul-2020 10:33:35

2K+ Views

A thread is a piece of code (under execution) in a program, which executes a sub task of the process independently. independent process.In other words, a thread is a light weight process which executes a piece of code independently.Thread synchronizationIf a process has multiple threads running independently at the same time (multi-threading) and if all of them trying to access a same resource an issue occurs.To resolve this, Java provides synchronized blocks/ synchronized methods. If you define a resource (variable/object/array) inside a synchronized block or a synchronized method, if one thread is using/accessing it, other threads are not allowed to ... Read More

Advertisements