aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to differentiate between compile time errors and runtime errors ? 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 "How to differentiate between compile time errors and runtime errors ?" Watch "How to differentiate between compile time errors and runtime errors ?" New topic
Author

How to differentiate between compile time errors and runtime errors ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Im having tough time in understanding questions related to compile time and runtime error. Can you please shed light on this topic as how to proceed in this regard? i have two code listings shown below:

Code Listing 1 :


Code Listing 2:





the compiler gives error in Code Listing 2 as to variable j might not have been initialized. Can you please tell me what the compiler thinks when it encounters code listing 1 and 2. And also the generalized version of the problem relating to compile time error and runtime exception. ??
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Dear Gurpreet,

Welcome to JR.

Well, there is a quick pointer. In code listing 1, the compiler will always execute the initialization for i before evaluating the condition.
So it compiles fine. In case-2, initialization of j is conditionally dependent on the outer loop. The compiler is not sure whether the outer
loop will even run or not, so it in such a scenario, it suspects as its dependent on outer loop, it is not necessary that j will initialize that's
why it will give the compile time error.

HTH,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to differentiate between compile time errors and runtime errors ?