Step 1: Install Java Development Kit (JDK)
- Download JDK:
- Visit the official Oracle JDK download page or an alternative like OpenJDK.
- Choose the appropriate version for your operating system (Windows, macOS, Linux) and download the installer.
- Install JDK:
- Follow the installation instructions provided by the installer.
- During installation, set the Java Home path. This is the directory where the JDK is installed. Note this path; you’ll need it later.
- Verify Installation:
- Open a terminal or command prompt.
- Type the following command and press Enter:
java -version
- This should display information about the installed Java version.
- Similarly, check the Java Compiler version:
javac -version
Step 2: Choose an Integrated Development Environment (IDE)
Choose an IDE based on your preference. Two popular choices are Eclipse and IntelliJ IDEA.
For Eclipse:
- Download Eclipse:
- Visit the official Eclipse download page.
- Choose the Eclipse IDE for Java Developers package and download the installer.
- Install Eclipse:
- Run the installer and follow the on-screen instructions.
- Configure Eclipse:
- Open Eclipse.
- Set the workspace location (where your projects will be stored).
For IntelliJ IDEA:
- Download IntelliJ IDEA:
- Visit the official IntelliJ IDEA download page.
- Download the Community (free) or Ultimate (paid) edition.
- Install IntelliJ IDEA:
- Run the installer and follow the installation instructions.
- Configure IntelliJ IDEA:
- Open IntelliJ IDEA.
- Complete the initial setup wizard, including configuring the JDK.
- Set the project directory.
Step 3: Configure IDE with JDK
Eclipse:
- Open Eclipse.
- Go to
Window > Preferences. - In the Preferences window, navigate to
Java > Installed JREs. - Click “Add External JARs” and select the
jarfiles in your JDK’slibdirectory. - Click “Apply and Close.”
IntelliJ IDEA:
- Open IntelliJ IDEA.
- Go to
File > Project Structure. - Under Project, ensure that the Project SDK is set to the installed JDK.
- Click “OK” to apply changes.
Step 4: Create a Java Project
- Open your chosen IDE.
- Create a new Java project.
- Write a simple Java program to test your setup.
For Eclipse:
- Open Eclipse.
- Go to
File > New > Java Project. - Enter a project name (e.g.,
HelloWorld) and click “Finish.” - Inside the
srcfolder of your new project, create a new Java class:- Right-click on the
srcfolder. - Choose
New > Class. - Enter a class name (e.g.,
HelloWorld) and check the option to include thepublic static void main(String[] args)method. - Click “Finish.”
- Right-click on the
- In the editor, replace the default code in
HelloWorld.javawith the following:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
- Save the file (
Ctrl + SorCmd + S). - Right-click on the
HelloWorldclass file in thesrcfolder. - Choose
Run As > Java Application.
You should see the output “Hello, World!” in the console at the bottom of the Eclipse window.
For IntelliJ IDEA:
- Open IntelliJ IDEA.
- Click on
Create New Project. - Choose
Javaon the left sidebar, and clickNext. - Enter a project name (e.g.,
HelloWorld) and clickFinish. - Inside the
srcfolder of your new project, create a new Java class:- Right-click on the
srcfolder. - Choose
New > Java Class. - Enter a class name (e.g.,
HelloWorld) and check the option to include thepublic static void main(String[] args)method. - Click
OK.
- Right-click on the
- In the editor, replace the default code in
HelloWorld.javawith the following:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
- Save the file (
Ctrl + SorCmd + S). - Right-click on the
HelloWorldclass file in thesrcfolder. - Choose
Run 'HelloWorld.main()'.
You should see the output “Hello, World!” in the Run window at the bottom of the IntelliJ IDEA window.