• Aucun résultat trouvé

Environnement et langages évolués

N/A
N/A
Protected

Academic year: 2022

Partager "Environnement et langages évolués"

Copied!
344
0
0

Texte intégral

(1)

Environnement et langages évolués

Christophe Fouqueré

Master Informatique 2ème année christophe.fouquere@univ-paris13.fr

A204, Université de Paris 13

(2)

Bibliographie (très) partielle :

Java La synthèse, Des concepts objet aux

architectures Web, Clavel et alii, Dunod Informatiques, 2000

Programmation réseau avec Java, E. Rusty Harold, O’Reilly, 2001

XHTML, I. Graham, Eyrolles, 2001

EJB fondamental, Ed Roman, S. Ambler, T. Jewel, Eyrolles, 2002

EJB Patterns, D. Alur, J. Crupi, D. Malks, Prentice Hall, 2008

et bien sûr http://docs.oracle.com en particulier http:

//docs.oracle.com/javase/{6,7,8}/docs/api/

et http://docs.oracle.com/javaee/7/api/

2 / 289

(3)

Objectifs du cours :

Usage d’environnements de développements (Eclipse, Netbeans) : apprentissage en TP

Compréhension des pratiques logicielles en environnement ouvert

Cas des sites web et services web : mécanismes sous-jacents et mise en oeuvre pratique

Quelques frameworks

Questions liées à la sécurité (typage, ...)

(4)

Plan de cours

1

rappels Java

2

EJB/J2EE

3

Hibernate

4

JSF

5

Struts

6

Spring

(Devoir ou) Exposé : JUnit

Maven Ant Git / Svn Ruby on Rails framework php Dot-net

C#

...

4 / 289

(5)

1

Java

(6)

Java : la base !

Java : Une classe = structure + méthodes

6 / 289

(7)

package test;

import java.util.*;

public class Personne { private String nom;

protected List<String> prenoms;

public transient String societe;

private static final String societeException

= new String("inconnu");

public boolean defini;

public void identifiant() {System.out.println

("je m’appelle" + nom);}

Personne(Object o) {

if (o instanceof String) {this.nom = (String) o;}

}

public static void main(String args[]) { Personne p = new Personne("zz");

assert p.nom == "t": "erreur de creation";

} }

$ ls test Personne.java

$ javac test/Personne.java

$ java test.Personne

$ java -ea test.Personne

Exception in thread "main" java.lang.AssertionError:

erreur de creation

at test.Personne.main(Personne.java:25)

(8)

package test;

import java.util.*;

public class Personne { private String nom;

protected List<String> prenoms;

public transient String societe;

private static final String societeException

= new String("inconnu");

public boolean defini;

public void identifiant() {System.out.println

("je m’appelle" + nom);}

Personne(Object o) {

if (o instanceof String) {this.nom = (String) o;}

}

public static void main(String args[]) { Personne p = new Personne("zz");

assert p.nom == "t": "erreur de creation";

} }

$ ls test Personne.java

$ javac test/Personne.java

$ java test.Personne

$ java -ea test.Personne

Exception in thread "main" java.lang.AssertionError:

erreur de creation

at test.Personne.main(Personne.java:25) définition de classe

(convention: début majuscule)

constructeur de classe (donc pas de construc- teur vide)

nom du paquetage (donc test.Personne)

importation de classes

7 / 289

(9)

package test;

import java.util.*;

public class Personne { private String nom;

protected List<String> prenoms;

public transient String societe;

private static final String societeException

= new String("inconnu");

public boolean defini;

public void identifiant() {System.out.println

("je m’appelle" + nom);}

Personne(Object o) {

if (o instanceof String) {this.nom = (String) o;}

}

public static void main(String args[]) { Personne p = new Personne("zz");

assert p.nom == "t": "erreur de creation";

} }

$ ls test Personne.java

$ javac test/Personne.java

$ java test.Personne

$ java -ea test.Personne

Exception in thread "main" java.lang.AssertionError:

erreur de creation

at test.Personne.main(Personne.java:25) utilisable localement

utilisable globalement

utilisable par héritage

(10)

package test;

import java.util.*;

public class Personne { private String nom;

protected List<String> prenoms;

public transient String societe;

private static final String societeException

= new String("inconnu");

public boolean defini;

public void identifiant() {System.out.println

("je m’appelle" + nom);}

Personne(Object o) {

if (o instanceof String) {this.nom = (String) o;}

}

public static void main(String args[]) { Personne p = new Personne("zz");

assert p.nom == "t": "erreur de creation";

} }

$ ls test Personne.java

$ javac test/Personne.java

$ java test.Personne

$ java -ea test.Personne

Exception in thread "main" java.lang.AssertionError:

erreur de creation

at test.Personne.main(Personne.java:25) non modifiable après instanciation

variable de classe non sérialisable

test d’instance

7 / 289

(11)

package test;

import java.util.*;

public class Personne { private String nom;

protected List<String> prenoms;

public transient String societe;

private static final String societeException

= new String("inconnu");

public boolean defini;

public void identifiant() {System.out.println

("je m’appelle" + nom);}

Personne(Object o) {

if (o instanceof String) {this.nom = (String) o;}

}

public static void main(String args[]) { Personne p = new Personne("zz");

assert p.nom == "t": "erreur de creation";

} }

$ ls test Personne.java

$ javac test/Personne.java

$ java test.Personne

$ java -ea test.Personne

Exception in thread "main" java.lang.AssertionError:

erreur de creation

at test.Personne.main(Personne.java:25) méthode principale pour un pro-

gramme

type primitif (comme byte, char, double, float, int, long, short)

type paramétré

assertion / excep- tion

(12)

Java : Rappels : interfaces

public interface DigestListener { public void setDigest(byte[] digest);

}

import java.io.*;

public class DigestServer implements DigestListener { ...

public void setDigest(byte[] digest) { ...

} ...

}

8 / 289

(13)

Java : Rappels : interfaces

public interface DigestListener { public void setDigest(byte[] digest);

}

interface = signa- ture de (partie de) classe

import java.io.*;

public class DigestServer implements DigestListener { ...

public void setDigest(byte[] digest) { ...

} ...

}

classe implantant les méthodes de l’interface

(14)

