Maruthi Krishna has Published 951 Articles

Can we use readUTF() to read a string from a .txt file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:13:58

284 Views

The readUTF() method of the java.io.DataOutputStream reads data that is in modified UTF-8 encoding, into a String and returns it.ExampleThe following Java program reads a UTF-8 text from a .txt file using the readUTF() method.import java.io.DataInputStream; import java.io.EOFException; import java.io.FileInputStream; import java.io.IOException; public class UTF8Example {    public static void ... Read More

Reading UTF8 data from a file using Java

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:07:15

3K+ Views

In general, data is stored in a computer in the form of bits (1 or, 0). There are various coding schemes available specifying the set of bytes represented by each character.Unicode (UTF) − Stands for Unicode Translation Format. It is developed by The Unicode Consortium. if you want to create ... Read More

Writing UTF8 data to a file using Java

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:02:31

3K+ Views

In general, data is stored in a computer in the form of bits (1 or, 0). There are various coding schemes available specifying the set of bytes represented by each character.Unicode (UTF) − Stands for Unicode Translation Format. It is developed by The Unicode Consortium. if you want to create ... Read More

How can we check if file exists anywhere on the system in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:58:33

254 Views

You can verify whether a particular file exists in the system in two ways using the File class and using the Files class.Using The File classThe 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 ... Read More

How to read integers from a file using BufferedReader in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:54:20

16K+ Views

The BufferedReader class of Java is used to read the stream of characters from the specified source (character-input stream). The constructor of this class accepts an InputStream object as a parameter.This class provides a method known as readLine() which reads and returns the next line from the source and returns ... Read More

Why subclass doesn't inherit the private instance variables of superclass in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:46:33

5K+ Views

When you declare the instance variables of a class private, you cannot access them in another class if you try to do so a compile-time error will be generated.But, if you inherit a class that has private fields, including all other members of the class the private variables are also ... Read More

What is the difference between getter/setter methods and constructor in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:37:17

10K+ Views

ConstructorsA constructor in Java is similar to method and it is invoked at the time creating an object of the class, it is generally used to initialize the instance variables of a class. The constructors have the same name as their class and, have no return type.If you do not ... Read More

Is it possible to override a Java method of one class in same?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:32:26

2K+ Views

When we have two classes where one extends another and if, these two classes have the same method including parameters and return type (say, sample) the method in the subclass overrides the method in the superclass.i.e. Since it is an inheritance. If we instantiate the subclass a copy of superclass’s ... Read More

What happens when a subclass object is assigned to a superclass object in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:25:12

5K+ Views

Converting one data type to others in Java is known as casting.If you convert a higher datatype to lower datatype, it is known as narrowing (assigning higher data type value to the lower data type variable).char ch = (char)5;If you convert a lower data type to a higher data type, ... Read More

When overriding clone method, why do we need to declare it as public in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:19:07

1K+ Views

The clone() method belongs to the class named Object of the java.lang package, it accepts an object as a parameter creates and returns a copy of it.In order to use this method, you need to make sure that your class implements the Cloneable (marker) interface.Example Live Demopublic class CloneExample implements Cloneable ... Read More

Advertisements