Introduction and first 'Hello' to be GO-getter

Introduction and first 'Hello' to be GO-getter

Hey, everyone. In this #GO-getter series, I will share my Golang learning journey and will share everything that I am learning about GO.

As the official documentation GOes, the Go programming language is an open-source project to make programmers more productive. Unlike Java, which is processed through a compiler, and JVM is required to turn bytecode into machine code, GO is a complied language that compiles code into a single binary, does not need any machine to execute and can be run on different platforms (Ubuntu, macOS or Windows) consistently.

To work on GO, one needs to have GO installed in their local machine. You can head over to https://go.dev/doc/install, an official GO page and you will see a page like this:

Tab on the type of OS you have, and follow the instructions to download and install GO on your local machine. Once you have installed it, you can confirm it by typing "go version" in your command prompt. It will show a version you have installed and you are good to GO!

Let's start with the very first GO program. Open your favorite IDE. I'm using VS code as my editor as it provides the best language-supporting tools and other cool extensions. If you are also using VS code then download go extension by Team at Google which will give us the insights to write code correctly.

Make file hello.go and type the following code for the first "Hello Wolrd" program in GO. As per the syntax if you write like this:

In Go, everything lies in the package. So we must declare the package at the top. As we are using Print function to print statements in the console which is coming from "fmt" package, we must import it to make it available locally in the file.

As I am coming from Java, quite familiar with the main method which is entry point of any Java application, Go also has a main function that must be declared to execute the file. Every Go application must contain a single main package and main() method to make it executable. "fmt" package is one of the many built-in packages provided by Golang for different functionality. These packages contain methods which can be used by referencing the package itself like "fmt.Print()".

To run Go program you need to type go run "filename" as shown below:

It will print our typed statement as shown in the terminal. Print function does not create any new line after printing. We can use Println function (similar to System.out.println in Java) from the same "fmt" package to print the new line at the end. You can refer all the functions provided by "fmt" package here https://pkg.go.dev/fmt#hdr-Scanning.

With this, we created our first Golang program. Many more concepts to learn in the upcoming blogs. See you in the next one, till then Happy Learning.