File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes compile time and run time error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compile time and run time error" Watch "compile time and run time error" New topic
Author

compile time and run time error

Venu Chakravorty
Ranch Hand

Joined: Aug 19, 2009
Posts: 46
what are the cases when one is supposed to expect:
1. compile time error
2. run time error
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

venu chakravorty wrote:1. compile time error

Compiler can catch it. mostly related to syntax validation
venu chakravorty wrote:2. run time error

Compiler cant catch it . mostly related to logic of your program
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

seetharaman venkatasamy wrote:
Compiler can catch it. mostly related to syntax validation

Some more examples might be

Typechecking errors
(Rarely) compiler crashes

seetharaman venkatasamy wrote:
Compiler cant catch it . mostly related to logic of your program

Some examples are

Division by zero
Deferencing a null pointer
Running out of memory


http://muhammadkhojaye.blogspot.com/
Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
Compile time error
--------------------------
string s=null;
This will be compile time error because "string" should be of "String"


Run time error
--------------------
ArrayList arr= new ArrayList();
arr.add("1');
arr.add("2');

System.out.println(arr.get(3));

This will be of run time error as arr is having size of 2 only but you are accessing 3rd one.
Raphael Huerta
Greenhorn

Joined: Jun 10, 2009
Posts: 2
Compile time errors happens when you attemp to compile your code and the compiler find errors such as undefined variables, missing parenthesis, accessing variables out of scoped or something like that.

Run time errors happens when your program is running and an unchecked exception is thrown such as NullPointerException or ArithmeticException.


SCJP 6, SCWCD 5
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
The really nasty runtime errors occur when the program runs happily and produces the wrong result
Venu Chakravorty
Ranch Hand

Joined: Aug 19, 2009
Posts: 46
thanks everyone.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: compile time and run time error