Download - Java SE 7
![Page 1: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/1.jpg)
Frédéric Renout
Nouveautés
Java SE 7
Novembre 2011
![Page 2: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/2.jpg)
Frédéric Renout
IntroductionJava GUIJava « core »Java dynamic bindingJava Concurrent
Agenda
Novembre 2011
![Page 3: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/3.jpg)
Frédéric Renout
Quoi de neuf ?
Langage
I/OConcurrent
SécuritéRéseau
Collections
Déploiement Client graphique
Dynamique
Novembre 2011
![Page 4: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/4.jpg)
Frédéric Renout
Client GraphiqueDéploiement
Java GUI
Novembre 2011
![Page 5: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/5.jpg)
Frédéric Renout
Client graphiqueNouveau Look and Feel : NimbusTransparence , gradient et formes libres pour
les fenêtres swing Interactions graphiques améliorées entre awt
et swing
DéploiementAmélioration de JNLP
Embeddable Signature partielle
Gui
Novembre 2011
![Page 6: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/6.jpg)
Frédéric Renout Novembre 2011
GUI - Transparence
![Page 7: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/7.jpg)
Frédéric Renout Novembre 2011
GUI - Gradient
![Page 8: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/8.jpg)
Frédéric Renout Novembre 2011
GUI - Forme
![Page 9: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/9.jpg)
Frédéric Renout Novembre 2011
GUI – AWT-Swing
![Page 10: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/10.jpg)
Frédéric Renout
CollectionSécuritéRéseauLangage
Java « Core »
Novembre 2011
![Page 11: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/11.jpg)
Frédéric Renout
Interface de Queue bloquante (LinkedTranferQueue)
Dérive de BlockingPermet d’attendre qu’un item envoyé soit
consomméMéthodes:
hasWaitingConsumer / getWaitingConsumerCount
transfer : bloquant tryTransfer : bon bloquant et paramétrable
Démo
CollectionsTransferQueue
Novembre 2011
![Page 12: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/12.jpg)
Frédéric Renout
Nouveaux algo basés sur ECC (Elliptic Curve Cryptography)
Possibilité de désactiver l’utilisation d’algos « faibles » durant l’utilisation de TLS (=SSL)
Sécurité
Novembre 2011
![Page 13: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/13.jpg)
Courbe elliptique : y2mod p =x3+ax+b mod pIci : y2=x3-5x+3
Courbe ayant des propriétés de calcul « simples » pour +
Sécurité - ECC
Novembre 2011Frédéric Renout
![Page 14: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/14.jpg)
Sécurité - ECC
Novembre 2011Frédéric Renout
Algorithme :A et B choisissent publiquement une courbe C et un point P de
cette courbeA choisi secrètement un entier dA
B choisi secrètement un entier dB
A envoie publiquement dAP = P+P+…dA fois…+P
B envoie publiquement dBP = P+P+…dB fois…+P
A et B peuvent calculer dA(dBP) = dB(dAP) = (dBdA)P qui est leur clé de chiffrement secrète
Un espion E doit pouvoir retrouver dA et dB et aujourd’hui le temps nécessaire pour résoudre ce problème est très longPlus d’infos :
http://www.apprendre-en-ligne.net/crypto/moderne/elliptique.htmlhttp://fr.wikipedia.org/wiki/Cryptographie_sur_les_courbes_elliptiques
![Page 15: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/15.jpg)
Frédéric Renout
UrlClassLoader.close Fermer le classLoader pour libérer les
ressources chargées et les remplacerSocket Direct Protocol
Solaris & Linux Utilisé par infiniBand qui permet de faire des
accès mémoire entre machine sans passer par l’OS
Réseau
Novembre 2011
![Page 16: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/16.jpg)
Frédéric Renout
Projet Coin
coin something : to invent a new word or phrase that other
people then begin to use
Modification mineure du langage visant à rendre le code plus facile à écrire et à maintenir
Langage
Novembre 2011
![Page 17: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/17.jpg)
Frédéric Renout
L’utilisation de varargs de types paramétrés génère des warnings à l’utilisation des méthodesJava 7 permet deGénérer un warning à la déclaration : possible heap pollutionSupprimer ces warnings @SafeVarargs
Retire tout warnings @SuppressWarnings(« unchecked », »varargs »)
Retire les warnings à la déclaration -Xlint:-varargs
LangageVarargs
Novembre 2011
![Page 18: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/18.jpg)
Frédéric Renout
Possibilité de séparer les nombres par des _5000000 = 5_000_000Limite les erreurs de lecture
Possibilité de représenter un nombre sous sa forme binaire42 = 0b101010Facilite la représentation des bitmasks…
LangageNombres
Novembre 2011
![Page 19: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/19.jpg)
… ou d’une bitmap
public static final short[] HAPPY_FACE = {
(short)0b0000011111100000;
(short)0b0000100000010000;
(short)0b0001000000001000;
(short)0b0010000000000100;
(short)0b0100000000000010;
(short)0b1000011001100001;
(short)0b1000011001100001;
(short)0b1000000000000001;
(short)0b1000000000000001;
(short)0b1001000000001001;
(short)0b1000100000010001;
(short)0b0100011111100010;
(short)0b0010000000000100;
(short)0b0001000000001000;
(short)0b0000100000010000;
(short)0b0000011111100000; }
Novembre 2011Frédéric Renout
LangageNombres
![Page 20: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/20.jpg)
… ou d’une bitmap
public static final short[] HAPPY_FACE = {
(short)0b0000011111100000;
(short)0b0000100000010000;
(short)0b0001000000001000;
(short)0b0010000000000100;
(short)0b0100000000000010;
(short)0b1000011001100001;
(short)0b1000011001100001;
(short)0b1000000000000001;
(short)0b1000000000000001;
(short)0b1001000000001001;
(short)0b1000100000010001;
(short)0b0100011111100010;
(short)0b0010000000000100;
(short)0b0001000000001000;
(short)0b0000100000010000;
(short)0b0000011111100000; }
Novembre 2011Frédéric Renout
LangageNombres
![Page 21: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/21.jpg)
Frédéric Renout
On peut switcher sur des types primitif (ou leurs wrappers)des enumsdes Strings
LangageSwitch
Novembre 2011
![Page 22: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/22.jpg)
Frédéric Renout
List<IndexOutOfBoundsException> dictionnaire = new ArrayList<IndexOutOfBoundsException >();
Map<String,Map<String,String>> i18nDictionnaire = new HashMap<String,Map<String,String>>();
Langageinférence de type
Novembre 2011
![Page 23: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/23.jpg)
Frédéric Renout
List<IndexOutOfBoundsException> dictionnaire = new ArrayList<>();
Map<String,Map<String,String>> i18nDictionnaire = new HashMap<>();
Langageinférence de type
Novembre 2011
![Page 24: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/24.jpg)
Frédéric Renout
Multiple catchRe-throw precis
LangageException
Novembre 2011
![Page 25: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/25.jpg)
Frédéric Renout
try {
File input = new File("input.txt");
FileReader fr = new FileReader(input);
File output = new File("output.txt");
FileWriter fw = new FileWriter(output);
int readed;
while ((readed = fr.read()) != -1) {
fw.write(readed);
}
fw.flush();
fw.close();
fr.close();
} catch (FileNotFoundException e) {
log(e);
}catch (IOException e) {
log(e);
}
}
Langage - ExceptionMultiple catch
Novembre 2011
try {
File input = new File("input.txt");
FileReader fr = new FileReader(input);
File output = new File("output.txt");
FileWriter fw = new FileWriter(output);
int readed;
while ((readed = fr.read()) != -1) {
fw.write(readed);
}
fw.flush();
fw.close();
fr.close();
} catch (FileNotFoundException | IOException e) {
log(e);
}
}
![Page 26: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/26.jpg)
Frédéric Renout
public void copy() throws FileNotFoundException , IOException {try { File input = new File("input.txt"); FileReader fr = new FileReader(input); File output = new File("output.txt"); FileWriter fw = new FileWriter(output); int readed; while ((readed = fr.read()) != -1) { fw.write(readed); } fw.flush(); fw.close(); fr.close(); } catch (FileNotFoundException e) { log(e); throw e; }catch (IOException e) { log(e); throw e; } }}
Langage – Exceptionre-throw précis
Novembre 2011
public void copy() throws FileNotFoundException , IOException {try { File input = new File("input.txt"); FileReader fr = new FileReader(input); File output = new File("output.txt"); FileWriter fw = new FileWriter(output); int readed; while ((readed = fr.read()) != -1) { fw.write(readed); } fw.flush(); fw.close(); fr.close(); } catch (Exception e) { log(e); throw e; } }}
![Page 27: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/27.jpg)
Frédéric Renout
Nouvelle interface : AutoClosableOn passe les ressources au tryEn sortie les ressources sont fermées dans le
sens inverse de la déclarationEn cas d’exception dans le try les exceptions
du à la fermeture sont supprimées mais accessibles via Throwable.getSuppressed
Démo
Langagetry with resources
Novembre 2011
![Page 28: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/28.jpg)
Frédéric Renout
JVM
Novembre 2011
InvokeDynamic
![Page 29: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/29.jpg)
Frédéric Renout
Quels langages tournent sur une JVM?
JVMInvokeDynamic
Novembre 2011
Java
ScalaGroovy
Jython
RhinoErjang
JRubyEt pleins d’autres...
![Page 30: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/30.jpg)
Frédéric Renout
Beaucoup de ces langages sont des langages dynamiquesJava est fortement typé. Les traitements dynamiques doivent être « émulés » et sont couteux.Nouvelle instruction au niveau du bytecode : invokeDynamicNouvelle API de réflection : java.lang.invoke
CallSiteMethodHandle
Démo
JVMInvokeDynamic
Novembre 2011
![Page 31: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/31.jpg)
Frédéric Renout
ThreadLocaleRandomPhaserFork/join
Concurrent
Novembre 2011
![Page 32: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/32.jpg)
Frédéric Renout
Utilisation de nombre aléatoires dans des threads ou des ForkJoinTask
Garanti que chaque Thread à son propre Random
ConcurrentThreadLocaleRandom
Novembre 2011
![Page 33: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/33.jpg)
Frédéric Renout
Permet de synchroniser de traitements, de gérer des phases :1. Enregistrer le nombre d’entités se
synchronisant sur le Phaser2. Démarrer les Threads3. Se synchroniser avec
arriveAndAwaitAdvance()4. Attendre une phase : awaitAdvance(#phase)
Démo
ConcurrentPhaser
Novembre 2011
![Page 34: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/34.jpg)
Frédéric Renout
Fork : diviser un tache en sous-tachesJoin : combiner les résultats des sous-tâches
ConcurrentFork/join
Novembre 2011
![Page 35: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/35.jpg)
Frédéric Renout
Utiliser efficacement plusieurs processeursWorkStealing : les threads inutilisés prennent
des tâches à ceux occupés.Similaire à Map/Reduce de Google mais avec
une granularité différente (on peut définir des seuils de fork) et une scalabilité différente : MapReduce fonctionne sur des clusters, fork/join sur une JVM et sa machine
ConcurrentFork/join
Novembre 2011
![Page 36: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/36.jpg)
Frédéric Renout
Déclenchements Synchrone -> invoke Asynchrone -> execute Asynchrone et future ->submit
ConcurrentFork/join
Novembre 2011
![Page 37: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/37.jpg)
Frédéric Renout
ConcurrentFork/join
ForkJoinPool
fork() join
()
ForkJoinTask
compute()invocation
compute()
Novembre 2011
![Page 38: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/38.jpg)
Frédéric Renout
ConcurrentFork/join
Démo
Novembre 2011
![Page 39: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/39.jpg)
Frédéric Renout
A Jean-Michel
NIO2
Novembre 2011
![Page 40: Java SE 7](https://reader035.vdocuments.pub/reader035/viewer/2022081602/5487456fb4af9fa5578b45f8/html5/thumbnails/40.jpg)
Frédéric Renout
Questions
Novembre 2011