Start Java Programming in Eclipse

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

ECLIPSE TUTORIAL

OUTLINE

This tutorial has two sections:

Section 1. Write Java programes in Eclipse


Section 2. Create text files in Eclipse

ECLIPSE TUTORIAL - Page 1


SECTION 1 – WRITE JAVA PROGRAMS IN ECLIPSE

Typically, Eclipse should be installed on the computer you’re using.

1. From the Start menu, select the Eclipse icon to start it. Eclipse prompts you for a workspace, as
follows:

A workspace is a location in the computer file system where your Java projects and other
resources are stored. In the screenshot above, a folder named workspace is created as the
workspace folder. You can choose any accessible folder of your desire as the workspace.

2. Select Launch button to start. To create a Java project, select File, New, Java Project.

3. In the New Java Project dialog, type a project name and select the Finish button.

ECLIPSE TUTORIAL - Page 2


4. For the first-time use, you may be presented with a Welcome view. Close the Welcome tab,
you’ll see the Package Explorer. (If not, select on the menu, Window, Show View, Package
Explorer).

The Package Explorer allows you to browse the structure of your projects, create, rename or
add files. Next, create a package in the created project my java project. Java package is a way
of organising java files into, well, packages.

5. To create a package, right-select the project name my java project, then select New, Package,
Type a package name.

Note: package name needs to follow Java identifier naming rules. For example, white space
characters are not allowed in package name.

ECLIPSE TUTORIAL - Page 3


6. To create a Java program, right-select on the package name my_package, New, Class. Choose
a class name. In the screenshot below, the name ‘HelloWorld’ is used. Check the ‘public static
void main(String[] args)’ checkbox, so that a main method stub will be created.

7. Select the Finish button. You’ll see the following screen:

8. In the main method, type your first line of Java code, System.out.println(“Hello world”);.

ECLIPSE TUTORIAL - Page 4


9. To execute the Java program, in the Package Explorer, right-select HelloWorld.java, Run As,
Java Application, as below.

10. The result of running the Java program is displayed in the Console window, as below.

ECLIPSE TUTORIAL - Page 5


SECTION 2 – CREATE TEXT FILES IN ECLIPSE

At some point of the course, you may have to create text files as data source. For your Java program
to access the data, text files need to be created at the top level of Java project.

1. To create a folder at the top level, right-select project name, New, Folder.

Note, you must right-select on the project name, not any component inside the project.
Otherwise, the folder won’t be created at the top level.

2. Type the folder name data, as below, then select Finish.

ECLIPSE TUTORIAL - Page 6


3. To create a text file, right-select the newly created folder data, New, File. In the popup dialog,
type “my_data.txt”, select Finish.

4. The following screenshot shows your project structure. The src folder contains the java files,
while the data folder contains the text files.

ECLIPSE TUTORIAL - Page 7

You might also like