Hello World!
An introduction to syntax, printing, and entry points.
The “Hello World!” program is the first step in learning how to code with any language. This tradition was first established in the 70s by Nokia Bell Labs and has since advanced into the famous first line of code that most programmers write. It is a program that prints the text “Hello World!” to some output stream, usually the console, and it’s primarily taught for three purposes:
  • To illustrate the basic syntax of a language
  • To check that you have correctly installed your computer language.
  • To teach printing
    • Printing is a handy tool because you can use it for debugging regardless of what language or IDE you are running
Here are some examples of how printing works:
Code:
print("Hello World!")
Output:
> Hello World!
Code:
System.out.println("Hello World!");
Output:
> Hello World!
Code:
cout << "Hello World!";
Output:
> Hello World!
Code:
print("Big thank you to all contributors to Hour of Code!")
Output:
> Big thank you to all contributors to Hour of Code!
Code:
System.out.println("Big thank you to all contributors to Hour of Code!");
Output:
> Big thank you to all contributors to Hour of Code!
Code:
cout << "Big thank you to all contributors to Hour of Code!";
Output:
> Big thank you to all contributors to Hour of Code!
Code:
print("I like to eat pizza!")
Output:
> I like to eat pizza!
Code:
System.out.println("I like to eat pizza!");
Output:
> I like to eat pizza!
Code:
cout << "I like to eat pizza!";
Output:
> I like to eat pizza!
Note: When you print text, everything between the quotation marks is printed to the output.
Entry points
Another important beginner concept is entry points. Entry points are where your program will begin to run. In Java and C++, the main function/method (you will learn more about functions and methods later) marks this entry point. That means to get the “Hello World!” examples from above to run in these languages, you will need to put your code inside the brackets after the main function/method. The entry points for getting our previous printing code to run are marked below; only code after the entry point will run.
Code:
public class HelloWorld{
    public static void main(String[] args)
    { 
        // THIS IS THE ENTRY POINT
        System.out.println("Hello World!");
    }
}
Output:
> Hello World!
Code:
#include <iostream>

using namespace std;

int main()
{ 
    // THIS IS THE ENTRY POINT
    cout << "Hello World!";
    return 0;
}
Output:
> Hello World!
Python is executed differently from Java and C++. It simply runs all code from the very first line to the very bottom line, and this means you don’t need to mark any entry points like in Java or C++. The same python code from before, copied below for convenience, will run fine.
Code:
print("Hello World!")
Output:
> Hello World!
Note: It’s possible to structure your code in Python to define an entry point that isn’t the first line, but it isn't necessary to get the code running. In Java and C++, you need to define an entry point, or your code will not run.
Many of the future articles won’t include marked entry points because they take a lot of space and don’t add much instructional value, but it’s essential to know that if you want to get code running on your computer, you will need to use entry points for Java and C++.
You can play with all the code we've used in this article on Replit:
Copyright ©2023 Howard County Hour of Code