Writing “Hello, World!” in 10 Popular Programming LanguagesThe “Hello, World!” program is the traditional first step for anyone learning a new programming language. It’s intentionally simple — usually just enough code to display the phrase “Hello, World!” — but it introduces core language concepts: syntax, compilation or interpretation, basic input/output, and the minimal structure required to run code. Below are ten popular programming languages with example code, short explanations of the examples, platform notes, and quick tips to help you run each snippet.
1. C
#include <stdio.h> int main(void) { printf("Hello, World! "); return 0; }
C is a compiled, procedural language. This example includes the stdio header for printf, defines main as the entry point, prints the string with a newline, and returns 0 to indicate success. To run: save as hello.c, compile with gcc hello.c -o hello
, then ./hello
.
2. C++
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
C++ builds on C with standard library streams. std::cout
writes to standard output; std::endl
appends a newline and flushes the stream. Compile with g++ hello.cpp -o hello
, then ./hello
.
3. Java
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
Java requires a class and a main
method signature to start execution. Save as HelloWorld.java
, compile with javac HelloWorld.java
, then run with java HelloWorld
.
4. Python
print("Hello, World!")
Python is an interpreted, high-level language with concise syntax. Run with python hello.py
(or python3 hello.py
depending on your system).
5. JavaScript (Node.js)
console.log("Hello, World!");
JavaScript runs in browsers and on servers via Node.js. Save as hello.js
and run with node hello.js
. In browsers, you can run it in the console or include in an HTML page.
6. Ruby
puts "Hello, World!"
Ruby’s puts
prints the string followed by a newline. Run with ruby hello.rb
.
7. Go
package main import "fmt" func main() { fmt.Println("Hello, World!") }
Go is a compiled language with a simple toolchain. Save as hello.go
and run go run hello.go
or go build
and execute the binary.
8. Rust
fn main() { println!("Hello, World!"); }
Rust emphasizes safety and performance. Use rustc hello.rs
to compile or cargo run
in a Cargo project.
9. Kotlin
fun main() { println("Hello, World!") }
Kotlin runs on the JVM and can be used for Android development. Run with Kotlin compiler or within a Gradle project: kotlinc hello.kt -include-runtime -d hello.jar
then java -jar hello.jar
, or kotlin hello.kt
with the scripting support.
10. Swift
print("Hello, World!")
Swift is used for Apple platforms and server-side development. Run with swift hello.swift
or compile with swiftc hello.swift -o hello
then ./hello
.
Why “Hello, World!” Still Matters
- Introduces toolchain basics: compiling vs interpreting, building and running programs.
- Shows minimal syntax: what a file looks like in each language.
- Reveals language conventions: required imports, entry points, standard libraries.
- Good first test: confirms your environment is correctly configured.
Quick Comparison
Language | Paradigm | Typical Run Command |
---|---|---|
C | Procedural, compiled | gcc hello.c -o hello && ./hello |
C++ | Multi-paradigm, compiled | g++ hello.cpp -o hello && ./hello |
Java | OOP, compiled to bytecode | javac HelloWorld.java && java HelloWorld |
Python | Interpreted, high-level | python hello.py |
JavaScript (Node) | Event-driven, interpreted | node hello.js |
Ruby | Interpreted, high-level | ruby hello.rb |
Go | Compiled, concurrent | go run hello.go |
Rust | Compiled, systems | rustc hello.rs && ./hello |
Kotlin | JVM, modern | kotlinc … && java -jar hello.jar |
Swift | Compiled, modern | swift hello.swift |
Tips for Learners
- If a program fails to run, check the exact error message — it usually points to what’s missing (compiler, wrong filename, missing main signature).
- Use an online REPL for quick experimentation if installing toolchains feels heavy.
- After “Hello, World!”, try reading input, printing variables, and writing a small function — the next logical steps.
Happy coding.
Leave a Reply