Saturday, January 9, 2021

Java.io.DataOutputStream in Java

Oracle Java Tutorial and Material, Oracle Java Learning, Oracle Java Exam Prep

A data output stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in.

Constructor and Description :

◉ DataOutputStream (OutputStream out) : Creates a new data output stream to write data to the specified underlying output stream.

Important Methods:

◉ void flush() : Flushes this data output stream.

Syntax :public void flush()

           throws IOException

Overrides:

flush in class FilterOutputStream

Throws:

IOException

◉ int size () : Returns the current value of the counter written, the number of bytes written to this data output stream so far.

Syntax :public final int size()

Returns:

the value of the written field.

◉ void write (byte[] b, int off, int len) : Writes len bytes from the specified byte array starting at offset off to the underlying output stream.

Syntax :public void write(byte[] b,

         int off,

         int len)

           throws IOException

Overrides:

write in class FilterOutputStream

Parameters:

b - the data.

off - the start offset in the data.

len - the number of bytes to write.

Throws:

IOException 

◉ void write (int b) : Writes the specified byte (the low eight bits of the argument b) to the underlying output stream.

Syntax :public void write(int b)

           throws IOException

Overrides:

write in class FilterOutputStream

Parameters:

b - the byte to be written.

Throws:

IOException

◉ void writeBoolean (boolean v) : Writes a boolean to the underlying output stream as a 1-byte value.

Syntax :public final void writeBoolean(boolean v)

                        throws IOException

Parameters:

v - a boolean value to be written.

Throws:

IOException

◉ void writeByte (int v) : Writes out a byte to the underlying output stream as a 1-byte value.

Syntax :public final void writeByte(int v)

                     throws IOException

Parameters:

v - a byte value to be written.

Throws:

IOException

◉ void writeChar (int v) : Writes a char to the underlying output stream as a 2-byte value, high byte first.

Syntax :public final void writeChar(int v)

                     throws IOException

Parameters:

v - a char value to be written.

Throws:

IOException

◉ void writeDouble (double v) : Converts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the underlying output stream as an 8-byte quantity, high byte first.

Syntax :public final void writeDouble(double v)

                       throws IOException

Parameters:

v - a double value to be written.

Throws:

IOException

◉ void writeFloat (float v): Converts the float argument to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream as a 4-byte quantity, MSB first.

Syntax :public final void writeFloat(float v)

                      throws IOException

Parameters:

v - a float value to be written.

Throws:

IOException

◉ void writeInt (int v) : Writes an int to the underlying output stream as four bytes, high byte first.

Syntax :public final void writeInt(int v)

                    throws IOException

Parameters:

v - an int to be written.

Throws:

IOException

◉ void writeLong (long v) : Writes a long to the underlying output stream as eight bytes, high byte first.

Syntax :public final void writeLong(long v)

                     throws IOException

Parameters:

v - a long to be written.

Throws:

IOException

◉ void writeShort (int v) : Writes a short to the underlying output stream as two bytes, high byte first.

Syntax :public final void writeShort(int v)

                      throws IOException

Parameters:

v - a short to be written.

Throws:

IOException 

◉ void writeUTF (String str) : Writes a string to the underlying output stream using modified UTF-8 encoding in a machine-independent manner.

Syntax :public final void writeUTF(String str)

                    throws IOException

Parameters:

str - a string to be written.

Throws:

IOException

Implementations of some of the important methods

Program:

//Java program to demonstrate DataOutputStream 

// This program uses try-with-resources. It requires JDK 7 or later. 

import java.io.*; 

class DataOutputStreamDemo 

{ 

public static void main(String args[]) throws IOException 

{ 

//writing the data using DataOutputStream 

try ( DataOutputStream dout = 

new DataOutputStream(new FileOutputStream("file.dat")) ) 

{ 

dout.writeDouble(1.1); 

dout.writeInt(55); 

dout.writeBoolean(true); 

dout.writeChar('4'); 

} 

catch(FileNotFoundException ex) 

{ 

System.out.println("Cannot Open the Output File"); 

return; 

} 

// reading the data back using DataInputStream 

try ( DataInputStream din = 

new DataInputStream(new FileInputStream("file.dat")) ) 

{ 

double a = din.readDouble(); 

int b = din.readInt(); 

boolean c = din.readBoolean(); 

char d=din.readChar(); 

System.out.println("Values: " + a + " " + b + " " + c+" " + d); 

} 

catch(FileNotFoundException e) 

{ 

System.out.println("Cannot Open the Input File"); 

return; 

} 

} 

} 

Oracle Java Tutorial and Material, Oracle Java Learning, Oracle Java Exam Prep
Output:

Values: 1.1 55 true 4

Important Points:

◉ DataOutputStream and DataInputStream are often used together.

◉ When a DataOutputStream is closed (by calling close( )), the underlying stream specified by out is also closed automatically.

◉ There is no longer any explicit close() method call. The try-with-resources construct takes care of that.

Friday, January 8, 2021

How to Iterate LinkedList in Java?

Oracle Java Tutorial and Material, Oracle Java Learning, Core Java, Java Guides

LinkedList in java is basically a part of the collection framework present in java.util package. It is the implementation of the LinkedList data structure that stores elements in a non-contiguous manner inside the memory.

Five ways to iterate a LinkedList are:

1. Using for loop

2. Using while loop

3. Using enhanced for loop

4. Using Iterator

5. Using forEach() method

Method 1: Using For Loop

// Java program for iterating the LinkedList 

// using For loop 

import java.util.LinkedList; 

public class GFG { 

public static void main(String[] args) 

{ 

// Creating a LinkedList of Integer type 

LinkedList<Integer> linkedList = new LinkedList<>(); 

// Inserting some Integer values to our LinkedList 

linkedList.add(40); 

linkedList.add(44); 

linkedList.add(80); 

linkedList.add(9); 

// LinkedList after insertions: [40, 44, 80, 9] 

// Calling the function to iterate our LinkedList 

iterateUsingForLoop(linkedList); 

} 

// Function to iterate the LinkedList using a simple for 

// loop 

public static void

iterateUsingForLoop(LinkedList<Integer> linkedList) 

{ 

System.out.print( 

"Iterating the LinkedList using a simple for loop : "); 

for (int i = 0; i < linkedList.size(); i++) { 

System.out.print(linkedList.get(i) + " "); 

} 

} 

}

Output

Iterating the LinkedList using a simple for loop : 40 44 80 9

Method 2: Using while Loop


We can iterate our LinkedList using a while loop in a very similar way as we did using a for loop.

// Java program for iterating the LinkedList 
// using while loop 

import java.util.LinkedList; 

public class GFG { 
public static void main(String[] args) { 

// Creating a LinkedList of Character type 
LinkedList<Character> vowels = new LinkedList<>(); 

// Inserting some Character values to our LinkedList 
vowels.add('a'); 
vowels.add('e'); 
vowels.add('i'); 
vowels.add('o'); 
vowels.add('u'); 

// LinkedList after insertions: ['a', 'e', 'i', 'o', 'u'] 

// calling the function to iterate our LinkedList 
iterateUsingWhileLoop(vowels); 
} 

// Function to iterate our LinkedList using while loop 
public static void iterateUsingWhileLoop(LinkedList<Character> vowels){ 

System.out.print("Iterating the LinkedList using while loop : "); 

int i=0; 
while(i<vowels.size()){ 
System.out.print(vowels.get(i) + " "); 
i++; 
} 

} 
} 

Output

Iterating the LinkedList using while loop : a e i o u

Method 3: Using enhanced for loop


Using enhanced for loop we can sequentially iterate a LinkedList. The execution of the enhanced for loop ends after we visit all the elements. Let us see an example of iterating the LinkedList using the enhanced for loop.

// Java program for iterating the LinkedList 
// using Enhanced For loop 

import java.util.LinkedList; 

public class GFG { 
public static void main(String[] args) 
{ 

// Creating a LinkedList of String type 
LinkedList<String> linkedList = new LinkedList<>(); 

// Inserting some String values to our LinkedList 
linkedList.add("LPI"); 
linkedList.add("for"); 
linkedList.add("LPI"); 

// LinkedList after insertions: ["LPI", "for", 
// "LPI] 

// Calling the function to iterate our LinkedList 
iterateUsingEnhancedForLoop(linkedList); 
} 

// Function to display LinkedList using Enhanced for 
// loop 
public static void iterateUsingEnhancedForLoop(LinkedList<String> linkedList) 
{ 

System.out.print( 
"Iterating the LinkedList using enhanced for loop : "); 

for (String listElement : linkedList) { 
System.out.print(listElement + " "); 
} 
} 
}

