Our first Java application

Updated: 3 years ago

Check out other lessons in Learning the Java syntax

Now that we've covered the basic structure, let's get to work. In this lesson, we are going to create our first Java application. A simple program that will display text to the console.

Displaying text

It's time to create our first application. We'll use a method called System.out.println() to display text to the console. We'll put that method inside our main method code block (inside the {}) and then we'll run the program.

 package com.codescrubs;

 public class Main
 {
     public static void main(String[] args)
     {
         // This will output Java is pretty cool! to the console
         System.out.println("Java is pretty cool!");
     }
 }

So I put System.out.println("Java is pretty fun!"); inside the curly brackets under the main method. Do not forget to end the statement with a;, because otherwise it won't work. Like a period is used in English to end a statement, a semicolon (;) is used to end a Java statement. Without it Java doesn't know when the statement finishes.

Running your app

If you check the IntelliJ toolbar you'll see Run. Click on the option Run 'Main'. Click it.

At the bottom you should see

Java is pretty fun!
Process finished with exit code 0

If you're following along, congratulations. You've just created your first Java application.

What's actually going on?

System.out.println(); is a method inside a System class that enables us to display text to the console. Whatever you put inside the parenthesis in double quotes ("") will be displayed to the screen. Double quotes are necessary because that's how you create strings, which we will cover in the next lesson.

» Next lesson:
Variables