Wednesday, December 11, 2013

Sunday, September 29, 2013

JEE 7: New features


  1. CDI 1.1
    1. Single point of control
    2. Default enabling, values: all(default),annotated, none
    3. attribute: bean-discovery-mode="all"
    4. CDI @Vetoed : vetos a bean/package
  2. Bean validation 1.1(JSR 349)
    1. improves semantic readability
    2. pre or post conditions are validated before/after constructor
    3. pre/post conditions on method/constructor
      1. e.g. Constructor:  public CardValidator(@NotNull Algorithm algorithm) {;}
  3. Interceptors(JSR318)
    1. @AroundConstructor
    2. @AroundInvoke(not new)
    3. @Priority -> prioritisation standard defined; some constants available in related class(Interceptor.Priority)
  4. Concurrency 1.0
    1. User threads
    2. Simple and advanced design patterns
    3. Default Managed Executer; custom executer can be defined in web.xml
    4. ManagedScheduleExecuter
      1. Submit delayed/periodic tasks
      2. Accessed through JNDI
    5. ManagedThreadFactory
      1. default is auto defined
      2. custom defined in web.xml
      3. Accessed through JNDI
    6. Dynamic proxy
      1. can create ruinable context proxies
  5. JPA 2.1
    1. Schema generation
      1. can declare scripts/ddl in persistence.properties, helps running a sql script on load of application
    2. @Index: allows to create indexes
    3. Unsynchronised persistence context
      1. SynchronizationType.UNSYNCHRONIZED(or SYNCHRONIZED)
      2. em.joinTransactions();
    4. Stored Procedures
      1. NamedStoredProcedureQuery
      2. NamedStoredProcedureParameter
    5. CDI injection into listeners.
    6. Support for multitenancy.
  6. JTA 1.2
    1. @Transactional(value=Transactional.txType.Required, rollbackOn={SQLException.class, JMSException.class},  dontRollbackOn=SQLWarning.class)
    2. @TransactionScoped: lifecycle limited to transaction
    3. can make normal pojos transactional using this annotation
  7. EJB 3.2
    1. passivationCapable
    2. @Asynchronous
    3. @Schedule has persistence = false
  8. JMS 2.0
    1. AutoCloseable
    2. MessageHandler(not new)
    3. JMS context API (JMSContext.class, ctx.createProducer(), ctx.createConsumer(),)
    4. JMSConnectionFactoryDefinition: to define a datasource for JMS messages
      1. JMSConnectionFactoryDefinition(name="", interfaceName="")
      2. JMSConnection EndPoint Definition(name="", interfaceName="") 
  9. Servlet 3.1
    1. Non-blocking I/O - checks read/write availability b4 actually doing it.
      1. ReadListener
      2. WriteListener
    2. Protocol Upgrade
      1. HttpUpgradeHandler
        1. init(WebConnection wc);
        2. destroy();
      2. Improved security
        1. <deny-uncovered-http-methods> : denies all non-secure accesses
  10. WebSocket 1.1
    1. full-duplex bi-directional communication over TCP
    2. annotated server endpoint @javax.websocket.seerver.ServerEndPoint(name="" value="" decoders="MyClass1.class" encoders="MyClass2.class") for server class and @OnMessage on respective method 
    3. usable with porous
    4. removed boilerplate code
    5. Lifecycle callbacks javax.websocket.OnOpen, etc
    6. Annotated client endpoint (@javax.websocket.ClientEndPoint)
    7. programmatic end points also available(any class extending EndPoint.class)
    8. Encoder/Decoder: custom classes extending Encoder/Decoder class
  11. EL 3.0
    1. stand-alone environment support: useful for batch
    2. ELProcessor
  12. JSF 2.2
    1. Faces Flow; @FlowScoped
      1. xxx/xxx/xx/webapp/flow/1.xhtml, 2.xhtml, 3.xhtml (1->2->3)
        1. these are cumulatively defined in flow-flow.xml (declarative)
        2. programatically can be done FlowScoped bean using @FlowDefinitioin
        3. without xml or FlowDefinition it works similar to JSF 2.1
    2. ResourceLibrary Contract
      1. META-INF/contracts/package1/css,js,template.xhtml
      2. META-INF/contracts/package2/css,js,template.xhtml
    3. pass through attributes p:type="email" -> type="email"
    4. h:inputFile for file upload, type Part.class
  13. JAX-RS 2.0
    1. New API to consume rest services
      1. Client, WebTarget, Invocation, Response (all .class)
    2. async client call supported(Future.class)
    3. Async server too
    4. Message filter ClientRequestFilter,ClientResponseFilter
      1. Entity Interceptors - intercept inbound/outbound stream
  14. JSONP 1.0
    1. Json builder, builder.createJsonOject().build(0; JsonOjlect.class JsonParser: to read Json object
  15. Batch processing
    1. chunk style processing => job.xml 
      1. <chunk>
      2. <reader
      3. <processor>
      4. <writer>
    2. Batchlet processing
    3. job/chunk/listeners
    4. Partition: split a job among multiple cores
    5. Creating workflows
  16. JavaMail 1.5
    1. @MailSessionDefinition
  17. JCA 1.7 Java connection architecture
  18. Default resources
    1. JMS connexion factory
    2. JNDI names 
Summary
CDI 1.1 (JSR 346) enables finer scanning control and the ability to veto the processing of a class or package. Bean Validation 1.1 (JSR 349) allows for method validation and the ability to pre/post conditions on method and constructors. Interceptors 1.2 (JSR 318) focused on the ability to associate an Interceptor associated with a constructor and the ability to prioritise interceptor bindings.
For Concurrency utilities 1.0 (JSR 236), the emphasis was on ManagedExecutor with a focus on:
* User threads in Java EE applications
* The ability to support simple and advance concurrency design patterns
* And to extend Concurrency Utilities API from Java SE (JSR 166y)
Further emphasis in concurrency was on ManagedThreadFactory and DynamicProxy.
Dynamic Proxy:
* Creates dynamic proxy objects, and adds contextual information available for applications running in Java EE environment
* It supports Classloading, JNDI, Security, …

Also covered as part of concurrency: ManagedExecutor
* User threads in Java EE applications
* Support simple and advance concurrency design patterns
* Extend Concurrency Utilities API from Java SE (JSR 166y)
– java.util.concurrent package

In addition: ManagedScheduledExecutor
* Managed version of ScheduledExecutorService
* Submit delayed or periodic tasks

For JPA 2.1 (JSR 338), standardized database schema generation and the ability to define additional indexes in schema generation were emphasized. JTA 1.2 (JSR 907) was praised for its capacity for transaction management on Managed Beans as a CDI interceptor binding; in addition, it offers CDI scope whose lifecycle is scoped to the currently active JTA transaction.

WebSocket and annotated server endpoint which enables full-duplex bi-directional communication over a single TCP connection.

JSON Builder creates an object model (or an array) in memory by adding elements. JsonParser is an event-based parser that can read JSON data from a stream.


javaOne 2013 Overview

1. Introduction to Java 8 and JVM
  • Project Nashorn implemented 
    • Implementing a light-weight high performance JavaScript runtime in Java with JVM
    • Enables embedding of javascript in java applications.
  • Transition in  technologies
    • Thick(Rich) client platforms
      • AWT -> Swing -> JavaFX
    • Rich Internet application(RIA) platforms
      • Servlets -> JSP -> JSF -> REST -> Web Sockets
    • Integration platforms
      • RMI -> CORBA -> SOAP -> JAXB
  • JavaFX
    • Lightweight and hardware accelerated Java UI platform
    • Components 
      • FXML: A XML based declarative markup language.
      • Controller
      • CSS
    • Code Binding
      • Method 1 : Input and output fields have unique Ids. On input in UI, it creates an instance of Controller and uses DI to link front inputs to controller variables through FXId
      • Method 2: Using javaScript on JVM, input field triggers an action in javaScript.
      • Method 3 :  Dynamic Binding(Listeners); binding is done through hashMethods(#animate, where animate() is in controller)
  • Java 8: Lambda Programming
    • Refer here

2. GlassFish Community : GlassFish 4.0
  • Java EE 7 support
  • JSR 353: Java API for JSON processing 
  • JSR 356: Java API for WebSocket
  • JSR 236: Concurrency Utilities
  • JSR 343: Java Message Service 2.0 (Simplified)
  • JSR 352: Batch applications support with a runtime for both scheduling and executing batch jobs
  • Annotated POJOs, less boilerplate code
  • Cohesive integrated platform
  • Servlet 3.1 NIO
  • FacesBean are riding towards deprecation, CDI beans are the standard. 
3. Keynote

  • Watch Keynote here..
  • JDK 8 download here..
    • Lambda programming
      • Parallelism in real sense
      • Less boilerplate code
      • Streams
      • Makes code more readable, easily writable, less error prone and compact
    • Date & Time API
    • Security updates
    • Project Nashorn
  • NetBeans 7.4 RC1
    • Debug javaScript on the fly
    • Emulators for actual device test
    • Support for iOS and Android development
  • Java ME 8 and Raspberry pi
    • Meet DukePad: DIY, Raspberry pi, Java ME 8 and JavaFX (DukePad wiki)
    •  
  • Beyond SE 8
    • Project Sumatra: Enables Java use on GPUs and APUs
    • Project Avatar Avatar here..
4. JEE 7 with PrimeFaces
  • Martin Fousek was awesome !!
  • JSF 2.2
    • HTML 5 support
      • New namespaces
      • JSF/JavaScript components
      • Control over rendered facelets
    • Resource Libraries Contracts
      • Each contract is a collection of templates, js, css and other resources
      • URL based definition within faces-config
      • static/dynamic view definition
      • Multi-templating
    • Developer productivity
    • Meets enterprise demands
    • Faces Flow
  • PrimeFaces
    • Open source component library
    • Zero configuration
    • Extensive theming and mobile components
    • Well documented
    • Active community support
  • Expression Language 3.0
    • Easy communication between presentation layer and application logic
    • Deferred or immediate evaluation of expressions
    • Easy method invocation
    • Standalone ELProcessor
    • Contcatenation, semicolon and assignment operators
    • Static collections,  Collection operations
    • Lambda Expressions
  • PrimeTime with PrimeFaces
    • Built-in Ajax with JSF 2.0 Ajax APIs
    • Client APIs on jQuery
    • Enterprise theming with Theme Roller(4.0 Sentinel)
      • Client side validation
      • Dialog framework
      • Tree Drag and drop
      • Deferred loading and more
  • JSF Scaffolding with PrimeFaces
    • Generation of CRUD skeleton fron database
    • database -> entity classes -> JSF pages 
      • NetBeans can generate JSPs or vanilla facelets
      • nbpfcrudgen plugin can generate Facelets with PrimeFaces
  • FacesFlow(@FlowScoped)
    • Reusable collection of screens with defined entry and exit points
    • CDI injected.
    • Java definition using flow builder(@FlowDefinition)
  • Annotation based component registration
    • Improved faces component interface
    • Eliminates needs for TLD file
    • @FacesComponent
  • File upload 
    • Servlet 3.0 multiple architecture
    • Standard component with/without AJAX requests
  • NetBeans IDE support
  • Sample code on GitHub(Code here)
5. JSF 2.2
  • New features 
  • Stateless JSF
    • States
      • UI component state: model and view state.
      • Persistence tier state: persistence solution
      • Model tier state: controller state.
    • Specification changes in Restore view phase.
    • Stateless views
      • Memory and performance advantages.
      • Ability to route request to any node in cluster.
      • Preventing view expired exceptions.
  • Resources
    • ResourceResolver has been merged with ResourceHandler and ResourceResolver is deprecated.
    • Resource Library resources : "contracts" directory(resource directory) containing templates, insertion points in templates, resources (css, js etc)
  • Faces Flow
    • Modularity behaviour to jsf.
    •  It has a special location in class path (META-INF/flow).
    • Application sub-module
    • Well defined entry and exit
    • I/O parameters
    • Flow scope
    • Pre and post handlers
    • ADF task flows 
      • Bounded task flows:
        A set of activities, control flow rules and managed beans that interact to allow a user to complete a task.
      • Unbounded task flows:
        It has a single entry point and zero or more exit points. It contains its own set of private control flow rules, activities, and managed beans
    • Spring web flow
    • Flow handler supports 5 new node types(7 types, 5 new) : method types that can be called from facelet
      • View nodes
      • Method call nodes
      • Switch nodes
      • Flow call nodes : redirection from methods to new flow
      • Return nodes: return methods
  • Pass-through attributes
    • From a Facelet, pass-through attributes can be set in 3 ways:
      • Via a Name-spaced attribute on the component tag
      • TagHandler f:passThroughAttribute that sets a single attribute
      • TagHandler f:passThroughAttributes that sets multiple attributes
  • Security/Type-safety
    • CSRF protection: client state encryption.
    • Type checking for composite component attribute
  • @FlowScoped: A CDI scope that causes the runtime to consider classes with this annotation to be in the scope of the specified flow; A flow scoped bean is thus a bean that can be used to back a flow instead of just a single view (page)
  • CDI compatible @ViewScoped
  • Facelets Component tag declared via annotation(@ FacesComponent).
6. Programming with Lambda 
  • Benefits
    • Code clarity
    • Less errors
    • Parallelisation
  • Iterations
    • External iterators -> Internal iterators
    • Imperative style -> Functional style
  • Composing with lambda expressions
    • Imperative codes are mutable
    • TRIE data structure: good data structure for building memory efficient dictionary with ast lookup.
    • Declarative/Functional style using lambdas 
  • Sample code to double first even number after 3 using lambdas in java in composed method pattern
    • System.out::println(numbers.stream() // Stream operations are lazy
                        .filter(ClassName::isGreaterThan3) // all are inline private methods
                        .filter(ClassName::isEven)  // filters are subsets of input
                        .map(ClassName::doubleInt)
                        .findfirst()); 
  • Streams in Top gear
    • Stream 
      • An abstraction for aggregate computations on a data set. 
      • It is not a data structure.
      • It can be of infinite length
      • Fusing, laziness and parallelism supported
      • Filter and map are Lazy operations
      • Terminal operations execute the stream pipeline
      • Stream pipeline behave like builders
      • Code re-use is leveraged by using streams
      • Sum, min, max, count are cases of reduction operation
      • Reduces elements to a single summary value using a  combining function
      • Reduction is mutable
      • Sample => filter().map().sum()
        filter and map don't actually do any operation, they just set intermediately operations in stream pipeline
    • Stream source 
      • Collection.stream(), Collection.parallelStream()
      • Arrays.stream()
      • Spliterators(Spliterator.class)
      • Arrays and IntStream have best decomposability
    • Parallel Streams
      • Deterministic
      • Better use of multiple cores
      • Parallel pipeline is composite of many sequential pipelines
      • More work, less time 
      • Concurrent invocation
      • Built on fork-join tasks 
      • Performance: not always faster