'Hello World!' - Programming Tradition
Created | Updated Jul 28, 2009
Since the 1970s, it has become customary when learning a new programming language or testing an unfamiliar programming environment to write a 'Hello world!' program with which to do so. This is a program that, quite simply, displays the words 'Hello world!' as output on the computer screen1. Although, due to the syntax of some languages, a 'Hello world!' program can sometimes appear quite complex, it's generally regarded as the simplest type of program that can be executed in a given language.
History
The first recorded appearance of 'Hello world!' in a programming example was in 1972, in A Tutorial Introduction to the Language B by BW Kernighan. B was a precursor to the longer lasting and better known language C. Kernighan used the following example to illustrate a point about 'external variables':
main( ) { extrn a, b, c; putchar(a); putchar(b); putchar(c); putchar('!*n'); } a 'hell'; b 'o, w'; c 'orld';This was just an isolated example. Kernighan could've just as easily used 'look, a bus!'2 to illustrate his point and no-one would have noticed. However, in 1978, Kernighan and co-author Dennis Ritchie wrote a book called The C Programming Language, still considered to be the authoritative reference on the language behind the UNIX operating system, among other things. In the very first section of the book, Kernighan and Ritchie used 'Hello world!' to explain how to write, compile and run a C program:
main() { printf("hello, world\n"); }The C Programming Language was considered such a good example of technical writing that its style was emulated by successive authors of programming manuals. Many imitated Kernighan and Ritchie's use of 'Hello world!' as an initial sample program. It's become a handy tool. As The C Programming Language demonstrated, a program that's very straightforward logically and does only one basic thing can then be used to teach someone how to use the language's syntax and other components such as its compiler.
Today, variants of 'Hello world!' are in use in just about every introduction to programming, whether in a book, website or classroom. 'Hello world!' is often the source of computer geek jokes and cultural references. Unless the computing world suddenly decides to convert to 'look, a bus!', there's every reason to believe 'Hello world!' will be around for years to come.
Examples
What follows are some examples of 'Hello world!' in a few common programming languages. This is only a minuscule sampling of the range of 'Hello world!'.
BASIC
10 PRINT "Hello world!"C (as mentioned above)
main() { printf("hello, world\n"); }C++
main() { cout << "Hello world!" << endl; return 0; }HTML
<HTML> <BODY> Hello world! </BODY> </HTML>Java
class HelloWorld { public static void main(String args[]) { System.out.println("Hello world!"); } }Javascript
<html> <body> <script language="JavaScript" type="text/javascript"> document.write('Hello world!'); </script> </body> </html>PHP
<?php echo 'Hello world!'; ?>Python
print "Hello world!"UNIX Shell
echo 'Hello world!'And, of course...