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, but you will see it used.
1 2 3 4 5 6 7 8 9 10 |
// introductory/ConsoleOutput.java // Michael Maus, 25 August 2004 // This program shows a message on the console. public class ConsoleOutput { public static void main(String[] args) { System.out.println("Hello, Earthling"); } } |
System
class is automatically imported (as are all java.lang
classes).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.
System.exit(0);at the end if you wish.