On voit ici comment afficher une chaîne dans différents langages.
Le code source des exemples se trouve dans exemples/intro/helloworld/.
Voir aussi La page Hello world de java.
Pour faire fonctionner ces exemples :
Le code source des exemples se trouve dans exemples/intro/helloworld/.
Voir aussi La page Hello world de java.
# depuis la racine du cours : cd exemples/intro/helloworld/
python
HelloWorld.py :
print "Hello World!"Exécution :
python HelloWorld.py
java
HelloWorld.java :
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Compilation :
javac HelloWorld.javaGénère un fichier
HelloWorld.class
Exécution :
java HelloWorldNettoyage :
rm HelloWorld.class
php
HelloWorld.php :
<?php echo "Hello World!\n";Exécution :
php HelloWorld.php
go
HelloWorld.go :
package main
import "fmt"
func main(){
fmt.Println("Hello World!")
}
Exécution :
go run HelloWorld.go
rust
HelloWorld.rs
fn main() {
println!("Hello World!");
}
Compilation :
rustc HelloWorld.rsGénère un fichier exécutable
HelloWorld
Exécution :
./HelloWorldNettoyage :
rm HelloWorld
haskell
HelloWorld.hs :
main = putStrLn "Hello, World!"Compilation :
ghc HelloWorld.hsGénère un fichier exécutable
HelloWorld et 2 fichiers auxiliaires : HelloWorld.hi et HelloWorld.o.
Exécution :
./HelloWorldNettoyage :
rm HelloWorld HelloWorld.{hi,o}
ocaml
HelloWorld.ml :
print_string "Hello world!\n";;Compilation :
ocamlc -o HelloWorld HelloWorld.mlGénère un fichier exécutable
HelloWorld et 2 fichiers auxiliaires : HelloWorld.cmi et HelloWorld.cmo.
Exécution :
./HelloWorldNettoyage :
rm HelloWorld HelloWorld.{cmi,cmo}
prolog
HelloWorld.pl :
:- initialization hello_world, halt.
hello_world :-
write('Hello, World!'), nl.
Exécution :
swipl -l HelloWorld.pl
bash
Si vous êtes sous bash, vous pouvez directement faire en ligne de commande :echo "Hello World!"Ou mettre ce code dans un fichier
HelloWorld.sh et exécuter :
bash HelloWorld.shOu rendre
HelloWorld.sh exécutable :
chmod +x HelloWorld.shet l'exécuter :
./HelloWorld.sh