Post

Creating Your First Java Project in IntelliJ IDEA



Creating a New Project

  1. Launch IntelliJ IDEA:
    • First, open IntelliJ IDEA on your computer.
  2. Create a Project:
    • On the welcome screen, select “Create New Project”.
    • Ensure you are on the “New Project” tab.
  3. 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.
  4. Select JDK:
    • In the dialog, ensure the correct JDK version is selected. If the JDK is not installed, follow the instructions to install it.
  5. 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

  1. Create a Package:
    • Right-click on the src directory and select “New” -> “Package”.
    • Name the package, for example, com.example.helloworld.
  2. Create a Class:
    • Right-click on the created package and select “New” -> “Java Class”.
    • Name the class Main and click “OK”.
  3. Write the Code:
    • Open the created Main class and add the following code:
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

  1. 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.