wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP2 Question - Compiler Error Vs. Run-time Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "SCJP2 Question - Compiler Error Vs. Run-time Error" Watch "SCJP2 Question - Compiler Error Vs. Run-time Error" New topic
Author

SCJP2 Question - Compiler Error Vs. Run-time Error

Anurag Swaym
Greenhorn

Joined: Aug 12, 2002
Posts: 14
Is there a rule of thumb to distinguish between Compiler Error Vs. Run-time error.
Syntax errors obviously generate Compiler errors. Apart from Syntax errors, how can you say whether a particular group of code produces compiler or Run-time error ?
Thanks.
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
A NullPointerException would be a standard run-time error.


scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Anurag Swaym
Greenhorn

Joined: Aug 12, 2002
Posts: 14
My question was specific for Java certification exam. You know that a block of code is incorrect and is going to generate some errors.
My question is: Is there a logical way, by which you can predict that this block of code is going to generate compiler error as opposed to run-time error.
Thanks
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Wellcome to the Ranch swamyarun
Please read about our name policy and adjust your displayed name accordingly.
Experience will tell you which exceptions are runtime or not.
In the meantime consider if it is feasible to force a try clause, each time the exception could be arised in the program. For instance, a NullPointerException being a checked one would force to put all the method invocations within a try, or declare it in the method. Not feasible, thus, it is a RuntimeException.
Also remember that certain actions will always imply such risk, that the exceptions they could arise are checked by the compiler for you not forgetting about them. Forgetting about managing them, I mean. That is the case of the actions that have to access the file system and the IOException.
Now I see that my answer is not very related to your question.
I will keep it anyway for the benefit of others.
[ August 12, 2002: Message edited by: Jose Botella ]

SCJP2. Please Indent your code using UBB Code
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Got me sort of worried for a few seconds!


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
There's many errors in semantics that the compiler can discover too. As you learn the language and compile code you are going to get some the compiler errors. Some are going to stick in your head.
What I do is learn a bit from one of the well known Java books, code a bit, then I pick up the Java Language Specification and try to get a more deeper understanding of a topic. The JLS is full of "It is a compile time error to ...".
No easy way to do it, like making money.
-Barry
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Distinguising between code that will compile, or not, and the one generating exceptions is of paramount importance for the exam.
There isn't a unique rule for that. However while studying the Java language, the sooner someone is aware of the compiler error/runtime exception dichotomy, the sooner he will begin to really understand the language. That is, while examining a Java piece of code first think if the code compiles, and then if the code will execute. But do these in two different steps.
For instance, the compiler checks for the existance and accesibility of all the expressions that access members of a class. In this case the "interpreter" has nothing to do with it.
Casting is an area where distinguishing, when the compiler will complain -and when ClassCastException is thrown, requires a good understanding of what will compile, and if does so -the second step, what will run.
I am sorry no magic wand for that. Each case must be studied separately.
 
Consider Paul's rocket mass heater.
 
subject: SCJP2 Question - Compiler Error Vs. Run-time Error
 
Similar Threads
Compiler vs. Runtime Errors
runtime vs compiler error
When a compiler error vs when a runtime error
compile time vs runtime error???
Testing Active Vs Passive or Explicit vs Implicit