LANGAGE DE PROGRAMMATION JAVA - NOTES DE COURS
1. Introduction a Java
- Java est un langage :
* Oriente objet
* Fortement type
* Portable (grâce a la JVM)
* Securise
- JVM (Java Virtual Machine) : execute le bytecode Java
- JDK (Java Development Kit) : permet de compiler et executer du Java
2. Structure de base d'un programme Java
public class Main {
public static void main(String[] args) {
[Link]("Bonjour, Java !");
}
}
3. Types de donnees
- Types primitifs : int, double, char, boolean
- Types objets : String, Array, Scanner, etc.
4. Variables et operateurs
- Declaration : int age = 25;
- Operateurs : +, -, *, /, %, ==, !=, >, <, &&, ||
5. Structures de contrôle
- Conditionnelles : if, else
- Boucles : for, while, do...while
6. Tableaux
int[] notes = {12, 15, 17};
[Link](notes[0]);
7. Programmation orientee objet (POO)
- Concepts : classe, objet, encapsulation, heritage, polymorphisme
- Exemple :
public class Etudiant {
String nom;
int age;
public Etudiant(String n, int a) {
nom = n;
age = a;
}
public void afficher() {
[Link](nom + " a " + age + " ans");
}
}
8. Methodes et surcharge
public int addition(int a, int b) {
return a + b;
}
9. Heritage
class Animal {
void parler() {
[Link]("Je suis un animal");
}
}
class Chien extends Animal {
void parler() {
[Link]("Ouaf !");
}
}
10. Interface et classe abstraite
interface Volant {
void voler();
}
abstract class Animal {
abstract void crier();
}
11. Exceptions
try {
int x = 5 / 0;
} catch (ArithmeticException e) {
[Link]("Erreur : " + [Link]());
} finally {
[Link]("Bloc finally execute");
}
12. Entrees/Sorties (I/O)
import [Link];
Scanner sc = new Scanner([Link]);
[Link]("Entrez un nombre : ");
int n = [Link]();
13. Collections
ArrayList<String> noms = new ArrayList<>();
[Link]("Alice");
HashMap<String, Integer> notes = new HashMap<>();
[Link]("Alice", 15);
14. Recapitulatif - mots-cles utiles
public, private, static, this, new, final, extends, implements