Hello World: Your First Step into Programming

Now you have set up your coding environment, so, welcome to the wonderful world of coding, dear explorer! Now, you’re about to embark on an exciting journey where simple lines of text can create magic.

So, let’s begin to create our first code, which is called “Hello World!”

What is “Hello World”?

“Hello World” is the traditional first program beginners write when learning a new programming language. It’s like saying “Hi!” to the computer world.

If you work right, when you run the “Hello World!”, you will see computer print Hello World!in your console.

Hello World!

This simple program that outputs those two magical words helps you test if your coding environment works, learn basic syntax quickly, and join a 50-year tradition (started in 1972!), then enter the world of programming!

Hello World in Different Languages

Now let’s look at the Hello World! in different languages

Python: The Friendly One

print('Hello World!')

Python keeps it super simple – just one line! The print() function does all the work.

C: The Classic

#include <stdio.h>
int main() {
    printf("Hello World!");
    return 0;
}

C requires more setup – you need the stdio.h library and a main() function. The semicolons show it’s serious business!

C++: The Object-Oriented Cousin

#include <iostream>
using namespace std;
int main() {
    cout << "Hello World!";
    return 0;
}

Notice cout instead of printf! The << operator sends your message to the output stream.

C#: The Microsoft Favorite

using System;
class Program {
    static void Main() {
        Console.WriteLine("Hello World!");
    }
}

C# uses Console.WriteLine and requires everything to be inside a class. Very organized!

Java: The Strict Performer

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!"); 
    }
}

Java insists on a class (with matching filename!) and the exact main method signature. Case-sensitive!

JavaScript: The Web Magician

console.log("Hello World!");

JavaScript runs in browsers. Open Developer Tools (F12) and paste this in the Console to see magic happen instantly!

发表评论