Java : Rappels : classes abstraites et extensions abstract class Triangle {

int[] cotes = new int[3];

abstract double surface();

public String toString(){

return "Triangle de cotés " + cotes[0] + ", "

+ cotes[1] + ", " + cotes[2]

+ " et de surface " + surface();

} }

public class Isocele extends Triangle { double surface(){

return (cotes[0]

*java.lang.Math.sqrt(cotes[1]*cotes[1]

-cotes[0]*cotes[0]/4)/2);

}

Isocele(int a, int b, int c) {

cotes[0] = a; cotes[1] = b; cotes[2] = c;

}

public static void main(String args[]) { Triangle t = new Isocele(2,3,3);

System.out.println(t);

} }

9 / 289

(15)

Java : Rappels : classes abstraites et extensions abstract class Triangle {

int[] cotes = new int[3];

abstract double surface();

public String toString(){

return "Triangle de cotés " + cotes[0] + ", "

+ cotes[1] + ", " + cotes[2]

+ " et de surface " + surface();

} }

public class Isocele extends Triangle { double surface(){

return (cotes[0]

*java.lang.Math.sqrt(cotes[1]*cotes[1]

-cotes[0]*cotes[0]/4)/2);

}

Isocele(int a, int b, int c) {

cotes[0] = a; cotes[1] = b; cotes[2] = c;

}

public static void main(String args[]) { Triangle t = new Isocele(2,3,3);

System.out.println(t);

} }

classe abstraite, méthode abstraite

extension de classe

(16)

Java : Rappels : classes abstraites et extensions abstract class Triangle {

int[] cotes = new int[3];

abstract double surface();

public String toString(){

return "Triangle de cotés " + cotes[0] + ", "

+ cotes[1] + ", " + cotes[2]

+ " et de surface " + surface();

} }

public class Isocele extends Triangle { double surface(){

return (cotes[0]

*java.lang.Math.sqrt(cotes[1]*cotes[1]

-cotes[0]*cotes[0]/4)/2);

}

Isocele(int a, int b, int c) {

cotes[0] = a; cotes[1] = b; cotes[2] = c;

}

public static void main(String args[]) { Triangle t = new Isocele(2,3,3);

System.out.println(t);

} }

surcharge de méthode

9 / 289

(17)

Java : Rappels : gestion des exceptions

class ExpandableArray { protected Object[] data;

protected int size = 0;

public ExpandableArray(int cap) {data = new Object[cap];}

public int size() { return size;}

public Object get(int i) throws NoSuchElementException { if (i<0 || i>= size) throw new NoSuchElementException();

return data[i];

}

public void add(Object x) { if (size == data.length) {

Object[] olddata = data;

data = new Object[3 * (size + 1) / 2];

System.arraycopy( olddata, 0, data, 0, olddata.length);

}

data[size++] = x;

} }

class NoSuchElementException extends Exception {};

(18)

Java : Rappels : gestion des exceptions

class ExpandableArray { protected Object[] data;

protected int size = 0;

public ExpandableArray(int cap) {data = new Object[cap];}

public int size() { return size;}

public Object get(int i) throws NoSuchElementException { if (i<0 || i>= size) throw new NoSuchElementException();

return data[i];

}

public void add(Object x) { if (size == data.length) {

Object[] olddata = data;

data = new Object[3 * (size + 1) / 2];

System.arraycopy( olddata, 0, data, 0, olddata.length);

}

data[size++] = x;

} }

class NoSuchElementException extends Exception {};

pose et traitement externe

10 / 289

(19)

import java.io.*; import java.net.Socket;

public class Main {

public static void main(String[] args) { Socket connexion = null;

try {

connexion = new Socket("www.univ-paris13.fr",80);

Writer output = new OutputStreamWriter

(connexion.getOutputStream(), "8859_1");

output.write("GET / HTTP 1.0\r\n\r\n"); output.flush();

BufferedReader input = new BufferedReader(

new InputStreamReader

(connexion.getInputStream(),"8859_1"),1024);

StringBuffer sb = new StringBuffer(); int c;

while ((c = input.read()) != -1) sb.append((char) c);

System.out.println(sb);

}

catch (IOException e) {System.out.println(e);}

finally {

try {if (connexion != null) connexion.close();}

catch (IOException e) {System.out.println(e);}

} } }

(20)

import java.io.*; import java.net.Socket;

public class Main {

public static void main(String[] args) { Socket connexion = null;

try {

connexion = new Socket("www.univ-paris13.fr",80);

Writer output = new OutputStreamWriter

(connexion.getOutputStream(), "8859_1");

output.write("GET / HTTP 1.0\r\n\r\n"); output.flush();

BufferedReader input = new BufferedReader(

new InputStreamReader

(connexion.getInputStream(),"8859_1"),1024);

StringBuffer sb = new StringBuffer(); int c;

while ((c = input.read()) != -1) sb.append((char) c);

System.out.println(sb);

}

catch (IOException e) {System.out.println(e);}

finally {

try {if (connexion != null) connexion.close();}

catch (IOException e) {System.out.println(e);}

} } }

test et traitement local

11 / 289

(21)

Java : Rappels : les threads

class T implements Runnable{

public void run() {

for (int i = 0; i<5; i++) {

System.out.println("Processus léger T" + i);

try { Thread.sleep(500);} // 500 msec = 1/2 s catch (InterruptedException e) {

System.out.println("Interruption");

} }

System.out.println("Processus léger T terminé");

} }

public class TTest{

public static void main(String[] args) throws Exception { Thread t = new Thread(new T());

t.start();

for (int i = 0; i<5; i++) {

System.out.println("Processus léger main" + i);

Thread.sleep(500);

}

System.out.println("Processus léger main terminé");

} }

(22)

Java : Rappels : les threads

class T implements Runnable{

public void run() {

for (int i = 0; i<5; i++) {

System.out.println("Processus léger T" + i);

try { Thread.sleep(500);} // 500 msec = 1/2 s catch (InterruptedException e) {

System.out.println("Interruption");

} }

System.out.println("Processus léger T terminé");

} }

public class TTest{

public static void main(String[] args) throws Exception { Thread t = new Thread(new T());

t.start();

for (int i = 0; i<5; i++) {

System.out.println("Processus léger main" + i);

Thread.sleep(500);

}

System.out.println("Processus léger main terminé");

} }

interface nécessaire méthode obligatoire

création du thread

12 / 289

(23)

