![Page 2: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/2.jpg)
Java 1 - Introduction
Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE
![Page 3: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/3.jpg)
Java 2 - Technique
Les API Les librairies Best practices Exemples
![Page 4: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/4.jpg)
Java 2 - Technique
Les API Les librairies Best practices Exemples
![Page 5: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/5.jpg)
Les API
Les API que vous utiliserez le plus.
PerformantesCollections/JSTL
EvidentesInput/Math
Riches
![Page 6: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/6.jpg)
Les API
Collections Input / Output Threading Network Serialization
Reflection XML JDBC ...
![Page 7: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/7.jpg)
Les API
java.util.Collection
http://fr.wikipedia.org/wiki/Collection
D'une manière générale, une collection est un rassemblement d'objets.
![Page 8: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/8.jpg)
Collections
// 1. Un tableauString[] numbers = new String[] {
"one", "two", "three", "one" };
// 2. Une listeList<String> list =
Arrays.asList(numbers);
// 3. UnicitéSet<String> set = new
HashSet<String>(list);// contient { "one", "two",
"three" }
// 4. AdditionList<City> trajet = new
ArrayList<City>();trajet.addAll(villes1);trajet.addAll(villes2);
// 5. Soustractiontrajet.removeAll(villesViolentes
);
// 6. UnionSet<City> visitees = new
HashSet<City>();visitees.addAll(villes1);visitees.addAll(villes2);
// 7. IntersectionSet<City> villesFleuries = new
HashSet<City>(Arrays.asList(new City[] { new City("Colmar"), new City("Mulhouse"), new City("Lille") }));
visitees.retainAll(villesFleuries);
// contient les villes visitees et fleuries
![Page 9: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/9.jpg)
Les API
java.io
http://fr.wikipedia.org/wiki/Machine_de_Turing
Un ruban divisé en cases consécutives – permet l'entrée et la sortie d'information.
![Page 10: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/10.jpg)
Input Output
FileInputStream input = null;try { input = new FileInputStream(file); String content = readFile(input); logger.info(content);} finally { if (input != null) { try { input.close(); } catch (IOException ioe) { // Harmless logger.throwing("FooBar", "foo", ioe); logger.fine("Can't close file reader
properly"); } }}
![Page 11: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/11.jpg)
Les API
java.util.conccurent
http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html
De toute évidence, une rupture du continuum espace-temps a produit une nouvelle séquence chrono-évènementielle entraînant l'émergence de cette réalité alternative
![Page 12: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/12.jpg)
Conccurence
LOGGER .info("Starting Master.run()");BlockingQueue<Runnable> queue = new
LinkedBlockingDeque<Runnable>();ExecutorService service = new ThreadPoolExecutor(MINIMUM_THREADS, MAXIMUM_THREADS, KEEP_ALIVE, KEEP_ALIVE_UNIT,
queue);
Map<String, Future<?>> calls = new HashMap<String, Future<?>>();for (String pack : packs) { calls.put(pack, service.submit(new Slave(pack).getRunnable())); LOGGER.info("Submitted pack = [" + pack + "]");}
for (String pack : packs) { LOGGER.info(">> Waiting for pack = [" + pack + "]"); try { calls.get(pack).get(); } catch (InterruptedException e) { LOGGER.severe(e.toString()); } catch (ExecutionException e) { LOGGER.severe(e.toString()); } LOGGER.info("<< Waited for pack = [" + pack + "]");}service.shutdown();LOGGER.info("Done Master.run()");
![Page 13: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/13.jpg)
Les API
java.net.Socket
http://download.oracle.com/javase/6/docs/api/java/net/Socket.html
A socket is an endpoint for communication between two machines.
Exemples joints.
![Page 14: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/14.jpg)
Les API
java.io.ObjectOutputStream
http://download.oracle.com/javase/6/docs/api/java/io/ObjectOutputStream.html
An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream.
![Page 15: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/15.jpg)
Les API
java.lang.reflect
http://download.oracle.com/javase/6/docs/api/java/io/ObjectOutputStream.html
La classe Class n'a pas de constructeur, mais la JVM n'est qu'un ClassLoader
Bootclasspath
![Page 16: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/16.jpg)
Les API
javax.xml
http://download.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html
Troll (wikipedia) Un troll est une action de nature à créer une polémique en provoquant les participants d’un espace de discussion. Le mot désigne également un utilisateur qui a recours à ce type d’action
Faites du SAX .. ou du StAX
![Page 17: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/17.jpg)
XML
InputStream stream = openUrl(source.getUrl());SAXParser parser = SAXParserFactory.newInstance().newSAXParser();parser.parse(stream, new DefaultHandler() {
private boolean insideItem = false;private boolean captureText = false;private StringBuilder texte = null;private String linkHref = null;private Map<String, String> textes;
@Overridepublic void startElement(String uri, String localName,
String qName, Attributes attributes) throws SAXException {if (ITEMS.contains(localName)) {
textes = new HashMap<String, String>();insideItem = true;
} if (CAPTURED.contains(localName)) { texte = new StringBuilder(); captureText = true; } if ("link".equals(localName)) { linkHref = attributes.getValue("href"); } super.startElement(uri, localName, qName, attributes); } // …}
![Page 18: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/18.jpg)
Les API
java.sql.Connection
http://download.oracle.com/javase/6/docs/api/java/sql/Connection.html
Write once, run anywhere ^^
PreparedStatement statement = connection .prepareStatement("SELECT * FROM PERSON WHERE LASTVIEW < ?");statement.setDate(1, yesterday);ResultSet result = statement.executeQuery();
![Page 19: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/19.jpg)
Java 2 - Technique
Les API Les librairies Best practices Exemples
![Page 20: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/20.jpg)
Les librairies
Les librairies classiques
Juste évidentesApache commons
Les plus utiliséesSpring, Hibernate
![Page 21: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/21.jpg)
Les librairies
Spring Hibernate Apache XStream
JUnit AspectJ CGlib
![Page 22: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/22.jpg)
Les librairies - Spring
Un conteneur IoC Un encapsulateur
Transactionnel Sécurité MVC
Vers OSGI ..Partiellement commercial
![Page 23: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/23.jpg)
Les librairies - Hibernate
SGBDO Persiste
Automatiquement
En cycle
Transactionnellement
Cascading CGlib Vers EJB3 ..Partiellement JBoss
![Page 24: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/24.jpg)
Les librairies - Apache
Commons lang
Commons IO
Commons Configuration
Commons Net
Struts ..
![Page 25: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/25.jpg)
Les librairies - XStream
Simple RésistantA good job ..
![Page 26: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/26.jpg)
Les librairies - JUnit
Deux fois plus de code ? Troll
Tester ? Non, j'écris tout d'une traite, et parfait !
Métaphore du grimpeur et du python
![Page 27: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/27.jpg)
Les librairies - JUnit
Coder les yeux fermés
Construire des exemples
Documenter les cas non passant
L'application a demandé une carte de trop parce que l'utilisateur Joe a triché sur le réseau.
![Page 28: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/28.jpg)
Les librairies - AspectJ
Librairie avancée Injection de code Logging Sécurité Transactionnalité Profiling
![Page 29: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/29.jpg)
Les librairies - CGlib
CGLib, BCEL, ASM Injection de code Runtime injection Tissage de proxy
Persistance Mock
![Page 30: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/30.jpg)
Java 2 - Technique
Les API Les librairies Best practices Exemples
![Page 31: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/31.jpg)
Best practices
The cathedral and the bazaar
La roue est inventéeDepuis les années 70
Arts martiauxReproduire avant d'inventer
![Page 32: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/32.jpg)
Best practices
Javadoc Logging Exceptions JUnit XP, IoC, ConcernRun, Right, Fast, Small
Singleton (yuk) Observer Visitor Test driven
![Page 33: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/33.jpg)
Best practices - Javadoc
Vous n'utilisez que des librairies connues et bien documentées
Faîtes de même Respectez-vous
![Page 34: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/34.jpg)
Best practices - Javadoc
70% du code Exemple
/** * Stream the proxy response
body to the user agent response output stream.
* * SubClasses SHOULD
override this method both for metadata gathering and
* for stream backup. * * @param request * The user agent
request * @param response * The user agent
response * @return An output stream * @throws IOException * Upon streaming
failure */
![Page 35: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/35.jpg)
Best practices - Logging
Plus jamais System.out.println(..) Utiliser logger.info(..) Utiliser [value] et overrider toString(..)
/** * Run. * * @param packs * The packs * @throws InterruptedException * Upon {@link Thread#sleep(long)} failure */ public void perform() throws InterruptedException { LOGGER.info("Starting Master.perform() for data = [" + data + "]"); new Slave(data).run(); LOGGER.info("Done Master.perform() for data = [" + data + "]");}
![Page 36: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/36.jpg)
Best practices - Exception
Ne pas hésiter à relancer les exceptions A minima, utiliser les finally Un cas non passant = un destinataire
Ex: Formattage de nombre
« On ne propage pas un bug »try { // At this point, the client ouput stream is opened
streamResponse(request, response, proxyRequest, proxyResponse); } finally { // The proxy socket must be closed // The client input stream is closed // The client ouput stream must be closed
closeQuietly(response.getOutputStream(), proxyConnection, proxySocket);}
![Page 37: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/37.jpg)
Best practices - JUnit
http://www.extremeprogramming.org/rules/testfirst.html
Coder les tests avant la méthode Capitaliser pour durer Un test est un exemple de bonne
utilisation de votre code
Ex: core.CheckListener.checked(Category, String)
![Page 38: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/38.jpg)
Best practices - IoC
Renier les Singleton et variables globales Si MyClass.foo(..) utilise Globals.VAR,
Injecter un argument supplémentaire ou Injecter un membre de classe supplémentaire
Ex: Les connections SQL et le multi-threading
![Page 39: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/39.jpg)
Best practices – Design Patterns
Depuis les années 70, les ordinateurs doublent de vitesse processeur tous les ans, doublent de capacité mémoire, quadruplent de capacité de communication
La vitesse des logiciels diminue de moitié tous les ans
Ne pas réinventer la roue – ou uniquement après l'avoir apprise
![Page 40: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/40.jpg)
Best practices – Design Patterns
Observer : dès qu'on voit le mot clé Listener
Ex: Barre de progression
![Page 41: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/41.jpg)
Best practices – Design Patterns
Visitor : de multiples explorations
![Page 42: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/42.jpg)
Anti-patterns
Vous en rencontrerez. Inventoriez-les. Elles vous disent dans quelle direction est l'autre ..
la bonne solution.
![Page 43: EPITECH 2012 sebastien@migniot.com Java. Java 1 - Introduction Rappel : Historique Machine virtuelle Plateformes et marché Tour de J2SE Tour de J2EE](https://reader035.vdocuments.us/reader035/viewer/2022062511/551d9d7d497959293b8b5355/html5/thumbnails/43.jpg)
Exemples
Conccurency Collections Unit testing Hibernate Aspect Profiling