- Getting started with Java and the Eclipse IDE
- 1. Getting started with Java development and the Eclipse IDE
- 2. Create your first Java program
- 2.1. Create project
- 2.2. Create package
- 2.3. Create Java class
- 2.4. Run your application code from the IDE
- 3. Eclipse Resources
- How to Start and Compile a Short Java Program in Eclipse
Getting started with Java and the Eclipse IDE
1. Getting started with Java development and the Eclipse IDE
In this tutorial you learn how to get started with the Eclipse IDE to start programming in Java.
You learn how to create a Java project and your first Java class and how to start your program.
It assumes that you already installed and started the Eclipse IDE. It also uses the dark theme from Window Preferences Appearance Theme .
2. Create your first Java program
The following section describes how to create a minimal Java application using the Eclipse IDE.
2.1. Create project
Click on the Create a Java project quicklink. Select File New Java project from the menu. Enter com.vogella.eclipse.ide.first as the project name and press the Finish button to create the project.
Select Create if you are asked to create a module file.
A new project is created and displayed as a folder. Open the com.vogella.eclipse.ide.first folder and explore the content of this folder.
In this tutorial the project is typically named the same as the top-level Java package in the project. This makes is easier to find a project related to a piece of code if you use multiple projects.
2.2. Create package
A good naming convention is to use the same name for the top level package and the project. For example, if you name your project com.example.javaproject you should also use com.example.javaproject as the top-level package name.
Create the com.vogella.eclipse.ide.first package by selecting the src folder, right-click on it and select New Package .
Press the Finish button.
2.3. Create Java class
Right-click on your package and select New Class to create a Java class.
Enter FirstJava as the class name and select the public static void main (String[] args) checkbox.
Press the Finish button.
This creates a new file and opens the Java editor. Change the class based on the following listing.
package com.vogella.eclipse.ide.first; public class FirstJava public static void main(String[] args) System.out.println("Hello, World!"); > >
You could also directly create new packages via the new Java class dialog. If you enter a new package in this dialog, it is created automatically.
2.4. Run your application code from the IDE
Now run your code. Right-click on your Java class in the Package Explorer or Project Explorer and select Run-as Java application .
You can also right-click in the editor and select Run-as Java application .
Eclipse will run your Java program. You should see the output in the Console view.
Congratulations! You created your first Java project, a package, a Java class and you ran this program inside Eclipse.
3. Eclipse Resources
If you need more assistance we offer Online Training and Onsite training as well as consulting
How to Start and Compile a Short Java Program in Eclipse
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time.
This article has been viewed 87,151 times.
These instructions will teach you how to start and compile a short Java program using the Indigo release of Eclipse. Eclipse is a free, open-source integrated development environment that you can use to develop Java programs, as well as programs in other languages. This tutorial assumes that you already have Eclipse installed on your computer. The purpose of this tutorial is to help you navigate Eclipse and to show off a few of its many features. Eclipse is easy to learn and will increase your productivity dramatically.
Begin by creating a new Java project. There are a few different ways of accomplishing this. You can click the arrow next to the left-most icon on the toolbar and select «Java Project» from the drop-down menu. Alternately, you can start a new Java project by choosing «File,» then «New,» followed by «Java Project.» You can also use the shortcut Alt+Shift+N.
Enter a project name. You will see a window titled «Create a Java Project.» The buttons «Next» and «Finish» at the bottom of the window will be greyed out until a project name is entered in the first field. To proceed, give your project a name and enter it into this field. For this tutorial, we will use the name «Project1.» Enter the name and then click «Finish.» Your new project will appear on the left-hand side of the screen under «Package Explorer» among existing projects. Projects are listed in alphabetical order.
Start a new Java class. Before you begin writing code, you will need to create a new Java class. A class is a blueprint for an object. It defines the data stored in the object as well as its actions. Create a class by clicking the «New Java Class» icon, which looks like a green circle with the letter «C» in the center of it.
Enter the name of your class. You will see a window titled «Java Class.» To proceed, enter the name of your class into the field «Name.» Since this class will be the main class of the simple project, check the selection box labeled «public static void main(String[] args)» to include the method stub. Afterwards, click «Finish.»
Enter your Java code. Your new class called Class1.java is created. It appears with the method stub «public static void main(String[] args)» along with some automatically generated comments. A method will contain a sequence of instructions to be executed by the program. A comment is a statement that is ignored by the compiler. Comments are used by programmers to document their code. Edit this file and insert the code for your Java program.
Watch out for errors in your code. Any errors will be underlined in red, and an icon with an «X» will show up on the left. Fix your errors. By mousing over an error icon, you can see a suggestion box that lists the ways you can fix the error. In this tutorial, we will double-click «Create local variable answer» so that the variable is declared first before it is used.
Ensure that your entire program is free of errors. There are three types of errors you must beware of: syntax errors, run-time errors, and logic errors. The compiler will alert you of the first of these three, the syntax errors. Examples of syntax errors are misspelled variable names or missing semi-colons. Until you remove all syntax errors from your code, your program will not compile. Unfortunately, the compiler will not catch run-time errors or logic errors. An example of a run-time error is trying to open a file that does not exist. An example of a logic error is opening and using data from the wrong file.
Compile your program. Now that your program is free from errors, click the triangular icon to run your program. Another way to run your program is to select «Run» from the main menu and then select «Run» again from the drop-down menu. The shortcut is Ctrl+F11.
Verify that the output is what you expected. When your program runs, the output, should there be any, will be displayed on console at the bottom of the screen. In this tutorial, our Java program added two integers together. As two plus two equals four, the program is running as intended.
Fix any run-time or logic errors. As stated previously, the compiler will only catch syntax errors. If the output of your program is different from what you’ve expected, then there might have been an error even though the program compiled. For example, if the output was zero instead of four, then there was a mistake in the program’s calculation.