Académique Documents
Professionnel Documents
Culture Documents
Introduction
Plan
1 Vue générale
La technologie Java
Le langage Java
La machine virtuelle Java
Résumé
2 Hello World
Prérequis
Premier programme : 3 étapes
Résumé
3 HelloWorld en détail
Les commentaires
Définition d’une classe
La méthode main
Le code
Résumé
Cours Java - F. Michel
2 / 25
Vue générale Hello World HelloWorld en détail Résumé global
La technologie Java
Origine
Sun microsystems, ≈ 1995 Java sur Wikipédia
Le langage Java
Principales caractéristiques
Simple, Object Oriented, and Familiar
Robust and Secure
Architecture Neutral and Portable (JVM)
High Performance
Interpreted, Threaded, and Dynamic
La plate-forme Java
Le langage Java
Pour résumer
Prérequis
Pour pouvoir écrire un programme Java il faut au moins :
OpenJDK : openjdk.java.net/
un éditeur de texte
1. Codage
Création du fichier source HelloWorldApp.java
2. Compilation
Compilation du fichier source HelloWorldApp.java en
HelloWorldApp.class
3. Exécution
Utilisation de la JVM locale pour exécuter le fichier
HelloWorldApp.class
HelloWorldApp.java
/* *
* The HelloWorldApp c l a s s implements an a p p l i c a t i o n t h a t
* s i m p l y p r i n t s " H e l l o World ! " t o s t a n d a r d o u t p u t .
*/
p u b l i c c l a s s HelloWorldApp {
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] args ) {
System . o u t . p r i n t l n ( " H e l l o World ! " ) ; / / D i s p l a y t h e s t r i n g .
}
}
Dans un terminal
jo e@i ut : ~ $ j a v a c HelloWorldApp . j a v a
jo e@i ut : ~ $ l s
HelloWorldApp . c l a s s HelloWorldApp . j a v a
jo e@i ut : ~ $
Windows
propriétés du poste de travail → avancé → variables
d’environnement (nouveau)
PATH= blabla ; c :\JDKInstalDirectory \bin
Cours Java - F. Michel
16 / 25
Vue générale Hello World HelloWorld en détail Résumé global
Dans un terminal
joe@i ut : ~ $ j a v a HelloWorldApp
H e l l o World !
joe@i ut : ~ $
Pour résumer
HelloWorldApp.java en détail
Les commentaires
/* *
* The HelloWorldApp c l a s s implements an a p p l i c a t i o n t h a t
* s i m p l y p r i n t s " H e l l o World ! " t o s t a n d a r d o u t p u t .
*/
HelloWorldApp.java en détail
HelloWorldApp.java en détail
La méthode statique main
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] args ) {
System . o u t . p r i n t l n ( " H e l l o World ! " ) ; / / D i s p l a y t h e s t r i n g .
}
HelloWorldApp.java en détail
Le code
System . o u t . p r i n t l n ( " H e l l o World ! " ) ; / / Display the s t r i n g .
Pour résumer
Il faut au moins définir une classe.
La méthode main est le point d’entrée du programme.
l’API fournit en standard de très nombreuses fonctionnalités.
HelloWorldApp.java
/* *
* The HelloWorldApp c l a s s implements an a p p l i c a t i o n t h a t
* s i m p l y p r i n t s " H e l l o World ! " t o s t a n d a r d o u t p u t .
*/
p u b l i c c l a s s HelloWorldApp {
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] args ) {
System . o u t . p r i n t l n ( " H e l l o World ! " ) ; / / D i s p l a y t h e s t r i n g .
}
}
Résumé global
La technologie Java :
un langage de programmation orienté objet
The Java language Specification