Tips & Tricks Tutorials

Tutorial: Your First Java Application

Most readers of the IntelliJ IDEA blog are long past writing “Hello World” applications, but there are plenty of people who haven’t yet taken that first step to writing a Java program. If you are one of them, this tutorial is for you.

(If you’re an experienced developer, show students, juniors, friends and family this tutorial to get them started).

This video is based off the existing Create your first Java application tutorial. Before you get started, you will need to download and install IntelliJ IDEA.

Remember, IntelliJ IDEA Community is open source and completely free to use, and contains all the functionality you need to get started as a Java developer.

Once you’ve installed IntelliJ IDEA, you can watch the video and follow the tutorial steps together.

Some top tips, shortcuts and features from this video:

  • To create a new class, press ⌘N on MacOS or Alt+Insert on Windows or Linux on the directory in the Project Window, and select “Java class”.
  • When creating a new class, we can type the whole package path, separated by dots, followed by the class name, and IntelliJ IDEA will create the package and the Java file.
  • Move onto the next line in a class file by pressing Shift+Enter. This will put us onto the next line in the correct position and won’t break the previous line the caret was on.
  • To create a standard Java main method, we can simply type “main”. IntelliJ IDEA will generate a public static void main method for us with the correct parameters.
  • Live templates save us a lot of typing. Use ⌘J, or Ctrl+J in Windows or Linux, to see a list of all live templates that are valid for the current context.
  • Pressing Esc will always close a dropdown or dialog without making changes.
  • If we press Ctrl+. (that’s a period/full stop) when a code completion item is highlighted, IntelliJ IDEA will complete our code with the selected item and place a dot after it.
  • Go to the Run Window with ⌘4, or Alt+4 on Windows or Linux. Pressing this shortcut again will close the run window and put the focus back on the Editor.
  • Java ARchive (JAR) files are called artifacts in IntelliJ IDEA.
  • The keyboard shortcut ⌘; or Shift+Ctrl+Alt+s on Windows or Linux will open the Project Structure dialog.
  • Press Shift twice to use Search Everywhere if you don’t know the shortcut for something.
  • Pressing Ctrl twice brings up the Run Anything box, which is yet another way to run one of our configurations.

See also:

Whether you’ve completed this tutorial or are looking for some other way to start learning Java, check out IntelliJ IDEA Edu, a version of IntelliJ IDEA that provides courses to teach you Java. Or you can install the EduTools plugin.

image description

Discover more