Output

Iterating the LinkedList using enhanced for loop : LPI Central

Method 4: Using Iterator


◉ To iterate the LinkedList using the iterator we first create an iterator to the current list and keep on printing the next element using the next() method until the next element exists inside the LinkedList.

◉ We check if the LinkedList contains the next element using the hasNext() method.

// Java program for iterating the LinkedList 
// using Iterator 

import java.util.Iterator; 

// Importing LinkedList class from 
// java.util package 
import java.util.LinkedList; 

public class GFG { 
public static void main(String[] args) { 

// Creating a LinkedList of Integer Type 
LinkedList<Integer> linkedList = new LinkedList<>(); 

// Inserting some Integer values to our LinkedList 
linkedList.add(5); 
linkedList.add(100); 
linkedList.add(41); 
linkedList.add(40); 
linkedList.add(7); 

// LinkedList after insertions : [5, 100, 41, 40, 7] 

// Calling the function to iterate our LinkedList 
iterateUsingIterator(linkedList); 
} 

// Function to iterate the Linked List using Iterator 
public static void iterateUsingIterator(LinkedList<Integer> linkedList){ 

System.out.print("Iterating the LinkedList using Iterator : "); 

// Creating an Iterator to our current LinkedList 
Iterator it = linkedList.iterator(); 

// Inside the while loop we check if the next element 
// exists or not if the next element exists then we print 
// the next element and move to it otherwise we come out 
// of the loop 
// hasNext() method return boolean value 
// It returns true when the next element 
// exists otherwise returns false 
while(it.hasNext()){ 

// next() return the next element in the iteration 
System.out.print(it.next() + " "); 
} 

} 
} 

Output

Iterating the LinkedList using Iterator : 5 100 41 40 7

Method 5: Using forEach() method


Oracle Java Tutorial and Material, Oracle Java Learning, Core Java, Java Guides
◉ forEach() method was introduced in Java8. 
◉ It performs the specified task for each element of the Iterable until all elements have been processed or the action throws an exception. 

Syntax: 

public void forEach(Consumer<? super E> action)

// Java program for iterating the LinkedList 
// using For Each loop 

import java.util.LinkedList; 

public class GFG { 
public static void main(String[] args) 
{ 

// Creating a LinkedList of Integer Type 
LinkedList<Integer> linkedList = new LinkedList<>(); 

// Inserting some Integer values to our LinkedList 
linkedList.add(1); 
linkedList.add(2); 
linkedList.add(3); 
linkedList.add(4); 
linkedList.add(5); 

// LinkedList after insertions: [1, 2, 3, 4, 5] 

// Calling the function to iterate our LinkedList 
iterateUsingForEach(linkedList); 
} 

public static void
iterateUsingForEach(LinkedList<Integer> linkedList) 
{ 

System.out.print( 
"Iterating the LinkedList using for each function : "); 

// Calling the forEach function to iterate through 
// all the elements inside the Linked List 
linkedList.forEach( 
(element) -> System.out.print(element + " ")); 
} 
}

Output

Iterating the LinkedList using for each function : 1 2 3 4 5

Thursday, January 7, 2021

Java.util.TreeMap.descendingMap() and descendingKeyset() in Java

Oracle Java Tutorial and Material, Oracle Java Learning, Oracle Java Exam Prep

There are two variants of descending() in Java.util.TreeMap, both are discussed in this article.

1. descendingKeySet(): It returns a reverse order Navigable Set view of the keys contained in the map.

Syntax : 

public NavigableSet descendingKeySet()

Parameters:

NA

Return Value:

It returns a reverse order navigable set view of the keys in this map.

Exception:

NA

// Java code to demonstrate the working 

// descendingKeySet() 

import java.io.*; 

import java.util.*; 

public class descendingKeySet1 { 

public static void main(String[] args) 

{ 

// Declaring the tree map of Integer and String 

TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); 


// assigning the values in the tree map 

// using put() 

treemap.put(2, "two"); 

treemap.put(0, "zero"); 

treemap.put(3, "three"); 

treemap.put(6, "six"); 

treemap.put(9, "nine"); 

treemap.put(7, "seven"); 


// putting values in navigable set 

// use of descendingKeySet 

NavigableSet set1 = treemap.descendingKeySet(); 


System.out.println("Navigable set values are: " + set1); 

} 

} 