Java : Rappels : les threads

class T implements Runnable{

public void run() {

for (int i = 0; i<5; i++) {

System.out.println("Processus léger T" + i);

try { Thread.sleep(500);} // 500 msec = 1/2 s catch (InterruptedException e) {

System.out.println("Interruption");

} }

System.out.println("Processus léger T terminé");

} }

public class TTest{

public static void main(String[] args) throws Exception { Thread t = new Thread(new T());

t.start();

for (int i = 0; i<5; i++) {

System.out.println("Processus léger main" + i);

Thread.sleep(500);

}

System.out.println("Processus léger main terminé");

} }

exécution du thread

(24)

Java : Rappels : socket client

import java.io.*; import java.net.Socket;

public class Main {

public static void main(String[] args) { Socket cnx = null;

try {

cnx = new Socket("www.univ-paris13.fr",80);

Writer output = new OutputStreamWriter(

cnx.getOutputStream(), "8859_1");

output.write("GET / HTTP 1.0\r\n\r\n"); output.flush();

cnx.shutdownOutput(); // fermeture partielle BufferedReader input = // flux en lecture

new BufferedReader(

new InputStreamReader(cnx.getInputStream(),"8859_1"),1024);

StringBuffer sb = new StringBuffer(); int c;

while ((c = input.read()) != -1) sb.append((char) c);

System.out.println(sb);

} catch (IOException e) {System.out.println(e);}

finally {

try {if (connexion != null) connexion.close();}

catch (IOException e) {System.out.println(e);}

} } }

13 / 289

(25)

Java : Rappels : socket client

import java.io.*; import java.net.Socket;

public class Main {

public static void main(String[] args) { Socket cnx = null;

try {

cnx = new Socket("www.univ-paris13.fr",80);

Writer output = new OutputStreamWriter(

cnx.getOutputStream(), "8859_1");

output.write("GET / HTTP 1.0\r\n\r\n"); output.flush();

cnx.shutdownOutput(); // fermeture partielle BufferedReader input = // flux en lecture

new BufferedReader(

new InputStreamReader(cnx.getInputStream(),"8859_1"),1024);

StringBuffer sb = new StringBuffer(); int c;

while ((c = input.read()) != -1) sb.append((char) c);

System.out.println(sb);

} catch (IOException e) {System.out.println(e);}

finally {

try {if (connexion != null) connexion.close();}

catch (IOException e) {System.out.println(e);}

} } }

connexion à un socket serveur

(26)

Java : Rappels : socket client

import java.io.*; import java.net.Socket;

public class Main {

public static void main(String[] args) { Socket cnx = null;

try {

cnx = new Socket("www.univ-paris13.fr",80);

Writer output = new OutputStreamWriter(

cnx.getOutputStream(), "8859_1");

output.write("GET / HTTP 1.0\r\n\r\n"); output.flush();

cnx.shutdownOutput(); // fermeture partielle BufferedReader input = // flux en lecture

new BufferedReader(

new InputStreamReader(cnx.getInputStream(),"8859_1"),1024);

StringBuffer sb = new StringBuffer(); int c;

while ((c = input.read()) != -1) sb.append((char) c);

System.out.println(sb);

} catch (IOException e) {System.out.println(e);}

finally {

try {if (connexion != null) connexion.close();}

catch (IOException e) {System.out.println(e);}

} } }

flux entrées / sortie

13 / 289

(27)

Java : Rappels : socket serveur

import java.net.*; import java.io.*;

