Maruthi Krishna has Published 558 Articles

How to convert InputStream object to a String in Java?

Maruthi Krishna

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

31K+ 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

400 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

577 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

6K+ 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

Is it possible to use this keyword in static context in java?

Maruthi Krishna

Maruthi Krishna

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

1K+ Views

A static method or, block belongs to the class and these will be loaded into the memory along with the class. You can invoke static methods without creating an object. (using the class name as reference).Whereas "this" in Java acts as a reference to the current object. But static contexts(methods and ... Read More

When and where static blocks are executed in java?

Maruthi Krishna

Maruthi Krishna

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

2K+ Views

A static block is a block of code with a static keyword. In general, these are used to initialize the static members. JVM executes static blocks before the main method at the time of class loading.Example Live Demopublic class MyClass {    static{       System.out.println("Hello this is a static ... Read More

Advertisements