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

Exceptions !!

Ankitt Dhebarr
Ranch Hand

Joined: Feb 13, 2009
Posts: 32



Can anyone help me out by telling what will be the output of the above code and how is it step by step so that I can understand it exactly !!
Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110

Vijay.

[removed some 'not so nice' suggestions]
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



System.out.println("Be Meaningful Please - post your thoughts too");
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Vijay Raj wrote:
Vijay.


Vijay, please watch your attitude!


be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Samrat Som
Ranch Hand

Joined: Feb 04, 2009
Posts: 40
I suppose We Guys are here to share our knowledge and not pointing out others in such a harsh manner.


SCJP 1.6
SCWCD 1.5 (Preparing...)
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
Ankitt Dhebarr wrote:


Can anyone help me out by telling what will be the output of the above code and how is it step by step so that I can understand it exactly !!


dont be disappointed what other people have told. This fourn is for beginner and any sort of questions can be asked.
coming down to your question:
The output will be :
ABDEF

A & B will be displayed because of normal flow execution then the exception is thrown which is caught by a catch block hence the program flow comes to catch block and 'D' is displayed and not 'C'. The finally block has to be executed in all cases whether the exception is caught or not. So 'E' is displayed and at last the control comes out from try-catch-finally block and 'F' is displayed.


<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
Ankitt Dhebarr
Ranch Hand

Joined: Feb 13, 2009
Posts: 32
I really thank all for your kind support !!
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Harshit Rastogi wrote:

...This fourn is for beginner and any sort of questions can be asked.


Harshit, this is true, however, simply asking for the answers to questions, without trying it oneself, is not a productive method of learning don't you think, after all we shouldn't be doing others homework for them.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

Ankitt Dhebarr,

Generally, we expect people to ShowSomeEffort. Posting some code and asking 'what is the output' pretty much shows you have put in NO effort. The LEAST you could do is run the code yourself. That way, you would see exactly what the output is. Then, if you don't understand it, you can ask a more focused question, like "I was expecting output A, but got output B and don't understand why".

further, you could tell us which specific part you don't understand. Do you know what System.out.print() does? Do you know what a try/catch block is? what the finally is?

In other words, the more specific your question, the easier it is for someone to help you, and the better response you'll get. You may want to read a lot of this. They really are great suggestions on how to get the most out of this site.

Thanks!!!


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Flom Xanther
Ranch Hand

Joined: May 26, 2006
Posts: 48
Are you sure this will even compile?

I think it wouldn't compile, because line 10 is surely unreachable code!


Regards,
Flom
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
This code won't compile. Once you throw a exception at line 9, the control will never go to line 10. To compile you can do this::




"History would be kind to me, for I intend to write it."
Apoorv Srivastava
Ranch Hand

Joined: Jan 03, 2009
Posts: 43
Won't compile for sure...
Line no 9 is unreachable code..


SCJP 1.5...Preparing for SCWCD
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Apoorv, surely that depends on what conditional logic he chooses to write that would result in a NumberFormat Exception?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

Stephen: Note that there's a button on the top right hand side of your post to delete it.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
OOp's apologies, I didn't notice that ata all thanks for the heads up Jesper!..

..actually I cant see it at the moment..

..sorry Jesper I cant seem to find this button anywhere...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

Hmmm.... I can see that button on all posts, but that's because I'm a moderator. I assumed that as a normal user you would be able to delete your own posts (we had such a feature in the old forum software - since the beginning of this year we have new forum software). I'll ask the other moderators about it.

I deleted the empty post for you.
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Jesper, much appreciated
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

Jesper Young wrote:I assumed that as a normal user you would be able to delete your own posts (we had such a feature in the old forum software - since the beginning of this year we have new forum software). I'll ask the other moderators about it. I deleted the empty post for you.


We are no longer able to delete our own post, with the new forum software according to this (Don't know about any update after that)


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Jae Lim
Greenhorn

Joined: Feb 20, 2009
Posts: 12
Compilation fails
Srikanth Munjuluri
Greenhorn

Joined: Dec 08, 2008
Posts: 11
hi everyone,
firstly I am sorry that a huge matter has been created about nothing......You could have answered and then say Be EXPERIMENTING guy from next time..........
And regarding the question ,this code will not compile.....because of unreachable statement.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions !!