Creating Your First Java Project in IntelliJ IDEA
Creating a New Project
- Launch IntelliJ IDEA:
- First, open IntelliJ IDEA on your computer.
- Create a Project:
- On the welcome screen, select “Create New Project”.
- Ensure you are on the “New Project” tab.
- Set Up the Project:
- Name your project and choose a location to store your project files. For more information on naming conventions, refer to this article.
- Select the language as “Java” and choose ‘IntelliJ’ build system.
- Select JDK:
- In the dialog, ensure the correct JDK version is selected. If the JDK is not installed, follow the instructions to install it.
- Final Setup:
- Review the project settings and click “Create”.
Project Structure
After creating the project, you will see the project structure on the left panel. The main elements include:
- src: The directory where your project’s source files will be stored.
- Project Files: All configuration and build files.
Creating Your First Java Class
- Create a Package:
- Right-click on the
src
directory and select “New” -> “Package”. - Name the package, for example,
com.example.helloworld
.
- Right-click on the
- Create a Class:
- Right-click on the created package and select “New” -> “Java Class”.
- Name the class
Main
and click “OK”.
- Write the Code:
- Open the created
Main
class and add the following code:
- Open the created
1
2
3
4
5
6
7
package com.example.helloworld;
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Running the Project
- Run the Project:
- Click on any of the green triangles you see, or right-click on the class and select “Run Main.main()”.
- The console will open at the bottom, where you will see the program output:
Hello, World!
.
Conclusion
Congratulations! You have successfully created and run your first Java project in IntelliJ IDEA. Now you can start exploring the capabilities of Java and IntelliJ IDEA by adding new classes, methods, and libraries to your project.
© 2024 Java Tutorial Online. All rights reserved.