Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

curiosity about the power of Java

 
pioneer
Posts: 514
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear developers,
I am having a nice topic conversation with Ulff Ditmerr on the android subforum, about the debugger.

It is possible to execute a program that goes through the code and as output reports the exact order the rows in eclipse are executed?
I mean an algorithm that inserts a system.out.println (in android a Log.d) at the end of every line copying the content of the row immediately up to the system.out println, so that in a file of txt I can see exactly in which order all the instruction have been executed?
It is possible that nobody thought already something like this? maybe there is the so called reflection involved.

(i say this because I am quite deluded by the Eclipse debug to identify the flux of an entire program)
 
steward
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Giovanni Montano wrote:It is possible to execute a program that goes through the code and as output reports the exact order the rows in eclipse are executed?
I mean an algorithm that inserts a system.out.println (in android a Log.d) at the end of every line copying the content of the row immediately up to the system.out println, so that in a file of txt I can see exactly in which order all the instruction have been executed?


Yes. It's called a debugger, and Eclipse has one built in. Furthermore, it shows you what is being executed in context - ie, in the IDE itself - so you can inspect the values of almost anything; not the just the variables in the lines you're currently looking at.

Winston
 
pollinator
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with Eclipse, but I doubt that its debugger (or that if any other IDE, for that matter) comes with functionality like that. You can use AOP (aspect oriented programming) using a tool like AspectJ to execute code of yours at the beginning and end of each method, not each line of code - that code could log whatever you want logged. I advise to become much more familiar with the use of the debugger before deciding that it's not suited for your purposes - handling files is much more awkward than using the debugger.
 
Giovanni Montano
pioneer
Posts: 514
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:
Yes. It's called a debugger, and Eclipse has one built in. Furthermore, it shows you what is being executed in context - ie, in the IDE itself - so you can inspect the values of almost anything; not the just the variables in the lines you're currently looking at.

Winston


Winston, thank you for the interest, but the debugger after 6 days I am trying to sort out a lot of tricks to make it functional, does not go in the interfaces, because you cannot set breakpoints into them, since it is a lost-lost game( instead of win-win) because algorithmically speaking
IF you set few breakpoints,
THEN the "flux", the sequence will be limited as some classes are left out
ELSE
IF you set a lot of breakpoints
THEN you will miss the sequence because the order the breakpoints are set is not necessarly the order the compiler executes the code

So all in all or I am not able to use the debugger stepping through the flux, or the debugger is not the most efficient way to see java/android code flux

thank you again for your valuable attention
 
Ulf Dittmer
pollinator
Posts: 43011
76
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you just said reinforces my belief that you simply lack practice in using debuggers. Debuggers are for hunting down specific behavior (generally bugs) in the code, not for understanding how the various pieces of an app work together. You would set breakpoints where you want to study behavior, not all over the place.

You're right that any GUI code (and Android's in particular) is not executed particularly sequentially, due to the use of many callbacks. But an understanding and "feel" of that will come automatically as you develop more. Maybe the project you're working on now is a bit too advanced for your level of experience, or has too many classes, and you have an easier time starting with something a bit simpler.
 
Giovanni Montano
pioneer
Posts: 514
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What you just said reinforces my belief that you simply lack practice in using debuggers. Debuggers are for hunting down specific behavior (generally bugs) in the code, not for understanding how the various pieces of an app work together. You would set breakpoints where you want to study behavior, not all over the place.

You're right that any GUI code (and Android's in particular) is not executed particularly sequentially, due to the use of many callbacks. But an understanding and "feel" of that will come automatically as you develop more. Maybe the project you're working on now is a bit too advanced for your level of experience, or has too many classes, and you have an easier time starting with something a bit simpler.


Ulf I appreciate, by the way you are helping a lot of people on the other forum, you really nice thank you,
I will follow your recommendation, but to be honest still I am curious to know if advanced developer can use tools based on reflection to examine larger amount of "flux", and mainly why i cannot found example in internet, it looks like I am the first guy that is thinking to do this, that could be an unvaluable feature for newcomers
 
Marshal
Posts: 25158
64
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I read your posts, it seems to me that the way you use the debugger involves only setting breakpoints. When I use the debugger I step through the code one line at a time, using the "step forward" and "step into" buttons in Eclipse. It seems that you haven't discovered those buttons yet.
 
Giovanni Montano
pioneer
Posts: 514
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:When I read your posts, it seems to me that the way you use the debugger involves only setting breakpoints. When I use the debugger I step through the code one line at a time, using the "step forward" and "step into" buttons in Eclipse. It seems that you haven't discovered those buttons yet.


Paul, thank hou to read my post,
i use step into, return and mainly over, to skip line by line , it is also cool to put the cursor on some variables to see their value and using relative view, also i never used conditional formatting

i found it really hard to make it the debugger functional under android, but now that the settings are sorted out and i am acquiring more experience so i am more satisfied, indeed.
is learning, learning, learning, that is fantastic compared to my dull normal job. i would close now the discussion, case is solved, a special thank to ulf, wintson ritchie, the dutch "kerel" and of course to you, guys you help a lot of smart people to make their dream true, your consistency to reply the posts say a lot about your professionalism and individual world virew, thank you again to make this the best java place, and one of the best learning platform in general in all the web.
 
Winston Gutkowski
steward
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Giovanni Montano wrote:but to be honest still I am curious to know if advanced developer can use tools based on reflection to examine larger amount of "flux", and mainly why i cannot found example in internet, it looks like I am the first guy that is thinking to do this, that could be an unvaluable feature for newcomers


I'd actually say that an advanced developer would try to avoid using a debugger as much as possible.

And the main way to do that, ironically, is to
(a) Keep code as simple as possible.
(b) Keep methods as short as possible.

I suspect that if you do, the occasions you'd actually need something like a "Java eval()" would be very few.

Winston
 
Giovanni Montano
pioneer
Posts: 514
10
Android Open BSD Slackware
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I found after some other days of research an interesting trick, I will publish for users that search older posts.

in code template in Eclipse but also on IntelliJ, AndroidStudio, it is possible to make a code template shortcut that returns some really interesting parameters.

In Eclipse go to Preferences > Java > Editor > Templates and click on "New...".
This will let you create a new Code Template.

Fill in the form as followed:

•Name = logd
•Context = Java statements
•Select 'Automatically insert'
•Description = Log.d shortcut
•Pattern = ${:import(android.util.Log)}Log.d("${enclosing_type}", "${enclosing_method}: ${cursor}");
but still despite I looked into all the lines, I cannot obtain the line( that in android studio is possible to retrieve), nor the copy of the line of code before


the source is http://bon-app-etit.blogspot.nl/2013/10/create-code-template-for-logd-in-eclipse.html
 
Giovanni Montano
pioneer
Posts: 514
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I found another solution, using a special dedicated class,

EDIT:
it looks as it works really well, but as newbe I am struggling to find a way to effectively use it in Log.d:


import android.util.Log;
public class DebugLog {
public final static boolean DEBUG = true;
public static void log(String message) {
if (DEBUG) {
String fullClassName = Thread.currentThread().getStackTrace()[2].getClassName();
String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
int lineNumber = Thread.currentThread().getStackTrace()[2].getLineNumber();

Log.d(className + "." + methodName + "():" + lineNumber, message);
}

}
}

http://stackoverflow.com/questions/115008/how-can-we-print-line-numbers-to-the-log-in-java
 
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!