This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
what is the differance b/w checked and unchecked exceptions.
If a piece of code potentialy throws a checked exception, the compiler forces you to surround it with a try/catch or to declare that your method throws this exception. It does not if it is an unchecked exception (=> a method never has to declare that it can throw an unchecked exception)
how the JVM identifies these as checked and unchecked
Any exception inheriting from RuntimeException in unckeched, all the others are checked.
Note: unchecked exceptions must be considered as bugs: i.e. something that is not planned as opposed to checked exception which represent an unexpected state of things (like a connection closed by a 3rd party).
It is considered a bad practice to throw an unchecked exception: use something that the client class must catch deal with.
It is considered a bad practice to catch an unchecked exception: suppress the root cause in development time rather than dealing with it in runtime: remmember that (in a perfect world) unchecked exceptions must considered as bugs.
It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
Be aware that plenty of folks disagree with Simon.
The very existence of checked exceptions is controversial. Many languages don't have them and seem to get along just fine. A signficant number of bright people recommend using unchecked exceptions exclusively. Google around for more on the debate.
Bruce Eckell covers the subject with fair attention to both sides in Thinking In Java. His own suggestions matured (completely changed) from the first to third editions. Anybody know what he says in 4th edition?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi