All programming courses seem to start with the simplest program called "HelloWorld". Notice the image below contains programmer comments (in blue text) a class name "HelloWorld" (in a green field), a main method (in a yellow field), a system out command containing literal text, and a terminal window showing the output of our first program. This is the way out programming environment looks using the BluJ IDE.
Multi-Line comments are generally used to describe a class or method, they can describe preconditions and expected results, and they usually precede the class or method to which they pertain.
Simple Adding Program
This program accepts user input for two integers. It will NOT accept decimal values. If the user enters a decimal the program with terminate due to a run-time error. This program introduces you to the ability to collect user import. A necessary component is the Scanner object. First, you must import the Scanner class from the Java utilities library, notice the first line of code is the import statement.
import java.util.Scanner;
After importing the Scanner class you need to create a Scanner object. Next, choose a variable name for the Scanner object. Be sure to follow the rules for naming variables in Java.
Scanner input = new Scanner(System.in);
This Scanner object is named input, your name could be as descriptive as you like, following are some other examples. When we name objects and variables the name we give them is called an identifier.
Scanner userInput = new Scanner(System.in);
Scanner keyboardEntry = new Scanner(System.in);
You should not use single letters as identifiers, but rather descriptive names so that your code is easy to read and understand. This is for your benefit as well as for other programmers.
Output for Simple Adding Program
The output illustrates the prompts that our program provides for our user and the entries made by the user. Notice that the program gives the user a choice at the end of each addition task. The user can continue or terminate the program.