Fournir un langage simple et objet pour la plate-forme Java.
Le langage source à compiler pour générer un code exécutable (bytecode) par une JVM peut être :
| Version | Java | Commentaire | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Release | 1 | ||||||||||
| Domaine | Technologie | Fix | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
| Exécution | Interpréteur | Non | |||||||||
| VM | Oui | JVM | |||||||||
| Machine | Non | ||||||||||
| Compilation | Préprocesseur | Non | |||||||||
| Structures de contrôle | Condition | <strong>if</strong> () { } |
|||||||||
| Cas | <strong>switch</strong> () { x: <strong>break</strong>; } |
||||||||||
| Boucle | Itération | <strong>for</strong> (init; while; increment) { } |
|||||||||
| Un au moins | <strong>do</strong> { } <strong>while</strong> |
||||||||||
| Tant que | <strong>while</strong> () { } |
||||||||||
| Suite | <strong>continue</strong> |
||||||||||
| Stop | <strong>break</strong> |
||||||||||
| Gestion des erreurs | Exceptions | Oui | |||||||||
| OO | Héritage | Simple | Oui | ||||||||
| Multiple | Non | ||||||||||
| Types | Classes | Internes | Non | Oui | |||||||
| Collections | Iteration | Iterator it = col.iterator(); Object o = it.next(); |
<strong>for</strong> (Object o : col) |
||||||||
| Constantes | Déclaration | <strong>final</strong> |
|||||||||
| Import | Non | <strong>import</strong> <strong>static</strong> package.Class.*; |
|||||||||
| Enumérations | Non | <strong>enum</strong> MonEnum { val1, val2, val3 } |
|||||||||
| Numériques | Entiers | <strong>byte</strong>, <strong>short</strong>, <strong>int</strong>,
<strong>long</strong>
|
|||||||||
| Flottants | <strong>float</strong> |
||||||||||
| Caractères | Unique | <strong>char</strong> |
|||||||||
| Chaîne | <strong>String</strong> |
||||||||||
| Génériques | Types | Non | <strong>Classe<</strong>Type<strong>></strong> |
||||||||
| Méthodes | Non | <strong><</strong>Type<strong>> void
methode(</strong><Type><strong>)</strong> |
|||||||||
| Enregistrements | Classe | Structs/record | |||||||||
| Robustesse et mise au point | Contrôle des conversions | Oui | |||||||||
| Contrôle des limites de tableau | Oui | ||||||||||
| Contrôle division par zéro | Oui | ||||||||||
| Assertions | Non | <strong>assert</strong> booleanCondition : message; |
|||||||||
| Gestion mémoire | Automatique | GC | Pointeurs évités volontairement pour plus de robustesse. | ||||||||
Un exemple de code Java est :
<strong>public class</strong> MonApplication <strong>{</strong><br> <strong>public static
void</strong> main <strong>(</strong>String<strong>[]</strong> someArgs<strong>) {<br> if
(</strong>someArgs<strong></strong>.length <strong> > </strong>0<strong>)</strong><br> System.out.println
<strong>(<span class="codeString">"</span></strong><span class="codeString">Hello
"</span> + someArgs<strong></strong>[0]<strong>);</strong><br> <strong> else</strong><br> System.out.println
<strong>(<span class="codeString">"</span></strong><span class="codeString">Hello
world !<strong>"</strong></span><strong>);<br> } <br> }</strong>