JavaRush /Java Blog /Random EN /Creating and Running Your First Java Application (Part 1)...
Ve4niY
Level 14

Creating and Running Your First Java Application (Part 1)

Published in the Random EN group
To get an idea of ​​how IntelliJ IDEA can help you develop and run Java applications, we suggest you create and run a simple "Hello, World" example in this program. This way you will be able to learn about the main IDE features without having to go into the details of the code. Step-by-step instructions will help you not to get confused in the intricacies of launching and configuring the program. Building and Running Your First Java Application (Part 1) - 1

Before starting work

To create Java applications, you will need the Java Development Kit ( JDK ). If the program is not already installed, it can be downloaded and installed from Oracle.com . You can also find installation instructions there.

Create a project

Creating any application in IntelliJ IDEA starts with creating a project (you can find out why a project is needed in the IntelliJ IDEA Help, under the Project link ), so our first step is to create a "Hello, World" project. This project will contain the Java module for our Java application.
  1. If no project is currently open, click the Create New Project button on the welcome screen. Otherwise, choose New Project from the File menu. This will open the project creation wizard.

  2. In the left pane, select Java Module .

  3. On the right side of the page, in the Project name field , enter the name of the project: HelloWorld.

    Building and Running Your First Java Application (Part 1) - 2
  4. If you have never set up a JDK in IntelliJ IDEA before (in which case the Project SDK field is set to <None> ), you need to do it now.

    Instead of <None>, click New and select JDK from the submenu .

    In the Select Home Directory for JDK window , select the directory where the JDK was installed and click OK .

    Creating and Running Your First Java Application (Part 1) - 3

    The JDK version you selected will appear in the Project SDK field .

    Creating and Running Your First Java Application (Part 1) - 4

    Click Next .

    Please note that the specified JDK version will be associated by default with all projects and Java modules that will be created in the future.

  5. On the next page, a wizard is selected to specify additional technologies that will be supported in our module.

    Building and Running Your First Java Application (Part 1) - 5

    Because our application will be a "good old Java application", we don't need any of these technologies. So just click the Finish button .

    Wait while IntelliJ IDEA creates the necessary project structures. When this process is complete, you can see the structure of your new project in the Project window .

Studying the structure of the project

Let's take a look at the structure of the project. Creating and Running Your First Java Application (Part 1) - 6In the project tree, we see two top-level directories:
  • helloworld . This is the node containing your Java module. The .idea folders and the files inside the HelloWorld.iml directory are used to store your project and module configuration data respectively. The SRC folders contain the source code.

  • External Libraries (external libraries). This is the category that represents all the "external" resources required for your project. Currently in this category are .jar files from our chosen JDK.
Of all the mentioned folders, in this example, we will only need SRC. (For more information about tool windows in general and the Project window in particular, see IntelliJ IDEA Tool Windows and Project Tool Window in IntelliJ IDEA Help)

Create a package

Now we are going to create a package for the HelloWorld class (We will create this class in a bit.) Let's call this package com.example.helloworld.
  1. In the Project tool window, select the SRC folder and press ALT + INSERT. (Alternatively, you can select File -> New , or New from the context menu for the SRC folder).

  2. From the New menu , select Package . (you can use the up and down arrows to navigate through the menu, ENTER to select the highlighted item)

    Creating and Running Your First Java Application (Part 1) - 7
  3. In the New Package window that opens , enter the package name (com.example.helloworld). Press the OK button (or the ENTER key).

    Creating and Running Your First Java Application (Part 1) - 8

    The new package will appear in the Project window .

    Building and Running Your First Java Application (Part 1) - 9

Create a class

  1. Press ALT + INSERT. In the New window , from the list of available actions with the com.example.helloworld package selected, select Java Class and press Enter.

    Creating and Running Your First Java Application (Part 1) - 10
  2. In the Create New Class window that appears , in the Name field , enter the name HelloWorld. In the Kind field , leave the Class type and press Enter to confirm the creation of the class.

    Creating and Running Your First Java Application (Part 1) - 11

    The generated HelloWorld class appears in the project structure:

    Building and Running Your First Java Application (Part 1) - 12

    This completes all the preparations. The process of writing our first code will be discussed in the second part of the article.

Original article: Creating and running your first Java application
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION