Friday, December 23, 2016

Error Vs Exception in JAVA

Q. what is the difference between Error and Exception?

Ans.
1. Error is a problem in JAVA application, it may affect compilation and execution of the JAVA program.

There are two types of Errors in JAVA Application...
1. compile time Error
2. Runtime Errors

1. Compile Time Errors:
----------------------------------
Compile time error is a problem identified at compile time.

In general , there are three basic errors in all the programming language
a. Lexical Error: Mistake in keywords
EX: int i = 10; ------> valid
        nit i = 10; ------> invalid

b. Syntax Error: Grammatical Mistakes
EX: int i = 10; ---> valid
   int i = 10 ------> invalid
   i 10 int; --------> invalid

c. semantic error: operation with incompatible types
Ex: int i = 10; ---> valid
   boolean b = true;
   float = i + b;

2. Run Time Error:
These are the problems occurred at run time, for which, we are unable to provide programmatic           solution.
EX: InSufficientMainMemoryErrors
NoClassDefFoundError
NoSuchMethodError
JVMInternalProblemError

2. Exception:
------------------
These are problems for which, we are able to provide programmatic solutions:
EX:
1. ArithmeticException
2. NullPointerException
3. ArrayIndexOutOfBoundsException
---------------------------------------------------------------------------------------

No comments:

Post a Comment