Hello, World! Program in Ballerina

Ayesh Almeida
2 min readMay 9, 2021

--

In my previous article I have given a small introduction to Ballerina Language. In this article we would be writing a simple Hello World program in Ballerina.

Hello World program is the first step we take in every programming language. The intention is to print Hello, World! into the command line.

Open your favorite editor (vim, notepad, notepad++) and create a file named hello_world.bal with following code.

You can compile and run the program using following command.

$ bal run hello_world.bal

You would get following output.

Hello, World!

Line #1

First line is an import statement in Ballerina. Other than the basic language features, all the functionalities are delegated into Ballerina Standard Library Modules.

Ballerina IO Package allows you to read and write from console or file. Since we are printing Hello, World! to the console we need to import ballerina/io module to our application.

Line #3

This line contains a single-line comment and hence ignored by Ballerina Compiler. Comments are added to an application program to communicate the intention of the program to an other developer.

Ballerina supports two types of comments.

  1. Single Line Comments
  2. Doc Comments

Line #4

As all modern programming languages main() function is the entry-point for Ballerina Program.

main function can have arguments of type string[] or string....

is equivalent to;

Line #5

The fifth line is a statement and it prints Hello, World! to the console. And since this functionality is available in Ballerina IO Module we have to invoke the function with the module name.

Ballerina has syntax of C / C++ family and hence the semicolon is required for every statement.

Ballerina has its own unique way of doing the things and it is quite the same as in most C / C++ family languages.

--

--

Ayesh Almeida
Ayesh Almeida

Written by Ayesh Almeida

A Tech Enthusiast who wants to build simple solutions for complex problems.

No responses yet