JavaONE 2007 - Kjartan Aanestad (Objectware)1 JavaONE 2007.

of 21/21
javaONE 2007 - Kjartan Aanestad (Objectware) 1 JavaONE 2007
  • date post

    30-Dec-2015
  • Category

    Documents

  • view

    218
  • download

    0

Embed Size (px)

Transcript of JavaONE 2007 - Kjartan Aanestad (Objectware)1 JavaONE 2007.

  • javaONE 2007 - Kjartan Aanestad (Objectware)*JavaONE 2007

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)AgendaReverse Ajax - DWRGlassFish V3Effective Java Reloaded: This Time it's NOT for Real

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Reverse Ajax - DWRJoe Walker/Geert Bevin (TS-6410)New feature in DWR 2.0CommunityOne: ICEfaces and Ajax Push

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Reversed Ajax DWR:OverviewThe ability to asynchronously send data from a web-server to a browser

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Reversed Ajax DWR:OverviewSupports 3 methods of pushing the data to the browser:Polling Browser makes regular request to the serverPiggyback Puts the response with the next requestComet (aka Long lived http) Keeps the communication channel open to pass down information when time comes.

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Reversed Ajax DWR:live coding demo

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)GlassFish V3Jerome Dochez (TS-6503)Loosely based on the work for JSR 277 (Java Module System ) Due in Java SE 7Architecture based on IoC, modules and maven 2

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)GlassFish V3:Module subsystemThe module subsystem is called HK2 (Hundred Kb Kernel)Module system based on mavenIdentified by name and versionOne classloader per module of 1 to n jarsExports a subset of its content (Service Provider Interface)Imports other modules (listed in manifest file)

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)GlassFish V3:Module instancesModules identified by module instances at runtime2 classloaders (public/private)Runtime network of class loaders

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)GlassFish V3:RepositoryRepositories hold modulesAdd and remove at runtimeDifferent types supportedDirectory basedMavenModules can be added/removed/updated from repositories

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)GlassFish V3:BootstrappingModule subsystems can bootstrap itselfNo need to define a classpath at invocationPackaged in a jarImplement the ApplicationStartup interfaceDeclare dependencies in manifest

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)GlassFish V3:Build System: MavenEach module is build from a maven project (pom.xml) com.sun.enterprise.glassfish gf-web-connector 1.2.1 hk2-jar Running GlassFish retrieves the modules from the maven repository $ mvn gf:run

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)GlassFish V3:ServicesGlassFish V3 use extensively Services to identify extension points likeApplication containers like web-app, Jruby, Phobos..)Administrative commandsServices in V3:Interfaces are declared with @ContractImplementations are declared with @[email protected] interface AdminCommand {...} @Service(name=deploy)public class DeployCommand implements AdminCommand {...}

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Effective Java Reloaded: This Time it's NOT for RealJoshua Bloch (TS-2689)Effective Java still hasnt been reloaded - It will be done later this year for sure..Object creationGenerics

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Effective Java Reloaded: Object creationStatic factoriesMap m = new HashMap(); Map m = HashMap.newInstance();Regrettably HashMap has no such method (yet)write your own, your generic classes can and should:public static HashMap newInstance() { return new HashMap();}

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Effective Java Reloaded: Object creationBuilder patternUgly when constructors have many optional parameters new NutritionFacts(int servingSize, int servings, int calories, int fat, int sodium, int carbohydrate, 15 more optional params!); Builder constructor takes all required paramsOne setter for each optional parameterSetter returns the builder to allow for chainingNutritionFacts locoCola = new NutritionFacts.Builder(240, 8).sodium(30).carbohydrate(28).build();

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Effective Java Reloaded: Object creationpublic class NutritionFacts { public static class Builder { public Builder(int servingSize, int servings) { this.servingSize = servingSize; this.servings = servings; } public Builder calories(int val) { calories = val; return this; } ... // 15 more setters

    public NutritionFacts build() { return new NutritionFacts(this); } }

    private NutritionFacts(Builder builder) { .. }}

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Effective Java Reloaded: Generics bounded wildcardsUse bounded wildcards to increase applicability of APIs

    public interface Shop { void buy(int numToBuy, Collection myColl); void sell(Collection myLot);}Collection subtyping doesnt work!public interface Shop { void buy(int numToBuy, Collection

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Effective Java Reloaded: Generics wildcard captureControl Wildcard-CaptureType system doesnt know captured types are identical

    public static void rotate(List list) { if (list.size() == 0) return; list.add(list.remove(0));}Solution:public static void rotate(List list) { rotateHelper(list);}// Generic helper method captures wildcard onceprivate static void rotateHelper(List list) { if (list.size() == 0) return; list.add(list.remove(0));}

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • *javaONE 2007 - Kjartan Aanestad (Objectware)Effective Java Reloaded: Generics miscellaniafinal is the new privateMinimizes mutabilityClearly thread-safeone less thing to worry aboutUse the @Override annotation every time you want to overrideAvoid overriding my mistake

    javaONE 2007 - Kjartan Aanestad (Objectware)

  • javaONE 2007 - Kjartan Aanestad (Objectware)*JavaONE 2007Kjartan Aanestad - Objectware

    javaONE 2007 - Kjartan Aanestad (Objectware)

    **-CommunityOne mandagen (NetBeans, Glassfish, OpenJDK, OpenSolaris)-*DWR 2.0 releasa rett fr javaone*** Shoot and chat live chate og resultater Koda i form av pasting av kode Ble hacka av folk i salen* Jerome Dochez startet med et par GlassFish V3 demoer. Kjapp oppstart (under 1 sekund) Deployet flere applikasjoner inkludert PHP, Rails og standard web app * HK2 liten og kjapp (100 - Max memory footprint (in KB) for the GlassFish v3 kernel) De var fornyd med mavens module tankegang funker bra Hadde noen innvendinger mot maven uten at han gikk inn i detaljer, men alt i alt fornyd med bruke maven Hver modul har sin egen classloader Kan importere andre moduler* Modules have a list of other modules class loaders to load imported classes Garbage collection happens when all references to the public class loader are released

    **The module subsystem can bootstrap itself. There is no need to define a classpath at invocation, the application startup code is packaged in a Java Archive file. The application code that implements the ApplicationStartup interface is treated as a bootstrapper. It is this marker that permits the module system to load the module during initialisation. ***Some of the new material presented in the talk/session*-Static factories Trenger ikke opprette nytt object for hver gang (valueOf) De har navn Fleksible i den forstand at de kan returnere et objekt av hvilken som helst subtype Type inference*-Static factories Trenger ikke opprette nytt object for hver gang (valueOf) De har navn Fleksible i den forstand at de kan returnere et objekt av hvilken som helst subtype Type inference*-Static factories Trenger ikke opprette nytt object for hver gang (valueOf) De har navn Fleksible i den forstand at de kan returnere et objekt av hvilken som helst subtype Type inference*public class Shop { void buy(int num, Collection