Print Page Print Page

CH4 – Adding New Methods


This tutorial presents Eclipse. The tutorials on this site almost exclusively use the command-line or DrJava. However, you should have a basic understanding of Eclipse and so the next couple tutorials introduce you to Eclipse.

  1. Open Eclipse.
  2. Accept the default workspace by clicking the OK button.eclipse_launcher
  3. Ensure Eclipse is configured to build automatically by ensuring the Build Automatically option in the Project menu is checked.eclipse_build_automatically
  4. From the File menu, select New->Other.eclipse_menu_new_project
  5. From the popup window, expand Java and select Java Project. Click the Next button.eclipse_java_project_picker
  6. Name the project NewLine and click the Next button.eclipse_new_project_name
  7. Click the Finish button.
  8. In the left window, expand NewLine and highlight src.eclipse_src_highlight
  9. From the File menu, select New->Java Class.eclipse_menu_new_class
  10. Name the new class NewLine and be certain the checkbox indicating you would like to create the main method is checked.eclipse4
  11. Click the Finish button.
  12. Within the NewLine class, create the following method. Be certain you do not place it within the main method.
	public static void newLine(){
		System.out.println();
	}
  1. Within the main method, add the following three statements.
System.out.println("First Line.");
newLine();
System.out.println("Second line.");
  1. As Eclipse is configured to build automatically, the project should be compiled if you made no mistakes and you are not required to manually compile the class.
  2. Either click the Run button eclipes_run_buttonor select Run from the Run menu.eclipse_run_menu

The output should appears as follows.eclipse_run_output

The complete program should appear as follows.

public class NewLine {
	public static void newLine(){
		System.out.println();
	}
	public static void main(String[] args) {
		System.out.println("First line.");
		newLine();
		System.out.println("Second line.");
	}
}