Every Go executable starts with package main and a func main() entry point. Output uses the fmt package—similar to System.out.println in Java or print() in Python, but requires an explicit import.
Minimal program
package main
import "fmt"
func main() {
fmt.Println("Hello, World")
}
fmt.Println writes to stdout with a trailing newline. Use fmt.Print when you control line endings yourself.
Imports and formatting
Go requires imports for standard library packages. Unused imports are compile errors—delete them or use the value. go fmt standardizes indentation (tabs) and import grouping.
Important interview questions and answers
- Q: What prints text in Go?
A:fmt.Println,fmt.Printf, andfmt.Printfrom thefmtpackage. - Q: Can you run code without main?
A: Libraries usepackage somethingelse; onlypackage mainwithfunc main()builds an executable.
Self-check
- Which keyword declares the executable package?
- What happens if you import fmt but never use it?
Tip: Every executable needs package main and func main()—unlike Python scripts that run top-level statements without an entry point.
Interview prep
- What prints text?
fmt.Printlnandfmt.Printffrom the imported fmt package.- Entry point?
func main()inpackage main—required for executables.