aspose file tools*
The moose likes Beginning Java and the fly likes how to see how control is moving in a java program during execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to see how control is moving in a java program during execution" Watch "how to see how control is moving in a java program during execution" New topic
Author

how to see how control is moving in a java program during execution

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 371
when I am using C language for programming, I have a tool available to check how control is moving during execution.
Is there something available in java to see the movement of control during execution ? How can I check the control, if I am not getting desired oputput ?

Thanks
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

You can try the Debuggers which come with various IDEs like Netbeans, Eclipse.


Mohamed Sanaulla | My Blog
Buddhika Mawella
Ranch Hand

Joined: Jan 06, 2011
Posts: 39

I also use Eclipse debugger. try following link.
http://www.vogella.de/articles/EclipseDebugging/article.html


BM
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
You can put print statements in every method. But the debuggers are easier. You set a breakpoint by double-clicking the left margin of the code, and after the breakpoint you have three options:
  • Step into: follow through the method called
  • Step Over: Continue with the calling method, not inspecting the method called.
  • Step return: Execute to the end of the current method without seeing the intervening steps
  • You will have to try it to see it working.
    nirjari patel
    Ranch Hand

    Joined: Apr 23, 2009
    Posts: 371
    This is the code.


    Nothing is showing in city1.txt file. When I check debug file, follwoing lines are there
    "<terminated>ReadLine1 [Java Application]
    <terminated, exit value: 0>C:\Program Files\Java\jre6\bin\javaw.exe (2011-02-15 12:06:50 AM)"

    What shall I understand from this ? How can I see, why output is not comingup in city1.txt ? Can I checck it through control flow ?

    Please try to answer all questions.

    Thanks

    <terminated, exit value: 0>C:\Program Files\Java\jre6\bin\javaw.exe (2011-02-15 12:06:50 AM)
    Mohamed Sanaulla
    Saloon Keeper

    Joined: Sep 08, 2007
    Posts: 3068
        
      33

    Did you put a break point? You need to have a breakpoint in order for the execution to stop at the breakpoint and then you can use method suggested by Campbell to proceed further execution.

    Dont ever have an empty catch block. You are eating up the exception with out the user even getting to know. You can print/log the stacktrace in the catch block.
    Also You can have a look at the examples in the tutorial here.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38363
        
      23
    You have a serious error, that you are not closing the Reader. You ought to do that in a finally block, like this
  • Don't catch Exception; since it says IOException, or FileNotFoundException, catch those Exceptions. You will also have to import them.
  • Don't use tabs for indenting; use spaces.
  • Because you have both reading and writing in the same method, your close() methods might not both be called. It is not usually easy to have reading and writing in the same blocks. Consider a reading block which adds the text to a List<String> and a writing block which copies the text out of that List.
  • Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38363
        
      23
    I have split the reading and writing into two methods, and added some print instructions, and other testing code, marked with //test comments.By the way: in your original post you had an "end" comment about "main thread". You were not ending the main thread, but reaching the end of the main method.
     
    wood burning stoves
     
    subject: how to see how control is moving in a java program during execution