Results 1 to 4 of 4

Thread: Debug mode

  1. #1
    Aaron_Sharp is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Debug mode

    Quick question, is there any way to see the contents of an array being filled up during debug mode?

    lets assume I have
    for(int i=0; i<100;i++)
    array1[i] = i;

    .... array1 = {}
    step in.. array1 = {0}
    step in...array1 = {1}
    etc...

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    The elements of the array already exist when entering that loop. They just aren't initialized (i.e. all the values in the array would be 0, the default value for an integer). However, I'm not really sure what you mean by 'filled up'.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    user0 is offline Senior Member
    Join Date
    Dec 2010
    Posts
    100
    Rep Power
    0

    Default

    Hi - your question is not very clear. Do you want to see how elements are populated in the array? Assuming this is what you want to do, I would say it is possible.

    What IDE are you using to write your code?

    I use Eclipse IDE and it allows me to see an array being populated. In debug mode, if I look at the "Variables" panel, I can see the name of my array there. I can expand the name of the array and then I can see each array element (i.e. array[0], array[1], array[2]...) and the value or object stored in each element.

    If you are using an IDE other than Eclipse, I would say play around with it in Debug mode, look at all the panels and don't be afraid to explore. You should find what you are looking for.

    Best,
    --user0--

  4. #4
    charleyjoyce is offline Member
    Join Date
    Jan 2011
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Aaron_Sharp View Post
    Quick question, is there any way to see the contents of an array being filled up during debug mode?

    lets assume I have
    for(int i=0; i<100;i++)
    array1[i] = i;

    .... array1 = {}
    step in.. array1 = {0}
    step in...array1 = {1}
    etc...
    you can use the debugger jdb. Here's a simple set up to illustrate an example
    Java Code:
    public class DebuggerDemo {
        public static void main(String[] args){
            int[] integers = new int[5];
            for (int i = 0; i< integers.length;i++){
                System.out.println( integers[i] );
            }
        }
    }
    From the command line, compile your code with -g option
    Java Code:
    java -g DebuggerDemo.java
    then run jdb and type in "stop at DebuggerDemo:5". This inserts a breakpoint at line 5.
    Java Code:
    c:\> jdb
    Initializing jdb ...
    > stop at DebuggerDemo:5
    Deferring breakpoint DebuggerDemo:5.
    It will be set after the class is loaded.
    Next, type "run DebuggerDemo"

    Java Code:
    > run DebuggerDemo
    run  DebuggerDemo
    Set uncaught java.lang.Throwable
    Set deferred uncaught java.lang.Throwable
    >
    VM Started: Set deferred breakpoint DebuggerDemo:5
    
    Breakpoint hit: "thread=main", DebuggerDemo.main(), line=5 bci=4
    5                       System.out.println( integers[i] );
    
    main[1]
    at the main[1] prompt , type in "print integers[0]" for example to see your value
    Java Code:
    main[1] print integers[0]
     integers[0] = 0
    main[1] print integers[1]
     integers[1] = 0
    for more information on jdb, see here

Similar Threads

  1. Replies: 0
    Last Post: 03-18-2010, 06:39 PM
  2. Replies: 0
    Last Post: 12-18-2009, 03:14 PM
  3. watch expression in debug mode
    By bizso in forum Eclipse
    Replies: 6
    Last Post: 07-08-2009, 09:07 AM
  4. Debug challenge: how do you debug a Java program?
    By CJSLMAN in forum New To Java
    Replies: 60
    Last Post: 07-04-2009, 11:28 AM
  5. How to enable debug mode in eclipse
    By msgbharath in forum New To Java
    Replies: 3
    Last Post: 01-10-2009, 03:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •