Beginning Steps

Tour of Java

Take a look through your App.java class. Yeah— it's only around 5 lines of code. But we'll fix this. All of your code is put into classes. Classes are like the blueprints of your code— they define your code's purpose. We'll go into more detail much later.

Main Method

Most programming languages require a starting point for their code when it's run. For Java, it's the main method. If you look at your App.java file, the main method is the only thing inside your App class.

Running Your Code

If you look at the main method, you might notice the Run | Debug stuff above it. If you want to run your code, click this. You could also click the arrow next to the Command Palette to run it. Click the "Run" button below and see what happens.

Objective: Click the "Run" button and see what happens.

Well, nothing happens. Except that a cool window appears on the bottom of your screen with a bunch of complicated mumbo-jumbo.

This window is called the "Console" (also called the "Terminal" in other coding software). The console is a way for the code to "talk" to the programmer. It can do cool stuff like... tell you if your code has an error or something. However- our code can log data into the console. We just need to tell it which data we want it to log.

Let's fix this by writing our first line of code!

Print statements log a single line into the console. Like I mentioned- they are useful for logging data into our code.

There are two types of print statements:

System.out.print(your text here)

All this does is print whatever's in its parameters (data in the parenthesis) into the terminal, and nothing else.

Example:

System.out.print("This is a ");
System.out.print("print statement.");
-- output: This is a print statement.

System.out.println(your text here)

This is similar to System.out.print() except that after the text is printed, the pointer goes down a line. It's like writing a sentence, then going down a line.

Example:

System.out.println("This is a ");
System.out.println("print statement."); 

-- output: Hello
           World!

Objective— Write your First Code

Throughout this entire GitBook, you'll encounter tons of different challenges such as this one. All the requirements are given below, plus hints if needed.

All you'll need to do is:

Now- click the Run | Debug button again, and see what happens!

[insert print console pic over here]

If there isn't any scary red text that's not "Hello, World!", congratulations! You've just written your first line of code! The first of many.

Last updated