While solving the problem on the Internet, I observed the following java behavior, which I found a bit strange. I started by compiling a program along the following lines:
import java.io.*; class WeirdJava { public static void main (String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); HashMap<Integer, Integer> map = new HashMap<Integer,Integer>(); System.out.println("Weird Java"); } }
Please note that there are two errors in the above program:
- I did not handle exceptions that
BufferedReader can throw. - I did not import the standard
util library that contains the HashMap .
Now when I try to compile the above program, the java compiler gives an error that it cannot find the HashMap character. Note that an ad with a HashMap starts after a BufferedReader . Then I will add the following import statement to the program:
import java.util.HashMap;
When I compile the program again, this time the compiler shows an error
Unregistered IOException must be caught or thrown away
My questions:
- Why does this error not occur in a previous compilation attempt?
- The order in which the compilation error occurs does not seem natural. What are the compiler design principles that come into play during this procedure?
Bhoot source share