GoLang: The customary 'Hello, World' program

When you start learning a new language, usually it is customary to write a 'Hello, World' program. The advantage is that is ensure that the development environment is all set to start authoring more programs.

The below program prints "Hello, World" on the display screen.

Download the Golang compiler from here depending on your system.

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

In the above code, note the following:

  • The first statement declares a "main" package.

  • The second statement imports a standard package called "fmt" which contains methods to read/write to the console and also format text.

  • Then a method called "main" is implement which prints the text to the console. The main method is executed by default when the "main" package is run.

Now it is time to compile and run the program. If you are using Visual Studio Code, the terminal is in the same window. If you are using any other editors, you can always use your favorite command shell.

And at the terminal, run the program with the below command (considering the above code is saved in a file named 'helloworld.go'

go run helloworld.go

The output is as below: