La syntaxe et les éléments de bases de java - Technologue pro
La syntaxe et les éléments de bases de java - Technologue pro
La syntaxe et les éléments de bases de java - Technologue pro
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Mlle Imene Sghaier<br />
ISETN<br />
double w = 1.1;<br />
Attention : float pi = 3.141; // erreur à la compilation<br />
• Le format <strong>de</strong>s caractères<br />
Un caractère est codé sur 16 bis car il est conforme à la norme Unico<strong>de</strong>. Il doit être entouré par<br />
<strong>de</strong>s apostrophes. Une valeur <strong>de</strong> type char peut être considérée comme un entier non négatif <strong>de</strong> 0 à<br />
65535. Cependant la conversion implicite par affectation n'est pas possible.<br />
Exemple :<br />
/* test sur <strong>les</strong> caractères */<br />
class test1 {<br />
public static void main (String args[]) {<br />
char co<strong>de</strong> = 'D';<br />
int in<strong>de</strong>x = co<strong>de</strong> - 'A';<br />
System.out.println("in<strong>de</strong>x = " + in<strong>de</strong>x);<br />
}<br />
}<br />
4.4. L'initialisation <strong>de</strong>s variab<strong>les</strong><br />
Exemple :<br />
int nombre; // déclaration<br />
nombre = 100; //initialisation<br />
OU int nombre = 100; //déclaration <strong>et</strong> initialisation<br />
En <strong>java</strong>, toute variable appartenant à un obj<strong>et</strong> (définie comme étant un attribut <strong>de</strong> l'obj<strong>et</strong>) est<br />
initialisée avec une valeur par défaut en accord avec son type au moment <strong>de</strong> la création. C<strong>et</strong>te<br />
initialisation ne s'applique pas aux variab<strong>les</strong> loca<strong>les</strong> <strong>de</strong>s métho<strong>de</strong>s <strong>de</strong> la classe.<br />
Les valeurs par défaut lors <strong>de</strong> l'initialisation automatique <strong>de</strong>s variab<strong>les</strong> d'instances sont :<br />
Remarque : Dans une appl<strong>et</strong>, il est préférable <strong>de</strong> faire <strong>les</strong> déclarations <strong>et</strong> <strong>les</strong> initialisations dans<br />
la métho<strong>de</strong> init().<br />
Support <strong>de</strong> langage Java 2006-2007