Output:

Navigable set values are: [9, 7, 6, 3, 2, 0]

2. descendingMap() : It returns a reverse order view of the mappings contained in the map.
Syntax : 

public NavigableMap descendingMap()
Parameters:
NA
Return Value
It returns a reverse order view of the map.
Exception:
NA

// Java code to demonstrate the working 
// of descendingMap() 
import java.io.*; 
import java.util.*; 
public class descendingMap { 
public static void main(String[] args) 
{ 

// Declaring the tree map of Integer and String 
TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); 

// assigning the values in the tree map 
// using put() 
treemap.put(2, "two"); 
treemap.put(0, "zero"); 
treemap.put(3, "three"); 
treemap.put(6, "six"); 
treemap.put(9, "nine"); 
treemap.put(7, "seven"); 

// putting values in navigable map 
// use of descendingMap() 
NavigableMap map1 = treemap.descendingMap(); 

System.out.println("Navigable map values are: " + map1); 
} 
} 

Output:

Navigable map values are: {9=nine, 7=seven, 6=six, 3=three, 2=two, 0=zero}

Oracle Java Tutorial and Material, Oracle Java Learning, Oracle Java Exam Prep
Practical Application :
There are many applications possible of descending functions explained in this article. Some among them are priority scheduling, or designing a ranking system. Latter one is demonstrated in the code below.

// Java code to demonstrate the application 
// of descendingMap() and descendingKetSet() 
import java.io.*; 
import java.util.*; 
public class descendingAppli { 
public static void main(String[] args) 
{ 

// Declaring the tree map of Integer and String 
// to store participants info of scores with name 
TreeMap<Integer, String> participants = new TreeMap<Integer, String>(); 

// assigning score of participants 
// using put() 
participants.put(30, "Ashty"); 
participants.put(45, "Shavi"); 
participants.put(16, "Vaish"); 
participants.put(15, "Kil"); 
participants.put(11, "Manju"); 

// putting ranks in NavigableMap 
// use of descendingMap() to assign 1st to 
// maximum values and so on 
NavigableMap<Integer, String> Ranks = participants.descendingMap(); 

System.out.println("The ranks according to scores are : "); 

// Printing values rankwise 
int count = 0; 
for (NavigableMap.Entry<Integer, String> entry : Ranks.entrySet()) { 
count++; 
String str = Integer.toString(count); 
System.out.println("Rank " + str + ": " + entry.getValue()); 
} 
} 
} 

Output:

The ranks according to scores are : 
Rank 1: Shavi
Rank 2: Ashty
Rank 3: Vaish
Rank 4: Kil
Rank 5: Manju

Wednesday, January 6, 2021

Advantages and Disadvantages of Java

Oracle Java Tutorial and Material, Oracle Java Exam Prep, Oracle Java Certifications, Java Career

Java has been reliably holding the absolute best situation of the TIOBE record among any remaining programming dialects. In spite of the fact that numerous new dialects are found, the VIP of Java never goes down. Java has been administering over any remaining dialects for very 20 years the majority of experts can’t deny the unquestionable reality that Java is one of the principal historic and incredible lingos ever constructed and is that the superior all-around used programming language in various domains.

Java Language :    

◉ Java could likewise be a universally useful, significant-level programming language at first intended for handheld gadgets and set-top boxes.

◉ In 1995 java make applications on the internet. Today, Java is ordinarily utilized for making web and portable applications.

◉ Java has been referenced together among the first – loved and in this way the most utilized programming dialects within recent memory.

◉ This language has been over alive for very 20 years. A few subject matter experts and experts accept that Java is one of the premier viable programming dialects that was ever made.

◉ It is the premier generally utilized programming language that is known to man and is assumed for use likewise on the grounds that the circulated climate of the on the web.

Applications :

Java could likewise be a solid broadly useful programming language. it’s utilized to create work area and portable applications, enormous preparation, implanted frameworks, etc.

It is utilized for the following application given below as follows.

◉ Portable applications (uncommonly Android applications).

◉ Work area application.

◉ Web applications.

◉ Web workers and application workers.

◉ Games.

◉ Information base association.

◉ What’s more, a whole lot more!

