I just learned the Exceptions in Java, but I wonder whether "may not initialized variable" is an Error or Exception or something else?
I tried to treat it as an Exception and I write my code in notepad++ like this:
public class Demo{
public static void main(String[] args) throws Exception{
int a ;
System.out.println(a);
}
}
It didn't work, I still can't compile it using "javac Demo.java". It shows that it is not an Exception.
I have not learned "Error" before, but I search "Error" in the API, check the subclass of Error, I still don't know the answer.
Is there someone could help me? Many thanks.
~~~~~~~~~~~~~~~~~~~~~~~
Well, I know I should assign a value to a, what I want to know is the question I asked.
I learned that sentence "A local variable must be declared and assigned a value before it can be used." in Y.Daniel Liang's book , please don't use that sentence to answer me , it is not the answer to my question , thank you.
~~~~~~~~~~~~~~~~~~~~~~~
let's see another demo. It is about compile Exception.
public class Demo2{
public static void main(String[] args) throws ParseException {
//public static void main(String[] args){
String str = "1991-0101";
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date birthdayDate = sdf.parse(str);
System.out.println(birthdayDate);
}
}
The ParseException is a compileException (it extends Exception), when I didn't add the "throws ParseException", I can't compile it. After I add "throws ParseException", I CAN compile it, although it still can't run.
But when I add the "throws Exception" in the first Demo, I still can't compile it. This is the really point that makes me confused.
"It is a compilation error, not an exception", sorry I don't know how to talk to you in stackoverflow, but I think you are right, could you give me some keywords so that I can search in google or stackoverflow, or should I spend some time learn compilers?