Maruthi Krishna has Published 952 Articles

How to convert InputStream object to a String in Java?

Maruthi Krishna

Maruthi Krishna

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

10K+ 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 ... Read More

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

Maruthi Krishna

Maruthi Krishna

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

21K+ 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 ... Read More

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

Maruthi Krishna

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 ... Read More

Why does Java strictly specify the range and behavior of its primitive types?

Maruthi Krishna

Maruthi Krishna

Updated on 01-Aug-2019 12:31:17

182 Views

Java provides various datatypes to store various data values. It provides 7 primitive datatypes (stores single values) namely, boolean, byte, char, short, int, long, float, double.Java strictly specifies range and behaviors of all the primitive datatypes. Making the users choose the required datatypes based on the application thus reducing the ... Read More

List out the default values of numeric and non-numeric primitive data types in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 01-Aug-2019 12:21:52

356 Views

When you create instance variables in Java you need to initialize them, else the compiler will initialize on your behalf with default values which are −byte: 0short: 0int: 0long: 0float: 0.0double: 0.0boolean: falsestring: nullExampleIn the following Java program prints the default values of the numeric and non-numeric primitive variables in ... Read More

How to call the constructor of a superclass from a constructor in java?

Maruthi Krishna

Maruthi Krishna

Updated on 01-Aug-2019 12:09:16

5K+ Views

Whenever you inherit/extend a class, a copy of superclass’s members is created in the subclass object and thus, using the subclass object you can access the members of both classes.ExampleIn the following example we have a class named SuperClass with a method with name demo(). We are extending this class ... Read More

How to ensure that child class overrides a super class method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 01-Aug-2019 11:55:07

536 Views

A method which does not have body is known as abstract method. It contains only method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation (body) to it. If a ... Read More

Is it mandatory to override the default methods of an interface in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 01-Aug-2019 11:12:37

2K+ Views

The default methods are introduced in an interface since Java8. Unlike other abstract methods these are the methods can have a default implementation. If you have default method in an interface, it is not mandatory to override (provide body) it in the classes that are already implementing this interface.In short, ... Read More

What are the uses of this keyword in java?

Maruthi Krishna

Maruthi Krishna

Updated on 30-Jul-2019 22:30:26

720 Views

The "this" keyword in Java is a reference to the object of the current class. Using it, you can refer a field, method or, constructor of a class.Referring to a field using "this" keywordAs discussed you can refer an instance filed/variable of a class from an instance method or, a ... Read More

Can we call methods using this keyword in java?

Maruthi Krishna

Maruthi Krishna

Updated on 30-Jul-2019 22:30:26

2K+ Views

The "this" keyword in Java is used as a reference to the current object, within an instance method or a constructor. Yes, you can call methods using it. But, you should call them only from instance methods (non-static).ExampleIn the following example, the Student class has a private variable name, with ... Read More

Advertisements