Problem 3

An Important Message

This exercise will show you the detailed steps you must follow to create your first Java program.

Linux File Manager

In a previous problem, we learned how to create folders and files in the terminal. Now, we will use the Graphical User Interface (GUI) to achieve the same thing.

On the left application panel, open File Manager.

You will see the contents of your home ~ directory. Your personal folder should be there. Open your folder, then open up the pbd-solutions folder.

Create a folder with the GUI

Right-click in the window and select Create Folder.... A dialogue box will pop up to enter the name of the folder. Call the folder 03. Double click that folder to enter it.

Create a file with the GUI

Right-click inside the 03 folder and select Create Document > Empty File. Another dialogue box will pop up asking for the name.

Name the file FirstProg.java.

Edit the file

Double-click FirstProg.java to open it in gedit.

Type in the code listed below in a text editor or an IDE. It is important that you do NEVER copy-and paste code when you are a beginner. You will learn much quicker if you type it out yourself.

public class FirstProg {
    public static void main(String[] args) {
        System.out.println("Mr. Gallo is cool!");
    }
}

Press ctrl + s or go File > Save to save the source-code.

Compile and run

At this point we need to compile with javac and then run with java.

Open the terminal and navigate to the 03 folder which contains the FirstProg.java file. Use ls to confirm that the file is where you think it is. Compile, run, and observe the output.

~$ cd lastname/pbd-solutions/03
~/lastname/pbd-solutions/03$ ls
FirstProg.java
~/lastname/pbd-solutions/03$ javac FirstProg.java
~/lastname/pbd-solutions/03$ java FirstProg
Mr. Gallo is cool!
~/lastname/pbd-solutions/03$

What to do next

  1. Change the code so that the computer displays a different message.
  2. Change the code to output two messages.

◄ 2: Compiling Practice 4: A Good First Program ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.