Ask Questions?

View Latest Questions

Advertisement


 
 

Console Output
Posted on: July 26, 2006 at 12:00 AM
You can write programs that write text lines to the "console", which is typically a DOS command window.

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 System class is automatically imported (as are all java.lang classes).
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. println comes from Pascal and is short for "print line". There is also a similar print method which writes output to the console, but doesn't start a new line after the output.
Copyleft 2005 Fred Swartz MIT License
Advertisement


DMCA.com