Set up IntelliJ and run your first program
Part of the free Low-Level Design course on LogicWiz, in the chapter: Start here: your machine and Java. The class-diagram exercises run in the app.
Set up IntelliJ and run your first program
"I can read your design on paper. Now run it on your laptop and show me what the console prints."
Priya, at the start of Arjun's first practice session
Why you will practise on your own laptop
Arjun has an LLD round and a machine-coding round coming up. In a machine-coding round you get a problem and about 90 minutes. You write a working program on your own laptop, in an editor you know, and the interviewer watches it run.
This course matches that. The site shows you problems, designs and checks, but it does not run your code. For every problem you write the program in your own IDE and run it yourself. Priya says, "A design you never ran is a guess."
You may come from Python, JavaScript or C++, or from no language at all. This lesson takes you from an empty laptop to a program that prints a result.
You need two things.
- A JDK, the Java Development Kit. It holds the compiler,
javac, which checks your Java text and turns it into a form the computer can run. It holds the tooljava, which runs that form. It also holds Java's standard library: ready-made classes such as lists and strings. - An IDE, an integrated development environment. It is one window with an editor, buttons to build and run your program, and a debugger that lets you pause the program and look inside.
The IDE in this course is IntelliJ IDEA, made by JetBrains. It can download a JDK for you, so you may not need to install anything else by hand.
Install IntelliJ IDEA and get a JDK
Product names change, so here is how things stand in November 2026, from the JetBrains documentation. Since version 2025.3 JetBrains ships one product, called IntelliJ IDEA. Older guides name two editions: Community Edition, which was free, and Ultimate, which was paid. They are now one download.
The free features of IntelliJ IDEA need no subscription, and they cover everything in this course. A new install can offer a free 30-day trial of the Ultimate features. After the trial you can subscribe or carry on with the free features. If a friend says "Community Edition", they mean those free features. An older Community Edition also works for this course.
To install:
- Open jetbrains.com/idea/download in your browser and download the installer for your system.
- On Windows, run the installer. On a Mac, open the disk image and drag the app to Applications. Pick the image that matches your chip, Apple Silicon or Intel.
- Start IntelliJ IDEA. If the first screen asks about a trial or an account, read the choices. The free features are enough here.
Now check whether you already have a JDK. Open a terminal (Terminal on a Mac, Command Prompt on Windows) and type javac -version. A line such as javac 21.0.2 means you have a JDK. You need version 17 or newer. If the command is not found, or the number is below 17, let IntelliJ download one in the next step.
Newer versions such as 21 and 25 are fine. They are long-term support releases, and our code, written for Java 17, runs on them. IntelliJ itself opens without any Java installed, because it carries its own runtime. Your projects still need a separate JDK. IntelliJ's menus often call a JDK an SDK, a software development kit. It means the same here.
Create the project and your first class
- On the Welcome screen click New Project. In an open window use File, New, Project.
- In the New Project window choose Java in the list on the left. Do not pick a framework.
- Name the project
swiftkart-practice. Keep the suggested location or pick a folder you will find again. - For Build system choose IntelliJ. Maven and Gradle are build tools for large projects, and you do not need them.
- Open the JDK list. Pick a JDK of version 17 or newer if one is listed. If none is, choose Download JDK, pick a version and a vendor, and click Download. Any vendor works. If you are unsure, keep the one already selected.
- Leave "Add sample code" and "Create Git repository" switched off. Click Create.
The project opens. On the left is the Project tool window, a panel that lists your files. If it is hidden, press Alt+1 (Command+1 on a Mac). Your Java files live in the folder named src.
Right-click src, choose New, then Java Class. A small box asks for a name. Type Main and press Enter. IntelliJ creates the file Main.java. Type this into it.
public class Main {
public static void main(String[] args) {
long totalPaise = 2 * 6800 + 4500;
System.out.println(String.format("Cart total: Rs %d.%02d", totalPaise / 100, totalPaise % 100));
}
}
Read it slowly. Java starts your program by calling a method named main. The words in front of it are fixed: public means anyone may call it, static means it belongs to the class, so Java can call it before any object exists, and void means it returns nothing. The args part holds words typed after the program name, and we ignore it.
The cart holds two cartons of milk at 6800 paise each and one bread at 4500 paise. Paise are whole numbers: 100 paise make one rupee. The / between whole numbers drops the fraction, so 18100 / 100 gives 181 rupees. The % gives the remainder, 0 paise. The text %02d prints a whole number with at least two digits, padded with a zero.
Newer Java versions allow a shorter main, and IntelliJ's own tutorial uses it. We use the classic form because the problem kits use it and it works on Java 17.
Run it and read the console
Look at the grey strip to the left of the line numbers. A green triangle sits beside class Main and beside main. Click it and choose Run 'Main.main()'.
What happens next has two steps. First the compiler reads the whole file and checks every line. Python skips this step and finds mistakes only when it reaches the bad line. In Java, a mistake stops everything before anything runs. If the check passes, the Java runtime runs your main. IntelliJ does both steps when you press Run.
A Run tool window opens at the bottom. Its first line is the long command IntelliJ used. Ignore it. The next line is your output, and the last line says the program ended.
Cart total: Rs 181.00
Process finished with exit code 0
Exit code 0 means the program ended normally. Any other number means it stopped with a problem.
IntelliJ now keeps a run configuration named Main. It is a saved answer to "what should I start, and how". It appears in the top right of the window beside a green triangle. Click that triangle, or press Shift+F10 on Windows and Linux or Control+R on a Mac, to run it again. Hover over any button to see the key for your computer. The Run menu offers the same actions. The red square stops a program that does not end by itself.
The three errors almost every beginner meets
A missing JDK. You see a message that the project JDK is not defined, or that no JDK is specified, and the classes in your code turn red. The wording differs between versions. The cause is that the project has no JDK, so it cannot compile. To fix it, choose File, Project Structure. Under Project Settings open Project. In the SDK list pick a JDK of version 17 or newer, or choose Download JDK. Click OK.
A class name that differs from the file name. You see an error such as this one from the compiler.
Main.java:1: error: class Main is public, should be declared in a file named Main.java
IntelliJ shows nearly the same words in red. Java requires a public class to live in a file with the same name, so Mian.java cannot hold Main. To fix it, right-click the class name in the editor and choose Refactor, then Rename (Shift+F6). Type the correct name. IntelliJ renames the file, the class and every use together. Do not edit only one of them.
A package line that does not match the folder. A package is a named group of classes. Its name must match the folders under src, so package practice; belongs in a folder src/practice. A file directly under src has no package line. The mismatch shows as a red package line, as "cannot find symbol" for classes in your other files, or as "Could not find or load main class" when you run outside the IDE. To fix it, delete the package line if the file sits directly under src. Otherwise press Alt+Enter on the red line and choose a fix that makes the name and the folder agree. All files of one program must share the same package line.
Mac, Windows and Linux in a few lines
- Mac: most shortcuts use Command where Windows uses Control, and Option where Windows uses Alt. Apple menu, About This Mac, shows whether your chip is Apple Silicon or Intel.
- Windows: use the installer. IntelliJ asks for about 8 GB of memory and 10 GB of free disk.
- Linux: JetBrains offers the Toolbox App, or a tarball that you unpack and start with
bin/idea.sh. A snap package exists, but JetBrains recommends the Toolbox App because of reported problems.
If you prefer Visual Studio Code, install a JDK and the Extension Pack for Java. Every step in this course is written for IntelliJ.
📌 Summary: You need a JDK, which compiles and runs Java, and an IDE. Create a Java project, add a class with main, run it from the gutter triangle, and read the Run window.
What Arjun learns next
Arjun's first program prints a cart total. Next, Priya gives him a short tour of the Java he needs: its types, text and decisions, set beside the language he already knows.
Check your understanding
- Arjun has installed IntelliJ IDEA but never installed Java. In a new project the JDK list is empty. What is the quickest correct fix?
- The compiler says "class Cart is public, should be declared in a file named Cart.java", but Arjun's file is Cart1.java. What is the best fix?
- The Run window ends with "Process finished with exit code 0". What does that tell Arjun?
- Arjun pastes a file that begins with "package practice;" into src. His other files have no package line, and now he sees "cannot find symbol". Why?