aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes runtime vs compiler 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 "runtime vs compiler error" Watch "runtime vs compiler error" New topic
Author

runtime vs compiler error

Maria Garcia
Ranch Hand

Joined: Jul 14, 2002
Posts: 86
hi all,
i am still confused on whether a code generates a compiler or a run time error.
when should an error be caught by the compiler ? how should i know if an error would be caught during run time ?
thanks,
maria


SCJP 1.4
Kumar Kausikasa
Ranch Hand

Joined: Jun 04, 2002
Posts: 45
Hi ,
I do not know whether i understand your question right or not. But this is the general idea:
Compiler Error is generated mainly when the syntax you have written is not allowed in the java language. It means java compiler is not able to genrate a .class file becuase it doe snot understand what you have written.
Runtime Error: you get Runtime errors when you actually run the program. A good example is you have written a socket program to connect a machine.If that machine is not up and runnig, then it will throw a runtime excpetion.
HTH
Praveen.
Maria Garcia
Ranch Hand

Joined: Jul 14, 2002
Posts: 86
thanks praveen
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Runtime Error: you get Runtime errors when you actually run the program. A good example is you have written a socket program to connect a machine.If that machine is not up and runnig, then it will throw a runtime excpetion.
Be aware of the terminology you are using, since a Socket will throw an IOException (a checked exception) if the bind operation fails. An exception thrown at runtime is not necessarly an instance of RuntimeException.
It would be better to write:
"If that machine is not up and running, then it will throw an exception at runtime", instead of a runtime exception
[ August 25, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Paul Villangca
Ranch Hand

Joined: Jun 04, 2002
Posts: 133
Also, it's a good idea to differentiate between errors and exceptions. Errors are events that, in general, are caused be problems beyond the control of the programmer, and can't be controlled (for example, bad sectors or some other unfortunate occurrence.) Exceptions, on the other hand, are (in general) problems in the code itself (like accessing array[array.length]), or eventualities that the compiler forces you to handle(i.e. IOException.)
Dmitry Golynkin
Greenhorn

Joined: Aug 13, 2002
Posts: 23
code:
__________________________________________________
Question 5
class D {
{System.out.print("1");}
static {System.out.print("2");}
D() {System.out.print("3");}
D(String s) {System.out.print("4");}
}
class E extends D {
{System.out.print("5");}
static {System.out.print("6");}
E() {System.out.print("7");this("e");}
E(String s) {System.out.print("8");}
}
class F {
public static void main(String[] args) {
new E();
}
}
compiler error
__________________________________________________
Question 6
class Q {
int i = 1;
{System.out.print("1");}
static {System.out.print("2");}
Q() {System.out.print("3");}
Q(int x) {System.out.print("4");}
}
class R extends Q {
int j = 2;
{System.out.print("5");}
static {System.out.print("6");}
R() {super(j);System.out.print("7");}
}
class S {
public static void main(String[] args) {
new R();
}
}
compiler error
__________________________________________________
I've seen no problem with Q5 - compiler could see that |this| stands on the second place. But in Q6 compiler doesn't know that |j| can't reached before R() construction. Why compiler error???


good luck
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hi Dmitry:
The sub-class's instance variable are not available until super-class constructor is exectuted. Here is code whose output is 123456, to show what is done (available) when..
Dmitry Golynkin
Greenhorn

Joined: Aug 13, 2002
Posts: 23
The output is 123546
(JBuilder 5 EE)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: runtime vs compiler error