Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Based on the message, what kind of failure is this?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a mistake on purpose to see what the compiler would throw at me. In this case, I omit the variable that's called inside a method:



and in the main class


and I got


I'm using eclipse and surprisingly, only the T class that has those little red x mark at tryMe method pointing that I made a mistake there. But the code in Main.java is clean. No red x mark anywhere. ut then after "Run as Java Application", I get the failure (which I'm expecting). Now, Is this an Error (because of java.lang.Error) or exception (because the failure text also mentioned "Exception in thread..."). If exception, is it runtime or checked? Or is it just a compile error and none of the failure type I mentioned before? thanks
 
Ranch Hand
Posts: 109
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

Did you run this code after declaring public String name(line 5 - class T) as a comment //?
If you are it's a compile error because syntax error at line 5 in class T. Then remove // on line 5 in class T and try to run.
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hard to say. When I try to compile Main.java my compiler says:
 
Udara Amarasinghe
Ranch Hand
Posts: 109
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, did you remove // in class T?
 
Michael Ernest
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Udara Amarasinghe wrote:
Michael, did you remove // in class T?


I did. Does not make any difference to the compiler; maybe it contributes to an IDE bug, but a comment shouldn't affect the IDE runtime verifier either.
 
John Batista
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Different error message? this is unexpected. Did you run from console using java command? I run this from eclipse.
@Udara: so it's compile error as in Error type? not exception? I'm still a bit confused.
 
Michael Ernest
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did run it from a console, as I figured the error you received must have something to do with how the IDE editor and verifier are interacting.
 
Udara Amarasinghe
Ranch Hand
Posts: 109
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Batista wrote:Different error message? this is unexpected. Did you run from console using java command? I run this from eclipse.
@Udara: so it's compile error as in Error type? not exception? I'm still a bit confused.


In here compiler errors means just errors that appears in the comply time because of inappropriate syntax, try to comply not java files or mistakes like that...

But there is runtime errors that throws by JVM when found unrecoverable errors. And they are derived from java.lang.Error class.
And Exceptions are thrown by the program. Programs can recover from those. And they are derived from java.lang.Exception class.

these tutorial will helps you tutorial.

Michael Ernest wrote:I did run it from a console, as I figured the error you received must have something to do with how the IDE editor and verifier are interacting.


I didn't try it with eclipse IDE. So perhaps.
 
John Batista
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, how do one predict what kind of failure a code will give? Is it possible to predict that it's gonna be compile error or exception (and if exception, will it be checked or unchecked)? or do I have to memorize these? because there are exam questions that will ask about the result of an execution block. thanks
 
Ranch Hand
Posts: 83
Netbeans IDE MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ranch

Its exception of type java.lang.RuntimeException

while compiling compiler try to look for the variable "name" which you are printing. It cannot find the variable name becoz you have commented (for testing i suppose). It throws a runtime exception. its not a forced exception........ But its a compilation error only

look what result i got when i run it in the NetBeans

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
 
vinayak jog
Ranch Hand
Posts: 83
Netbeans IDE MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ranch

Its exception of type java.lang.RuntimeException

while compiling compiler try to look for the variable "name" which you are printing. It cannot find the variable name becoz you have commented (for testing i suppose). It throws a runtime exception. its not a forced exception........ But its a compilation error only

look what result i got when i run it in the NetBeans

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code

try to write both classes in same file
 
Udara Amarasinghe
Ranch Hand
Posts: 109
Netbeans IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Batista wrote:so, how do one predict what kind of failure a code will give? Is it possible to predict that it's gonna be compile error or exception (and if exception, will it be checked or unchecked)? or do I have to memorize these? because there are exam questions that will ask about the result of an execution block. thanks


Yes you have to keep them in memory. But it's very easy thing because if you can keep basic theories of the java language than definitely you will be able to determine what going on in this code and whether it makes errors or not. I suggest you to do more particles and try to understand and keep in memory those basic theories.

vinayak jog wrote:Its exception of type java.lang.RuntimeException


Vinayak, that runtime exception appears because you run this code in NetBeans. It's a IDE side runtime exception. If you compile this code as the default way(using javac command on a command prompt) without a IDE. You will get compilation failure without any thrown exception types of java.lang.Exception or Error types of java.lang.Error.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic