File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
nirjari patel
Ranch Hand
Posts: 386
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try the Debuggers which come with various IDEs like Netbeans, Eclipse.
 
Buddhika Mawella
Ranch Hand
Posts: 40
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also use Eclipse debugger. try following link.
http://www.vogella.de/articles/EclipseDebugging/article.html
 
Campbell Ritchie
Sheriff
Pie
Posts: 47270
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 386
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 3159
    33
    Google App Engine Java Ruby
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 47270
    52
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 47270
    52
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic