Page 1 of 1
How to determine whether something is a compilation error or an exception at run time
Posted: Sun Dec 16, 2018 6:33 am
by flex567
How do you differentiate if something is compilation error or a run time execption?
Re: About Question enthuware.ocajp.i.v7.2.1381 :
Posted: Sun Dec 16, 2018 7:16 am
by admin
flex567 wrote: ↑Sun Dec 16, 2018 6:33 am
How do you differentiate if something is compilation error or a run time execption?
I am not sure if there is a simple answer to this question. There are so many rules that a compiler checks while compiling code ranging from class structure, syntax, declarations, definitions, operations, and what not. If one were to pick a single most important thing then one could say that compiler checks the syntactical validity of the code but that would leave out a lot of semantic checks that the compiler performs. At run time, the JVM checks only whether the promises made by the code are being kept.
Understanding what happens at compile time and what happens at run time is a big requirement of this certification and I am afraid you will need to go through a whole book to fully understand this. I am not saying that it is difficult to understand but that there are too many rules to be listed here. If I try to list them here, this post will turn into a book

Re: How to determine whether something is a compilation error or an exception at run time
Posted: Sun Dec 16, 2018 7:23 am
by admin
Re: How to determine whether something is a compilation error or an exception at run time
Posted: Sun Dec 16, 2018 11:33 am
by flex567
Is this explained in the book?
How much is that important for the exam?
Re: How to determine whether something is a compilation error or an exception at run time
Posted: Sun Dec 16, 2018 12:28 pm
by admin
I think you misunderstood what I meant by book. I mean that you need to read a whole book to understand all the rules regarding compile time vs run time. This is not something that can be explained in a single section or even a single chapter.
It is very important for the exam.
Re: How to determine whether something is a compilation error or an exception at run time
Posted: Sun Dec 16, 2018 12:31 pm
by flex567
How can something that is very important for the exam not be explained in a section or a chapter in Desjmukh's book? I don't think any book that is recommended for preparation for the exam covers this.
At least short explanation or summary should be included.
Re: How to determine whether something is a compilation error or an exception at run time
Posted: Sun Dec 16, 2018 12:46 pm
by admin
I'm sorry but there is no magic bullet for this. It is like saying if Java programming is very important for the exam then why it isn't explained in a section!
Once you know all the rules of the language you will know what will cause error at compile time and what will cause an exception at run time. For that, you need to read the whole book. I don't think any book can explain this in a section.
May be you can ask opinion from other experts on StackOverflow or JavaRanch.
Re: How to determine whether something is a compilation error or an exception at run time
Posted: Sun Dec 16, 2018 1:14 pm
by admin
If compiler is able to determine that something is wrong with the code then that is a compilation error e.g. bad syntax, bad assignment, impossible casts, improper exception declarations and so on. There is a long list.
All the rest is exception at run time.