Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get line number in JAVA code has been executed

9dbff406-2843-45e2-9ace-bb31b351f404Nov 9 2016 — edited Dec 21 2016

I wanted to count code execution routes of a method.So I want to do something at the end of a method to get the line numbers of the codes had been executed in the method of a call

I have a class like this:

2016-11-09_142758.png

if I execute the code "new Test().run(5, 3);"

I can get the result like this:"5,6,7,8".--Because the codes at line 9,10,11 are not be executed

if I execute the code "new Test().run(5, 6);"

I can get the result like this:"5,6,9,10,11" --Because the codes at line 7,8 are not be executed

How can I do this? Thanks for answering!

Comments

807591
does the program not print "executing cmd" ?
ok, first, what do you think should happen, and second, what is happening really?

you arent doing anything with the input and output streams of your program.. so i dont know what you expect
807591
I should have been thinking about it a little bit longer. After I added a
waitFor()
and redirected the output as it is described in the article I posted the link to, everything worked as it should.
1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 18 2017
Added on Nov 9 2016
7 comments
4,537 views