public class Main {

private ServerSocket serverSocket;

private Socket socket;

public Main(int port) {

try { serverSocket = new ServerSocket(port, 1);}

catch (IOException e) {} // erreur de création }

public static void main(String[] args) { int port;

try {port = Integer.parseInt(args[0]);}

catch (Exception e) {port = 0;} // donc valeur au hasard Main ct = new Main(port);

while (true) {

try { Socket socket = serverSocket.accept();

// code métier sur la connexion avec le client }

catch (IOException e) {System.out.println(e);}

finally {

try { if (socket != null) socket.close();}

catch (IOException e) {}

} } } }

(28)

Java : Rappels : socket serveur

import java.net.*; import java.io.*;

public class Main {

private ServerSocket serverSocket;

private Socket socket;

public Main(int port) {

try { serverSocket = new ServerSocket(port, 1);}

catch (IOException e) {} // erreur de création }

public static void main(String[] args) { int port;

try {port = Integer.parseInt(args[0]);}

catch (Exception e) {port = 0;} // donc valeur au hasard Main ct = new Main(port);

while (true) {

try { Socket socket = serverSocket.accept();

// code métier sur la connexion avec le client }

catch (IOException e) {System.out.println(e);}

finally {

try { if (socket != null) socket.close();}

catch (IOException e) {}

} } } }

création d’un socket ser- veur

réception d’un client

14 / 289

(29)

Java : Version 1.4

Assertions :

if (i % 3 == 0) { ...

} else if (i % 3 == 1) { ...

} else { // We know (i ...

}

devient

if (i % 3 == 0) { ...

} else if (i % 3 == 1) { ...

} else {

assert i % 3 == 2 : i;

...

}

(30)

Java : Version 1.5

Types génériques :

static void expurgate(Collection c) {

for (Iterator i = c.iterator(); i.hasNext(); ) if (((String) i.next()).length() == 4)

i.remove();

}

devient

static void expurgate(Collection<String> c) {

for (Iterator<String> i = c.iterator(); i.hasNext(); ) if (i.next().length() == 4)

i.remove();

}

16 / 289

(31)

Java : Version 1.5

Itérations :

int sum(int[] a) { int result = 0;

for (int i : a) result += i;

return result;

}

(32)

Java : Version 1.5

Itérations :

int sum(int[] a) { int result = 0;

for (int i : a) result += i;

return result;

}

La variableiparcourta

17 / 289

(33)

Java : Version 1.5

Boxing (i.e. passage automatique entre types primitifs et classes associées, e.g. int et Integer).

Type énumératif :

public enum Saison { PRINTEMPS, ETE, AUTOMNE, HIVER } for (Saison saison : Saison.values())

System.out.println(saison);

Nombre d’arguments variable :

public static String format(String pattern, Object... arguments);

(34)

Java : Version 1.5

Annotations : permet aux logiciels intermédiaires (compilateurs, interpréteurs, environnements, ...) d’effectuer des tests, des vérifications, des ajouts de code.

Déclaration d’une annotation :

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.METHOD) public @interface Test { }

19 / 289

(35)

Java : Version 1.5

Déclaration du code source :

public class Foo {

@Test public static void m1() { } public static void m2() { }

@Test public static void m3() {

throw new RuntimeException("Boom");

}

public static void m4() { }

@Test public static void m5() { } public static void m6() { }

@Test public static void m7() {

throw new RuntimeException("Crash");

}

public static void m8() { } }

(36)

Java : Version 1.5

Déclaration du code intermédiaire :

import java.lang.reflect.*;

public class RunTests {

public static void main(String[] args) throws Exception { int passed = 0, failed = 0;

for (Method m : Class.forName(args[0]).getMethods()) { if (m.isAnnotationPresent(Test.class)) {

try {

m.invoke(null);

passed++;

} catch (Throwable ex) {

System.out.printf("Test %s failed: %s %n", m, ex.getCause());

failed++;

} } }

System.out.printf("Passed: %d, Failed %d%n", passed, failed);

} }

21 / 289

(37)

Java : Version 1.5 / pools de threads ou de processus

java.util.concurrent.ExecutorService :

static

ExecutorService newCachedThreadPool() Création d’un pool de threads à la demande avec réutilisation des threads libres.

static

ExecutorService newFixedThreadPool(int nThreads)

Création d’un pool de taille max fixée de threads à la demande avec réutilisation des threads libres.

static

ExecutorService newSingleThreadExecutor()

Création d’un pool de taille 1 de threads ==> Pile de longueur quelconque de demandes d’exécution.

void

shutdown() Fini les tâches en cours et stoppe le pool.

void

execute(Runnable command) Demande l’exécution de la commande par un thread du pool.

<T> Future<T> submit(Callable<T> task) Demande

l’exécution de la tâche par un thread et retourne une

instance de Future

(38)

Java : Version 1.5 / pools de threads ou de processus

java.util.concurrent.Callable<V> : similaire à un Runnable mais permet de retourner une valeur,

V call()

java.util.concurrent.Future<V> : pointeur vers un objet de calcul asynchrone,

boolean

cancel(boolean mayInterruptIfRunning)

Attempts to cancel execution of this task.

V get(long timeout, TimeUnit unit) Attend timeout unités de temps et renvoie le résultat (si temps dépassé ou autre alors exception).

23 / 289

(39)

import java.util.concurrent.*;

import java.net.*; import java.io.*;

class NetworkService {

private final ServerSocket serverSocket;

private final ExecutorService pool;

public NetworkService(int port, int poolSize) throws IOException {

serverSocket = new ServerSocket(port);

pool = Executors.newFixedThreadPool(poolSize);

}

public void run() { try {

for (;;) {

pool.execute(new Handler(serverSocket.accept()));

}

} catch (IOException ex) { pool.shutdown(); } }

public static void main(String[] args) { try {

NetworkService networkService = new NetworkService(33333,5);

networkService.run();

} catch (IOException e) {System.out.println(e);}

} }

(40)

import java.util.concurrent.*;

import java.net.*; import java.io.*;

class NetworkService {

private final ServerSocket serverSocket;

private final ExecutorService pool;

public NetworkService(int port, int poolSize) throws IOException {

serverSocket = new ServerSocket(port);

pool = Executors.newFixedThreadPool(poolSize);

}

public void run() { try {

for (;;) {

pool.execute(new Handler(serverSocket.accept()));

}

} catch (IOException ex) { pool.shutdown(); } }

public static void main(String[] args) { try {

NetworkService networkService = new NetworkService(33333,5);

networkService.run();

} catch (IOException e) {System.out.println(e);}

} }

Création du pool

Lancement d’un thread via le pool

24 / 289

(41)

class Handler implements Runnable { private final Socket socket;

Handler(Socket socket) { this.socket = socket; } public void run() {

try {

InputStream in = socket.getInputStream();

int i;

while ((i = in.read()) != 0) { System.out.write(i); } }

catch (SocketException e) {System.out.println(e);}

catch (IOException e) {System.out.println(e);}

try { socket.close(); }

catch (IOException e) {System.out.println(e);} } }

(42)

class Handler implements Runnable { private final Socket socket;

Handler(Socket socket) { this.socket = socket; } public void run() {

try {

InputStream in = socket.getInputStream();

int i;

while ((i = in.read()) != 0) { System.out.write(i); } }

catch (SocketException e) {System.out.println(e);}

catch (IOException e) {System.out.println(e);}

try { socket.close(); }

catch (IOException e) {System.out.println(e);} } }

Obligatoire car utilisé comme Thread

25 / 289

(43)

Java : Version 1.6

Différentes bibliothèques supplémentaires ou améliorées : JAX-WS : web services

JDBC

Java compiler API

Annotations prédéfinies supplémentaires

(44)

Java : Version 1.6

Scripting / Java :

import javax.script.*;

public class ScriptTest{

public static void main(String[] args){

try{

// Create an instance of the Scripting manager.

ScriptEngineManager manager = new ScriptEngineManager();

// Get the reference to the rhino scripting engine.

ScriptEngine engine = manager.getEngineByName ("javascript");

// Get the Binding object for this Engine.

Bindings bindings = engine.getBindings

(ScriptContext.ENGINE_SCOPE);

// Put the input value to the Binding.

bindings.put("strValue", "A Test String");

27 / 289

(45)

Java : Version 1.6

// Populate the script code to be executed.

StringBuilder scriptCode = new StringBuilder();

scriptCode.append("var javaString

= new java.lang.String(strValue);");

scriptCode.append("var result

= javaString.length();");

// Evaluate the Script code.

engine.eval(scriptCode.toString());

// Take the output value from the script, i.e Bindings.

int strLength = (Integer)bindings.get("result");

System.out.println("Length is " + strLength);

}catch(Exception exception){

exception.printStackTrace();

} } }

(46)

Java : Version 1.7

Modifications diverses :

List<String> list = new ArrayList<String>();

Map<Reference<Object>,Map<String,List<Object>>> map =

new HashMap<Reference<Object>,Map<String,List<Object>>>();

versus

List<String> list = new ArrayList<>();

Map<Reference<Object>,Map<String,List<Object>>> map = new HashMap<>();

et aussi pointeurs vers des fonctions, ... (cf. java.lang.invoke )

29 / 289

(47)

Java : Version 1.8

Expressions lambda annotations améliorées java.util.stream

sécurité et diverses autres choses

(48)

Java : Version 1.8

Syntaxe d’une lambda-expression :

(Type1 var1,...,Typep varp) -> corps

() -> System.out.println(this)

(String str) -> System.out.println(str) str -> System.out.println(str)

(String s1, String s2) -> { return s2.length() - s1.length(); } Arrays.sort(strArray,

(s1, s2) -> s2.length() - s1.length());

Possibilité d’utiliser des variables externes au corps et des arguments de la lambda seulement si ces variables sont inchangées dans la suite du programme (comme les variables

static

par exemple).

31 / 289

(49)

Java : Version 1.8

Le type d’une lambda-expression est une interface

fonctionnelle : interface à méthode unique (ou presque ...) :

@FunctionalInterface public interface Somme {

public int somme(int n1, int n2);

}

Utilisation dans un code :

public class Test {

public static void main(String[] args) { Somme somme =(int a, int b) -> a+b;

int resultat = somme.somme(3, 4);

System.out.println(resultat);

} }

(50)

Java : Version 1.8

Possibilité d’accéder directement aux méthodes (vues alors comme des lambda-expressions nommées) :

import java.io.*;

import java.util.*;

class Test {

public static void main(String[] args) {

PolygoneRegulier p1 = new PolygoneRegulier(2,4);

PolygoneRegulier p2 = new PolygoneRegulier(3,6);

PolygoneRegulier p3 = new PolygoneRegulier(2,8);

PolygoneRegulier p4 = new PolygoneRegulier(4,4);

List<PolygoneRegulier> lp = Arrays.asList(p1,p2,p3,p4);

lp.stream() // filtrage

.filter(x -> x.getNbCotes() == 2) // mapping

.map(x -> {x.setNbCotes(x.nbCotes+3); return x;}) .forEach( System.out::println );

} }

(slide suivant pour la classe

PolygoneRegulier

)

33 / 289

(51)

class PolygoneRegulier { int nbCotes, lgCotes;

PolygoneRegulier(int nbCotes,int lgCotes) { setNbCotes(nbCotes);

setLgCotes(lgCotes);

}

public String toString() {

return "Polygone Régulier: nbCotes = " + nbCotes + ", lgCotes = " + lgCotes;

}

public void setNbCotes(int nbCotes) { this.nbCotes = nbCotes;

}

public void setLgCotes(int lgCotes) { this.lgCotes = lgCotes;

}

public int getNbCotes() { return nbCotes;

}

public int getLgCotes() { return lgCotes;

} }

(52)

Java : Version 1.8

Un Stream permet effectivement d’appliquer des fonctions sur un flux d’éléments.

Un flux peut être créé à partie de collections, de listes, ... avec la méthode stream() .

Un flux permet de modifier des objets à la volée.

Les fonctions de modification permettent d’itérer, d’appliquer, de concaténer des résultats, ...

Les arguments fonctionnels de ces fonctions de modification ont l’annotation FunctionalInterface et l’un des types (ou des variantes) :

Function<T,R> : prend un objet de type T et retourne un objet de type R

Supplier<T> : retourne un objet de type R

Predicate<T> : retourne un booléen selon l’objet de type T

Consumer<T> : effectue une opération sur l’objet de type T

35 / 289

(53)

Java : Version 1.8

Exemple avec Consumer<T> :

import java.util.*;

import java.util.function.Consumer;

public class Test {

public static void main(String[] args) {

List<Personne> list = new ArrayList<Personne>();

list.add(new Personne("Younes",45,"PR"));

list.add(new Personne("Jean-Yves",40,"MCF"));

Consumer<Personne> impression

= (Personne p) -> System.out.println ("Nom :"+p.nom

+", Age :"+p.age

+", Profession :"+p.profession);

//3 possibilites : list.forEach(impression);

list.forEach(Personne::impression);

list.forEach(p -> p.impression());

} }

avec la classe Personne (slide suivant)

(54)

public class Personne { public String nom;

public int age;

public String profession;

public Personne(String nom,int age,String profession){

this.nom = nom;

this.age = age;

this.profession = profession;

}

public void impression(){

System.out.println("Nom :"+nom +", Age :"+age

+", Profession :"+profession);

} }

37 / 289

(55)

Autre exemple avec Predicate et 1 Stream parallléle :

import java.util.*;

import java.util.function.Predicate;

public class Test {

public static void main(String[] args) {

List<Personne> list = new ArrayList<Personne>();

list.add(new Personne("Younes",50,"PR"));

list.add(new Personne("Jean-Yves",40,"MCF"));

list.add(new Personne("Christophe",53,"PR"));

Predicate<Personne> isProfesseur

= e -> e.profession.equals("PR");

OptionalDouble ageMoyenPr = list .parallelStream()

.filter(isProfesseur) .mapToDouble(e -> e.age) .average();

System.out.println(ageMoyenPr.getAsDouble());

} }

(56)

Autre exemple avec Predicate et 1 Stream séquentiel :

import java.util.*;

import java.util.function.Predicate;

public class Test {

public static void main(String[] args) {

List<Personne> list = new ArrayList<Personne>();

list.add(new Personne("Younes",50,"PR"));

list.add(new Personne("Jean-Yves",40,"MCF"));

list.add(new Personne("Christophe",53,"PR"));

Predicate<Personne> isProfesseur

= e -> e.profession.equals("PR");

int nombre = list .stream()

.filter(isProfesseur) .mapToInt(e -> 1) .sum();

System.out.println(nombre);

} }

39 / 289

(57)

2

Annotations en Java

(58)

Une annotation est une méta-donnée permettant à l’“environnement”

de générer des fichiers de configuration (pour le déploiement, la compilation finale)

de générer des interfaces (en précisant les méthodes à y inclure), des classes subsidiaires, ...

de lier des noms de méthodes ou de spécifier des noms externes (base de donnée, ...)

de déterminer des informations annexes (documentation, tests,...)

41 / 289

(59)

Une annotation est inscrite dans le code java même en commençant par le symbole @ .

L’environnement doit comprendre des programmes permettant d’interpréter les annotations.

L’interprétation des annotations peut avoir lieu sur le fichier

.java ou sur le fichier .class si l’annotation y est

conservée (i.e. la méta-annotation @Retention est utilisée

dans le fichier source).

(60)

Une annotation se pose avant n’importe quel modifieur (p.e.

public

) d’une classe, d’une méthode ... (en Java 8 : même un type !)

Ele peut être combinée en une séquence d’annotations Une annotation peut annotée une autre annotation une annotation est posée dans un programme java :

...

@MonAnnotation(

unAttribut = 12345,

unAutreAttribut = "une valeur", )

public static void maMethode(...) { ... } ...

ou

...

@UneAutreAnnotation public class MaClasse(...)

{ ... } ...

ou

...

@UneDerniereAnnotation("val") public class MaClasse(...)

{ ... } ...

(si l’annotation n’a qu’un attribut de nom

String value())

43 / 289

(61)

une annotation est définie dans un programme Java comme un ensemble éventuellement vide d’attributs :

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME) public @interface MonAnnotation {

int unAttribut();

String unAutreAttribut();

}

une annotation est utilisée par un programme :

import java.lang.reflect.*;

public class CodeMonAnnotation {

public static void main(String[] args) throws Exception { for (Method m : Class.forName(args[0]).getMethods()) {

if (m.isAnnotationPresent(MonAnnotation.class)) { ... // code à effectuer

} } } }

Pour l’exemple précédent, il faut que l’annotation ait été

conservée dans le fichier .class , d’où l’utilisation de

l’annotation Retention (cf plus loin)

(62)

Pour chaque type d’annotation javac recherche dans son environnement ( classpath ) une classe dont le nom est celle du type d’annotation. Il ajoute alors au code compilé le contenu de l’annotation (valeurs par défaut, ...).

Plus de 60 annotations en standard dont :

@Deprecated : (devant une méthode) indique que la méthode qui suit n’est pas recommandée (i.e. son usage génèrera un warning)

@Override : (devant une méthode) indique que la méthode qui suit doit surcharger une méthode d’une super-classe

@SuppressWarnings(type) : supprime les warnings pour le type donné ( "deprecation" , "all" ,...)

45 / 289

(63)

Exemple : annotation standard sur un code java

import java.io.*;

public class Test {

// @SuppressWarnings("fallthrough") public static void main(String args[]) {

PrintStream out = System.out;

int i = args.length;

switch (i) { // manque des breaks case 0: println("0");

default: println("Default");

} }

// @Override

public String toZtring () { return super.toString();

}}

Sans suppression des commentaires :

$ javac Test.java

$ javac -Xlint Test.java

Test.java:7: warning: [fallthrough]

possible fall-through into case default: System.out.println("Default");

^ 1 warning

$

(64)

Exemple : annotation standard sur un code java

import java.io.*;

public class Test {

// @SuppressWarnings("fallthrough") public static void main(String args[]) {

PrintStream out = System.out;

int i = args.length;

switch (i) { // manque des breaks case 0: println("0");

default: println("Default");

} }

// @Override

public String toZtring () { return super.toString();

}}

Avec

@Override

décommenté :

$ javac Test.java

Test.java:10: method does not override or implement a method from a supertype

@Override

^ 1 error

$

Avec

@SuppressWarnings

décommenté :

$ javac -Xlint Test.java

$

47 / 289

(65)

Les méta-annotations sont en particulier utiles pour définir des annotations. Par exemple :

@Retention(type) : méta-annotation qui conserve selon le type ( RetentionPolicy.RUNTIME dans le code et après chargement dans la VM, RetentionPolicy.CODE dans le code seulement) l’annotation utilisée dans un programme.

@Target(type) : méta-annotation qui précise sur quoi peut être appliquée l’annotation ( ElementType.METHOD pour une méthode, ElementType.TYPE pour une classe, une

interface, ...).

(66)

Annotations prédéfinies ajoutées dans la version 1.6 :

@Generated : précise le code généré par un framework

public class MyClass{

public void codePersonnel(){

}

@Generated(

value = "ClasseGeneratrice", comments = "blablabla", date = "24 avril 2014"

)

public void codeGenere(){

} }

49 / 289

(67)

@Resource : spécifie comment la ressource est utilisable

@Resource(name = "MaListe", type = javax.jms.Queue, shareable = false,

authenticationType = Resource.AuthenticationType.CONTAINER, description = "Une Liste"

)

private javax.jms.Queue maListe;

(68)

@PostConstruct et @PreDestroy : spécifie ce qu’il faut faire en création d’instance et lors de la destruction de l’instance

public class ClassePersonnelle{

public ClassePersonnelle(){

}

@PostConstruct()

public void loadDefaults(){

// blabla }

@PreDestroy()

public void releaseResources(){

// blabla }

} }

51 / 289

(69)

@DeclareRoles : spécifie les autorisations

@DeclareRoles(value = {"Director", "Manager", "Others" }) public class LeaveService{

@Resource

private Context context;

public void applyLeave(){

// Any employee can apply for leave.

}

public void grantLeave(){ if(checkUserInRole()){

// Grant Leave.

} }

public void cancelLeave(){ if(checkUserInRole()){

// Cancel Leave.

} }

private boolean checkUserInRole(){

if( (context.isCallerInRole("Director") )

|| (context.isCallerinRole("Manager")) ){

return true;

}

return false;

} }

(70)

Il existe un framework permettant d’utiliser des annotations de test : The Checker Framework

javac -processor

org.checkerframework.checker.nullness.NullnessChecker MaClasse.java

Permet les tests suivants entre autres :

@NonNull test si la variable est non nulle (bien pour les sockets !)

@MapKey teste si la variable est une clé de map

@GuardedBy, @Holding teste sur la synchronisation

@Regex teste si une expression est régulière

@Format teste le formatage d’une chaîne de caractères ...

53 / 289

(71)

public class UneClasse { ...

void maMethode() {

@NonNull Truc ref = toto;

} }

(72)

exemples du Checker Framework

void helper1(@GuardedBy("MyClass.myLock") Object a) { a.toString(); // ILLEGAL: the lock is not held synchronized(MyClass.myLock) {

a.toString(); // OK: the lock is held

} }

@Holding("MyClass.myLock")

void helper2(@GuardedBy("MyClass.myLock") Object b) { b.toString(); // OK: the lock is held

}

void helper3(Object c) { helper1(c); // OK

c.toString(); // OK: no lock constraints }

void myMethod2(@GuardedBy("MyClass.myLock") Object e) { helper1(e); // OK pass to a method without locking e.toString(); // ILLEGAL: the lock is not held synchronized (MyClass.myLock) {

helper2(e);

helper3(e);

} }

55 / 289

(73)

exemples du Checker Framework

public @Regex String parenthesize(@Regex String regex) { return "(" + regex + ")";

}

@Format({FLOAT, INT}) String f;

f = "%f %d"; // Ok

f = "%s %d"; // OK, %s is weaker than %f

f = "%f"; // warning: last argument is ignored f = "%f %d %s"; // error: too many arguments

f = "%d %d"; // error: %d is not weaker than %f String.format("%d", 42); // OK String.format(Locale.GERMAN, "%d", 42); // OK

String.format(new Object()); // error (1a)

String.format("%y"); // error (1a)

String.format("%2$s", "unused", "used"); // warning (1b)

(74)

Exemple : Traitement manuel à l’exécution (1)

importjava.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.METHOD) public@interface Audit {

booleanvalue()default false;

}

public classTest {

public static voidmain(String args[]) { Application app = new Application();

app.methA("a1");

app.methB();

} }

public classApplication {

@Audit(true)

public void methA(String s) {

GestionAudit.gestion(this,"methA",String.class);

// code de l’application }

public void methB() {

GestionAudit.gestion(this,"methB");

// code de l’application }

}

$javac *.java

$java Test

[Audit] appel de methA

$

57 / 289

(75)

Exemple : Traitement manuel à l’exécution (1)

importjava.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.METHOD) public@interface Audit {

booleanvalue()default false;

}

public classTest {

public static voidmain(String args[]) { Application app = new Application();

app.methA("a1");

app.methB();

} }

public classApplication {

@Audit(true)

public void methA(String s) {

GestionAudit.gestion(this,"methA",String.class);

// code de l’application }

public void methB() {

GestionAudit.gestion(this,"methB");

// code de l’application }

}

$javac *.java

$java Test

[Audit] appel de methA

$

l’annotation Audit sera conservée à l’exécution

(76)

Exemple : Traitement manuel à l’exécution (1)

importjava.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.METHOD) public@interface Audit {

booleanvalue()default false;

}

public classTest {

public static voidmain(String args[]) { Application app = new Application();

app.methA("a1");

app.methB();

} }

public classApplication {

@Audit(true)

public void methA(String s) {

GestionAudit.gestion(this,"methA",String.class);

// code de l’application }

public void methB() {

GestionAudit.gestion(this,"methB");

// code de l’application }

}

$javac *.java

$java Test

[Audit] appel de methA

$

déclaration de l’anno- tation

appel à l’exécution, traitement selon la valeur de l’annotation (cf slide suivant)

57 / 289

(77)

Exemple : Traitement manuel à l’exécution (2)

importjava.lang.reflect.*;

public classGestionAudit {

public static voidgestion(Object object, String methodName, Class... paramTypes) { try{

Class paramTypesArray[] = newClass[paramTypes.length];

inti = 0;

for(Class paramType : paramTypes) paramTypesArray[i++] = paramType;

// Récupérer la méthode appelée.

Method method = object.getClass().getMethod(methodName, paramTypesArray);

// S’il n’y a pas d’annotation, autoriser l’appel

if( !method.isAnnotationPresent(Audit.class) )return;

// Récupérer la donnée de l’annotation, s’il faut auditer alors le faire Audit auditValue = method.getAnnotation(Audit.class);

if( auditValue.value() ) audit("[Audit] appel de " + methodName);

} catch(Exception e) { audit("[Audit exception] sur l’appel de " + methodName);

} }

private static voidaudit(String msg) { System.err.println(msg); } }

(78)

Exemple : Traitement manuel à l’exécution (2)

importjava.lang.reflect.*;

public classGestionAudit {

public static voidgestion(Object object, String methodName, Class... paramTypes) { try{

Class paramTypesArray[] = newClass[paramTypes.length];

inti = 0;

for(Class paramType : paramTypes) paramTypesArray[i++] = paramType;

// Récupérer la méthode appelée.

Method method = object.getClass().getMethod(methodName, paramTypesArray);

// S’il n’y a pas d’annotation, autoriser l’appel

if( !method.isAnnotationPresent(Audit.class) )return;

// Récupérer la donnée de l’annotation, s’il faut auditer alors le faire Audit auditValue = method.getAnnotation(Audit.class);

if( auditValue.value() ) audit("[Audit] appel de " + methodName);

} catch(Exception e) { audit("[Audit exception] sur l’appel de " + methodName);

} }

private static voidaudit(String msg) { System.err.println(msg); } }

nombre variable d’arguments (varargs, Java 5)

utilisation de la réflexi- vité dans Java

58 / 289

(79)

Exemple : Traitement manuel à l’exécution (2)

importjava.lang.reflect.*;

public classGestionAudit {

public static voidgestion(Object object, String methodName, Class... paramTypes) { try{

Class paramTypesArray[] = newClass[paramTypes.length];

inti = 0;

for(Class paramType : paramTypes) paramTypesArray[i++] = paramType;

// Récupérer la méthode appelée.

Method method = object.getClass().getMethod(methodName, paramTypesArray);

// S’il n’y a pas d’annotation, autoriser l’appel

if( !method.isAnnotationPresent(Audit.class) )return;

// Récupérer la donnée de l’annotation, s’il faut auditer alors le faire Audit auditValue = method.getAnnotation(Audit.class);

if( auditValue.value() ) audit("[Audit] appel de " + methodName);

} catch(Exception e) { audit("[Audit exception] sur l’appel de " + methodName);

} }

private static voidaudit(String msg) { System.err.println(msg); } }

test de présence de l’annotation associée au code de la méthode (rétention de la déclara- tion dans le code source)

test de sa valeur

(80)

Les annotations sont principalement gérées en phase de compilation :

En Java 1.5 : l’outil apt (annotation processing tool) sert au traitement des annotations. Etant séparé du compilateur, la gestion est complexe.

En Java 6 : javac intègre le traitement des annotations par un double mécanisme :

une structure liée aux constructions du langage une structure liée à l’arbre de syntaxe abstraite (ASP)

59 / 289

(81)

En Java 6, double mécanisme,

( javax.lang.model.element ) l’interface Element et ses sous-interfaces caractérisent un constructeur du langage (paquet, type, classe, méthode). Permet de connaître les sous- et sur-éléments constructeurs. Ne permet pas a priori de connaître le contenu opérationnel.

(p.e. com.sun.source.tree ) l’interface Tree et ses sous-interfaces caractérisent l’ASP de Java vu par le compilateur. Permet de connaître les sous-et sur-éléments constructeurs, structures du langage (boucle, ...), et d’accéder au bloc du fichier source associé.

Dans les 2 cas, possibilité d’utiliser le pattern visitor

(méthode accept(v)v est un visiteur (implantation de

ElementVisitor ou TreeVisitor ) implantant des

méthodes visitXXX()

(82)

Exemple : Traitement via le compilateur (1)

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.METHOD) public @interface Audit {

// true: les accès à cette méthode // sont écrits dans un fichier d’audit boolean value() default false;

}

public class Application {

@Audit(true)

public void methA(String s) { int i = 0;

// code de l’application }

@Audit(false)

public void methB(String s) { // code de l’application }

@Deprecated

public void methC() { // code de l’application

} } 61 / 289

(83)

Exemple : Traitement via le compilateur (2)

%javac -cp $CLASSPATH:/opt/jdk1.6.0_10/lib/tools.jar GestionAudit.java

%javac -processor GestionAudit Application.java methA(java.lang.String) :

Valeur de l’annotation associee = true METHOD

Method methA: null Body: {

int i = 0;

}

methB(java.lang.String) :

Valeur de l’annotation associee = false METHOD

Method methB: null Body: {

}

(84)

Exemple : Traitement via le compilateur (2)

%javac -cp $CLASSPATH:/opt/jdk1.6.0_10/lib/tools.jar GestionAudit.java

%javac -processor GestionAudit Application.java methA(java.lang.String) :

Valeur de l’annotation associee = true METHOD

Method methA: null Body: {

int i = 0;

}

methB(java.lang.String) :

Valeur de l’annotation associee = false METHOD

Method methB: null Body: {

}

jar contenant les classes permettant le preprocessing (analyse d’ASP, ...)

le code associé à l’an- notation Audit est exé- cuté

62 / 289

(85)

Exemple : Traitement via le compilateur (3)

import java.util.*;

import javax.annotation.processing.*;

import javax.lang.model.*; import javax.lang.model.element.*;

@SupportedAnnotationTypes(value= {"Audit"})

@SupportedSourceVersion(SourceVersion.RELEASE_6) public class GestionAudit extends AbstractProcessor {

private ProcessingEnvironment environment;

@Override public void init(ProcessingEnvironment environment) { super.init(environment);

this.environment = environment;

} ...

(86)

Exemple : Traitement via le compilateur (3)

import java.util.*;

import javax.annotation.processing.*;

import javax.lang.model.*; import javax.lang.model.element.*;

@SupportedAnnotationTypes(value= {"Audit"})

@SupportedSourceVersion(SourceVersion.RELEASE_6) public class GestionAudit extends AbstractProcessor {

private ProcessingEnvironment environment;

@Override public void init(ProcessingEnvironment environment) { super.init(environment);

this.environment = environment;

} ...

Liste des annotations gérées par cette classe-processeur

Spécification de la re- lease de Java néces- saire

63 / 289

(87)

Exemple : Traitement via le compilateur (3)

import java.util.*;

import javax.annotation.processing.*;

import javax.lang.model.*; import javax.lang.model.element.*;

@SupportedAnnotationTypes(value= {"Audit"})

@SupportedSourceVersion(SourceVersion.RELEASE_6) public class GestionAudit extends AbstractProcessor {

private ProcessingEnvironment environment;

@Override public void init(ProcessingEnvironment environment) { super.init(environment);

this.environment = environment;

} ...

classe-processeur par défaut

instanciation (p.e. par javac) avec l’environ- nement de compila- tion

(88)

...

@Override public boolean process

(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv){

AuditVisitor auditVisitor=new AuditVisitor(environment);

for (Element element :

roundEnv.getElementsAnnotatedWith(Audit.class)){

System.out.println(element + " : ");

System.out.println("Valeur de l’annotation associée = "

+ element.getAnnotation(Audit.class).value());

System.out.println(element.getKind());

auditVisitor.visit(element,null);

}

return false;

} }

64 / 289

(89)

...

@Override public boolean process

(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv){

AuditVisitor auditVisitor=new AuditVisitor(environment);

for (Element element :

roundEnv.getElementsAnnotatedWith(Audit.class)){

System.out.println(element + " : ");

System.out.println("Valeur de l’annotation associée = "

+ element.getAnnotation(Audit.class).value());

System.out.println(element.getKind());

auditVisitor.visit(element,null);

}

return false;

} }

processing sur l’environnement courant pour les an- notations en 1er argument, si return true alors anno- tations non analysées par les processeurs suivants

Références

Documents relatifs

Les expériences contrastées du Royaume-Uni et de la Suède sont à cet égard très instructives ; elles débou- chent sur l’hypothèse suivante : à la fois pour des raisons

La fenêtre joue le rôle de « conteneur » dans lequel vont être disposés les différents éléments constitutifs (composants) de l’interface. graphique de l’application

 L’école de Verlaine s’implique dans plusieurs projets en lien avec le développement durable, notamment dans le domaine de l’alimentation (cantine locale et

public interface Immutable{} // interface vide, un « marker » public class NotImmutableException.

extends (Collection&lt;? extends extends extends T&gt; collection) T&gt; collection) T&gt; collection) T&gt; collection) – static static static &lt;T&gt; List&lt;T&gt;

– Fournissent un service pour un seul utilisateur – Ne maintiennent pas d'état par rapport au client – Ne survivent pas à un crash du serveur d'EJB – Sont plutôt destinés à

Le code source Java est compilé non pas pour un processeur donné, mais pour une machine virtuelle (c'est-à-dire qui n'a pas d'existence physique), la JVM (Java Virtual Machine)..

• Utilisez la m´ ethode get de l’interface Future pour r´ ecup´ erer, chez le client, le r´ esultat de plusieurs appels ` a la m´ ethode aLongWorkWithResult.. • Testez, par