Ch4 – Flow Of Execution


This tutorial builds upon the previous tutorial and its use of Eclipse. Note that you are not required to use Eclipse to complete the exercises presented on this site. However, as this tutorial will demonstrate, by doing so you will find development, compiling, and debugging your programs much easier by using Eclipse.

  1. Open Eclipse and expand the NewLine project, src, and then right-click Default Package. Select New, Package from the popup menu.eclipse_new_package
  2. Name the package com.flow and click the Finish button.eclipse_com_flow
  3. Right click the newly created package and create a new class names NewLine.
  4. Create the newLine and threeLine methods as follows.
public static void newLine(){
  System.out.println();
}
public static void threeLine(){
  newLine();
  newLine();
  newLine();
}
  1. Add the following code to the main method.
public static void main(String[] args) {
  System.out.println("First line.");
  threeLine();
  System.out.println("Second Line.");
}

The final file should appear as follows.

package com.flow;
public class NewLine {
  public static void newLine(){
    System.out.println();
  }
  public static void threeLine(){
    newLine();
    newLine();
    newLine();
  }
  public static void main(String[] args) {
    System.out.println("First line.");
    threeLine();
    System.out.println("Second Line.");
  }
}
  1. Rather than run the program, let’s step through the code in debug mode. Place a breakpoint on lines 12 and seven. Or the first line in the main method and the first line in the threeLine method.eclipse_break_pointsIf the line numbers are not visible in Eclipse, go to Settings, then expand General, Editors, Highlight Text Editors, and ensure the Show line numbers option is checked.eclise_turn_on_line_numbering
  2. Click the debug button or select Debug from the Run menu.debug_buttonThe program pauses execution at the first breakpoint.eclipse_debug_stop_one
  3. Click the Step Over button to move to the next line.eclipse_step_over

As this tutorial demonstrates, using Eclipse is much easier than the command-line. If you wish using Eclipse, simply replace the “compile and run” instructions that show the command-line with the steps you take in Eclipse.