Oracle Java Tutorial and Material, Oracle Java Exam Prep, Oracle Java Certifications, Java Career


Advantages of JAVA :

◉ Straightforward Java –

It is anything but difficult to program, compose, gather, investigate, and learn than elective programming dialects. Java might be a more modest sum convoluted than C++; therefore, Java utilizes programmed memory portion and trash assortment.

◉ Item Oriented –

It grants you to make standard projects and reusable code.

◉ Stage Independent Java code –

It runs on any machine that needn’t bother with any unique programming to be introduced, however, the JVM should be available on the machine.

◉ Java is a disseminated language –

Java is a dispersed language as it gives an instrument for dividing information and projects between numerous PCs that improve the presentation and proficiency of the framework. The RMI(Remote Method Invocation) is something that bolsters the dispersed handling in Java.

◉ Secure Java –

It has no unequivocal pointer. Besides this, it is a security administrator that characterizes the entrance of classes.

◉ Memory distribution –

In Java, memory is part into two sections one is stored and another is stack. At whatever point we pronounce a variable JVM gives memory from one or the other stack or pile space. It assists with remaining the information and reestablish it without any problem.

◉ Multithreaded –

It is the potential for a program to perform numerous assignments simultaneously. at long last time showed up to become familiar with the ideas of Multithreading in Java.

◉ Java gives Automatic Garbage Collection –

There is programmed memory for the executives in Java that is overseen by the Java Virtual Machine(JVM). At whatever point the articles are not utilized by programs any longer and they don’t allude to anything.

Disadvantages of JAVA :

◉ Execution Java language –

It is a more slow language when contrasted with different dialects as it is a memory burning-through language.

◉ Look and Feel –

The default look of GUI applications written in Java utilizing the Swing toolbox is very not quite the same as local applications.

◉ Memory Management –

In Java, Memory is overseen through trash pickup, at whatever point the refuse gatherer runs, it influences the exhibition of the apparatus. This is frequently in light of the fact that all different strings inside the require to be halted to allow the junk authority string to figure.

◉ Java requires huge memory space –

Java requires a critical or significant measure of memory space when contrasted with different dialects like C and C++. During the execution of trash assortment, the memory productivity and the exhibition of the framework might be unfavorably influenced.

◉ Verbose and Complex codes –

Java codes are verbose, implying that there are numerous words in them and there are numerous long and complex sentences that are hard to peruse and comprehend. This can decrease the meaningfulness of the code.

Monday, January 4, 2021

What is Method Overloading in Java? An Example

Oracle Java Tutorial and Material, Oracle Java Exam Prep, Oracle Java Learning, Oracle Java Method Overloading

What is method overloading in Java?

Method overloading in Java is an object-oriented programming concept that allows a programmer to declare two methods of the same name but with different method signatures, like change in the argument list or change in the type of argument. Method overloading is a powerful Java programming technique to declare a method that does a similar job but with a different kind of input. One of the most popular examples of method overloading is the System.out.println() method whose job is to print data on the console. This method is overloaded to accept all kinds of data types in Java. 

You have the println() method which takes String, int, float, double, or even char in output. All of those methods are collectively referred to as an overloaded method in Java.

You should also know that difference between method overloading and overriding is also a popular Java interview question. In the next section, we will some important points about method overloading in Java and then a simple example of how to overload a method in Java.

Properties of method overloading in Java

1) Overloaded methods are bonded using static binding in Java. Which occurs during compile time i.e. when you compile a Java program. During the compilation process, the compiler bind method calls to the actual method.

2) Overloaded methods are fast because they are bonded during compile time and no check or binding is required during runtime.

3) Most important rule of method overloading in Java is that two overloaded methods must have a different signature. 

Here is an example of what does method signature means in Java:

◉ A number of arguments to a method are part of the method signature.

◉ Type of argument to a method is also part of the method signature

◉ Order of argument also forms part of the method signature provided they are of a different type.

◉ The return type of method is not part of the method signature in Java.

Oracle Java Tutorial and Material, Oracle Java Exam Prep, Oracle Java Learning, Oracle Java Method Overloading

Method Overloading Example in Java


Here is a list of method and there a corresponding overloaded method with the reason that How they are overloaded :

Original method :

public void  show(String message){
      System.out.println(message);
}

Overloaded method: number of argument is different

public void  show(String message, boolean show){
      System.out.println(message);
}

