Kids Can Program Too!


Sample from PART TWO:
The Elements of Programming
Putting A Program Together
Your Very First Program!

Your Very First Program!
Here is a very simple program:

01  // Example 1, file 'Wassup.java'
02  // This program displays 'Wassup?'
03  public class Wassup
04  {
05    public static void main(String[] args)
06    {
07      // Declare a string
08      String textWassup;
09      // Store the text in the string
10      textWassup = "Wassup?";
11      // Display "Wassup?"
12      System.out.println(textWassup);
13    }
14  }


After compiling and running it, it would simply display:

Wassup?

At first glance, this program may look like gibberish to you. But don't you worry - later in this book you will learn what each and every line means. For now, the important lines are lines 8, 10 and 12:
  • Line 8 defines an area for the text we want to display and gives it the name textWassup,
  • Line 10 stores the text "Wassup?" in that area, and
  • Line 12 produces that display; writing System.out.println is just a long way of saying "print."
As you can see, there are two different types of instructions: one is a definition (line 8), the other an action (lines 10 and 12). In the next sections we will learn the purpose of each type of instruction and how they work together.

Lines 1 and 2 are just comments for a person reading the program. Lines 3 and 5 are required by the Java Compiler and the Java Virtual Machine; every program must have these lines, with minor variations; we will not bother discussing them now, but their meaning will be described later.


Home   Overview   Outline   About the Author   Members   Download   Contact Us