Create First Java Project


Intellij Idea – Create First Java Project


”;


It is time we got a hands-on experience with IntelliJ. In this chapter, we will create our first Java Project. We will write and execute the traditional Hello World program. This chapter explains the compilation and running of Java application.

Create Project

For anything related to development, a developer has to create a new project with IntelliJ. Let us follow these steps to create a project −

  • Launch IntelliJ.

  • Go to File → New → Project menu.

  • Select the Java project and appropriate SDK and click on the Next button.

Java Project

  • If you want to create a Java class with the main method, then select Create Project from the template checkbox.

  • Select the command line app from the dialog box shown below and continue.

  • Enter the project name and the directory location.

  • Click on the Finish button.

Create Package

A package is created under Java project and can be created separately, or at the same time of creating a class. Let us follow these steps to create a package −

  • Go to the project perspective.

  • Right-click on Project, select the New->Module option.

Project Perspective

  • The new module window will be similar to the new project. Select the Java option and appropriate SDK and click on the Next button.

  • Enter the module name.

  • Click on the Finish button.

Create Java Class

In this section, we will learn how to create a Java class. A Java class can be created under a Java module. Follow these steps to create a module −

  • Go to the Project perspective.

  • Expand Project and select the src directory from the module.

  • Right click on it; select the New->Java Class option.

  • Enter the class name in the dialog-box and click on the OK button.

  • It will open the Editor window with the class declaration.

Run Java Application

We will now see how to run a Java application. Follow these steps and see how it runs −

  • Let us write a simple code, which will print a message on the console. Enter the following code in the Editor window −

public class HelloWorld { 
   public static void main(String[] args) { 
      System.out.println("Hello, World !!!"); 
   } 
}
  • Go to the Run menu and select the Run option.

  • Select the Class name and click on Run.

  • If there are no compilation errors, then it will show output at the bottom of the window.

Java Application

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *