Java Notes
Console Output
You can write programs that write text lines to the "console", which is typically a DOS command window. This is not as interesting as a Graphical User Interface (GUI), but you will see it used. It doesn't work nicely for applets, WebStart, and normal GUI programs. If you're looking for simple input/output, use dialog boxes (see Dialog Box Output).
1 2 3 4 5 6 7 8 9 10 11 |
// File : introductory/ConsoleOutput.java
// Purpose: This program shows a message on the console.
// Author : Michael Maus
// Date : 29 March 2005
public class ConsoleOutput {
public static void main(String[] args) {
System.out.println("Hello, Earthling");
}
}
|
- No imports are required
- The
Systemclass is automatically imported (as are alljava.langclasses). - Line 9 - Write the output
- You can write one complete output line to the console by calling
the
System.out.println()method. The argument to this method will be printed.printlncomes from Pascal and is short for "print line". There is also a similarprintmethod which writes output to the console, but doesn't start a new line after the output.