Overloaded method: type of argument is different

public void  show(Integer message){
      System.out.println(message);
}

Not an Overloaded method: the only return type is different

public boolean show(String message){
      System.out.println(message);
      return false;
}

Saturday, January 2, 2021

How to Take Input From User in Java?

Oracle Java Tutorial and Material, Oracle Java Prep, Oracle Java Guides, Oracle Java Exam Prep

Java brings various Streams with its I/O package that helps the user to perform all the input-output operations. These streams support all the types of objects, data-types, characters, files, etc to fully execute the I/O operations. There are two ways by which we can take input from the user or from a file

◉ BufferedReader Class

◉ Scanner Class

1. BufferedReader

It is a simple class that is used to read a sequence of characters. It has a simple function that reads a character another read which reads, an array of characters, and a readLine() function which reads a line.

InputStreamReader() is a function that converts the input stream of bytes into a stream of character so that it can be read as BufferedReader expects a stream of character.

BuffferedReader can throw checked Exceptions

// Java Program For BufferedReader Class 

import.java.io.*; 

public class BufferedReader 

{ 

// Main Method 

public static void main(String [] args) 

{ 

// Creating BuferedReader Object 

// InputStreamReader converts bytes to 

// stream of character 

BufferedReader BufferedReader_Name = new

BufferedReader(new InputStreamReader(System.in)); 

// Asking for input from user 

System.out.println("Enter String : "); 

System.out.println("Enter Integer : "); 

// String reading internally 

String String_name = BufferedReader_Name.readLine(); 

// Integer reading internally 

int Integer_value = 

Integer.parseInt(BufferedReader_name.readLine()); 

// Printing String 

System.out.println("Entered String : "+ String_name); 

//Printing Integer  

System.out.println("Entered Integer : "+ Integer_value); 

} 

}

Output : 

Entered String: Oraclejavacertified
Entered Integer: 123

2. Scanner


It is an advanced version of BufferedReader which was added in later versions of Java. The scanner can read formatted input. It has different functions for different types of data types. 

◉ The scanner is much easier to read as we don’t have to write throws as there is no exception thrown by it.
◉ It was added in later versions of Java
◉ It contains predefined functions to read an Integer, Character, and other data types as well.

Syntax for Scanner

Scanner Scanner_name = new Scanner(System.in);

Syntax for importing Scanner Class: To use the Scanner we need to import the Scanner Class

import java.util.Scanner ;  

Inbuilt Scanner functions are as follows

◉ Integer: nextInt()
◉ Float: nextFloat()
◉ String : readLine()

Hence, in the case of Integer and String in Scanner, we don’t require parsing as we did require in BufferedReader.

// Java Program to show how to take 
// input from user using Scanner Class 

import java.util.Scanner; 

class Scanner { 
public static void main( String[] args ) 
{ 
// Scanner definition 
Scanner Scanner_name= new Scanner(System.in); 
// input is a string read 
// by readLine() function 
String str= str.readLine(); 
// print string 
System.out.ptintln("Entered String : "+ str); 
// input is an Integer 
// read by nextInt() function 
int x= Scanner_name.nextInt(); 
// print integer 
System.out.ptintln("Entered Integer : "+ x); 
// input is a floatingValue 
// read by nextFloat() function 
float f = Scanner_name.nextFloat(); 
// print floating value 
System.out.ptintln("Entered FloatValue : "+ f); 
} 
}

Output :

Entered String: Oraclejavacertified
Entered Integer: 123
Entered FloatValue: 123.0

Differences Between BufferedReader and Scanner


Oracle Java Tutorial and Material, Oracle Java Prep, Oracle Java Guides, Oracle Java Exam Prep

◉ BufferedReader is a very basic way to read the input generally used to read the stream of characters. Its gives an edge over Scanner as it is faster than Scanner because Scanner does lots of post-processing for parsing the input; as seen in nextInt(), nextFloat()
◉ BufferedReader is more flexible as we can specify the size of stream input to be read. (In general, it is there that BufferdReader reads lager input than Scanner)
◉ These two factors come into play when we are reading larger input. In general, the Scanner Class serves the input.
◉ BufferdReader is preferred as it is synchronized. While dealing with multiple threads it is preferred.
◉ For decent input, easy readability. The Scanner is preferred over BufferedReader.