Learning to write hello world is the first step to getting started in every programming language. Let’s take a look at the hello world implementation of major programming languages.
1.Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!\n");
}
}
2.C
Create a new file hello.c, the code is as follows:
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
Compile hello.c
gcc -o hello hello.c or clang -o hello hello.c
Execute ./hello
3.C++
Create a new file hello.cpp, the code is as follows:
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]){
cout << "Hello World!" << endl;
return 0;
}
Compile hello.cpp
gcc -o hello hello.cpp or clang++ -o hello hello.cpp
Execute ./hello
4.Python
Create a new file hello.py, the code is as follows:
print("Hello World!")
Execute python hello.py
5.Golang
Create a new file hello.go with the following code:
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
Compile go build hello.go
Execute ./hello
6. Assembly
Create a new file hello.asm, the code is as follows:
section .data
msge db "Hello World!",0ah
len equ $-msge
global _start
_start:
mov eax,4 ; call number 4
mov ebx,1 ; ebx sends 1 to indicate output
mov ecx,msge ; The first address of the string is sent to ecx
mov edx,$len; The length of the string is sent to edx
int 80h; output string
mov eax,1; call number 1
mov ebx,0;
int 80h ; end
linux x86_64 compilation: nasm -f elf64 hello.asm connect ld -o hello hello.o
Execute ./hello
7.Rust
Create a new file hello.rs, the code is as follows:
fn main() {
println!("Hello World!");
}
Compile rustc hello.rs
Execute ./hello
8.Lua
Create a new file hello.lua, the code is as follows:
print("Hello World!")
Execute lua hello.lua
9.Perl
Create a new file hello.pl, the code is as follows:
print "Hello World!\n";
Execute perl hello.pl
10.Ruby
Create a new file hello.rb, the code is as follows:
puts "Hello, World!"
Execute ruby hello.rb
11.Nim
Create a new file hello.nim, the code is as follows:
echo "Hello World!"
Compile nim c hello.nim
Execute ./hello
12.Javascript
<script type="text/javascript">
document.write("Hello World!");
</script>