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 . Installation instructions can also be found there.Creating a Project
Creating any application in IntelliJ IDEA begins with creating a project (you can find out why a project is needed in IntelliJ IDEA Help, by clicking the Project link ), so our first step is to create a “Hello, World” project. This project will contain a Java module for our Java application.-
If no project is currently open, click the Create New Project button on the Welcome screen. Otherwise, select New Project from the File menu. This will open the New Project Wizard.
-
In the left pane, select Java Module .
-
On the right side of the page, in the Project name field , enter the name of the project: HelloWorld.
-
If you have never configured a JDK in IntelliJ IDEA before (in which case the Project SDK field is <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 .
The JDK version you selected will appear in the Project SDK field .
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.
-
On the next page, you select a wizard to indicate additional technologies that will be supported in our module.
Since 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 project structure
Let's take a look at the project structure. In the project tree we see two top-level directories:-
HelloWorld . This is the node containing your Java module. The .idea folders and files inside the HelloWorld.iml directory are used to store your project's configuration data and modules respectively. The SRC folders contain the source code.
- External Libraries (external libraries). This is a category that represents all the "external" resources needed for your project. Currently this category contains .jar files from our chosen JDK.
Creating a package
Now we're going to create a package for the class HelloWorld (We'll create this class a little later.) Let's call this package com.example.helloworld.-
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).
-
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)
-
In the New Package window that opens , enter the package name (com.example.helloworld). Click OK (or ENTER key).
The new package will appear in the Project window .
Creating a class
-
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.
-
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.
The created HelloWorld class appears in the project structure:
At this point all preparations are completed. The process of writing our first code will be discussed in the second part of the article.
GO TO FULL VERSION