wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compiler vs. Runtime Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compiler vs. Runtime Error" Watch "Compiler vs. Runtime Error" New topic
Author

Compiler vs. Runtime Error

juliane gross
Ranch Hand

Joined: May 30, 2002
Posts: 161
Is there anything like a "Rule of Thumb" or
does anyone know of an easier way to learn
which errors would result in a Runtime Error,
and which would result in a Compiler Error?
For example, using the dot-operator on null
results in a Runtime Error; why wouldn't want
the compiler take care of it?
Thanx for answering,

Juliane
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The compiler will report any errors it can find, but it's not all that smart. It never knows the value that any variable contains, so it will always allow you to dereference a variable (as long as the compiler is sure the variable has been initialized to some value.)
Similarly, it can check whether a type cast is plausible, but it can't check whether the cast will definitely succeed or not, so casts fail at runtime unless the compiler can prove that two types definitely can't be interconverted.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiler vs. Runtime Error
 
Similar Threads
Chap 3 ,page 237 K&B SCJP5 book -Question on Wrappers from Exam Watch Section
Runtime error vs Compiler error
boolean equals()
Getting error in setupConnection()
Trying to run class in JFrame