Tech Rocks

Coldfusion
Java
JQuery

An online resource for latest web technologies like Coldfusion, JRun, Pro*C, JQuery, HTML5, PHP, W3C, Java, J2EE, C, C++, ORACLE, PL/SQL, MySql, Ajax, Coldbox, Fusebox, UNIX, JavaScript, NodeJS and much more... contact@tech-rocks.org

Tuesday, October 22, 2013

Open source in-memory data grid vs Oracle Coherence

Hazelcast is the leading open source in-memory data grid it provides java developers an easy-to-use and powerful solution for data distribution that can be used as a clustering solution, a distributed cache and a NoSQL key-value store. For Enterprise customers needing hundreds of nodes of distributed in-memory computing, our off-heap elastic memory provide highly scalable, highly available, low latency and highly predictable clustered memory and distributed computing.

 

Click here for more info

Spring JSR-250 Annotations

Spring has JSR-250 based annotations which include @PostConstruct, @PreDestroy and @Resource annotations.

  • @PostConstruct: This annotation can be used as an alternate of initialization callback.

  • @PreDestroy: This annotation can be used as an alternate of destruction callback.

  • @Resource : This annotation can be used on fields or setter methods. The @Resource annotation takes a 'name' attribute which will be interpreted as the bean name to be injected. You can say, it follows by-name autowiring semantics.

Spring Bean Auto wiring

The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory without using <constructor-arg> and <property> elements.

 

The autowiring functionality has five modes which can be used to instruct Spring container to use autowiring for dependency injection:

  • no: This is default setting which means no autowiring and you should use explicit bean reference for wiring. You have nothing to do special for this wiring. This is what you already have seen in Dependency Injection chapter.

  • byName: Autowiring by property name. Spring container looks at the properties of the beans on which autowire attribute is set to byName in the XML configuration file. It then tries to match and wire its properties with the beans defined by the same names in the configuration file.

  • byType: Autowiring by property datatype. Spring container looks at the properties of the beans on which autowire attribute is set to byType in the XML configuration file. It then tries to match and wire a property if its type matches with exactly one of the beans name in configuration file. If more than one such beans exist, a fatal exception is thrown.

  • constructor: Similar to byType, but type applies to constructor arguments. If there is not exactly one bean of the constructor argument type in the container, a fatal error is raised.

  • autodetect: Spring first tries to wire using autowire by constructor, if it does not work, Spring tries to autowire by byType.

  •  

    Limitations of autowiring are:

  • Overriding possibility: You can still specify dependencies using <constructor-arg> and <property> settings which will always override autowiring.

  • Primitive data types: You cannot autowire so-called simple properties such as primitives, Strings, and Classes.

  • Confusing nature: Autowiring is less exact than explicit wiring, so if possible prefer using explicit wiring.

  •  

    Annotation wiring is not turned on in the Spring container by default. So, before we can use annotation-based wiring, we will need to enable it in our Spring configuration file by configuring <context:annotation-config/>.

     

    Note: null and empty string values can be injected in Spring

    Inject Java Collection in Spring

    Spring offers four types of collection configuration elements which are as follows:

    • <list>: This helps in wiring i.e. injecting a list of values, allowing duplicates.

    • <set>: This helps in wiring a set of values but without any duplicates.

    • <map>: This can be used to inject a collection of name-value pairs where name and value can be of any type.

    • <props>: This can be used to inject a collection of name-value pairs where the name and value are both Strings.

    Spring Bean Lifecycle

    • Instantiate - First the spring container finds the bean's definition from the XML file and instantiates the bean..

    • Populate properties - Using the dependency injection, spring populates all of the properties as specified in the bean definition..

    • Set Bean Name - If the bean implements BeanNameAware interface, spring passes the bean's id to setBeanName() method.

    • Set Bean factory - If Bean implements BeanFactoryAware interface, spring passes the beanfactory to setBeanFactory() method.

    • Pre Initialization - Also called postprocess of bean. If there are any bean BeanPostProcessors associated with the bean, Spring calls postProcesserBeforeInitialization() method.

    • Initialize beans - If the bean implements IntializingBean,its afterPropertySet() method is called. If the bean has init method declaration, the specified initialization method is called.

    • Post Initialization - If there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.

    • Ready to use - Now the bean is ready to use by the application.

    • Destroy - If the bean implements DisposableBean , it will call the destroy() method .

    Spring Container - configuration metadata

    There are following three important methods to provide configuration metadata to the Spring Container:

    • XML based configuration file.

    • Annotation-based configuration

    • Java-based configuration

    Spring Bean

    The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions.

     

    The bean definition contains the information called configuration metadata which is needed for the container to know the followings:

    • How to create a bean
    • Bean's lifecycle details
    • Bean's dependencies

     

    When defining a <bean> in Spring, you have the option of declaring a scope for that bean. For example, to force Spring to produce a new bean instance each time one is needed, you should declare the bean's scope attribute to be prototype. Similar way if you want Spring to return the same bean instance each time one is needed, you should declare the bean's scope attribute to be singleton.

     

    The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext.

    • singleton: This scopes the bean definition to a single instance per Spring IoC container.
    • prototype: This scopes a single bean definition to have any number of object instances.
    • request: This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
    • session: This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
    • global-session: This scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.

    The default scope of bean is Singleton for Spring framework and No, singleton beans are not thread-safe in Spring framework.

     

    Inner beans in Spring

    A <bean/> element inside the <property/> or <constructor-arg/> elements defines a so-called inner bean. An inner bean definition does not require a defined id or name; the container ignores these values. It also ignores the scope flag. Inner beans are always anonymous and they are always scoped as prototypes.

     

    To add a bean in spring application

    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="helloWorld" class="com.jeetu.HelloWorld">
    <property name="message" value="Hello World!"/>
    </bean>

    </beans>

    Spring Bean Factory vs ApplicationContext

    • Application contexts provide a means for resolving text messages, including support for i18n of those messages.

    • Application contexts provide a generic way to load file resources, such as images.

    • Application contexts can publish events to beans that are registered as listeners.

    • Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context.

    • The application context implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable.

    Spring ApplicationContext

    The three commonly used implementation of 'Application Context' are as below:

    • FileSystemXmlApplicationContext: This container loads the definitions of the beans from an XML file. Here you need to provide the full path of the XML bean configuration file to the constructor.

    • ClassPathXmlApplicationContext: This container loads the definitions of the beans from an XML file. Here you do not need to provide the full path of the XML file but you need to set CLASSPATH properly because this container will look bean configuration XML file in CLASSPATH.

    • WebXmlApplicationContext: This container loads the XML file with definitions of all beans from within a web application.

    XmlBeanFactory class

    The most commonly used BeanFactory implementation is the XmlBeanFactory class. This container reads the configuration metadata from an XML file and uses it to create a fully configured system or application.

    Spring IOC Containers

    There are two types of IoC containers:

    • Bean Factory container: This is the simplest container providing basic support for DI .The BeanFactory is usually preferred where the resources are limited like mobile devices or applet based applications

    • Spring ApplicationContext Container: This container adds more enterprise-specific functionality such as the ability to resolve textual messages from a properties file and the ability to publish application events to interested event listeners.

    Aspect-oriented programming - AOP

    Aspect-oriented programming, or AOP, is a programming technique that allows programmers to modularize crosscutting concerns, or behavior that cuts across the typical divisions of responsibility, such as logging and transaction management. The core construct of AOP is the aspect, which encapsulates behaviors affecting multiple classes into reusable modules.

    Benefits of IOC

    • Minimizes the amount of code in your application.

    • Makes your application easy to test as it doesn't require any singletons or JNDI lookup mechanisms in your unit test cases.

    • Loose coupling is promoted with minimal effort and least intrusive mechanism.

    • IOC containers support eager instantiation and lazy loading of services.

    Spring Dependency Injection Concept

    This concept says that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (the IOC container) is then responsible for hooking it all up.

     

    2 Types:

     

    • Constructor-based dependency injection: Constructor-based DI is accomplished when the container invokes a class constructor with a number of arguments, each representing a dependency on other class.

    • Setter-based dependency injection: Setter-based DI is accomplished by the container calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.

     

    Since you can mix both, Constructor- and Setter-based DI, it is a good rule of thumb to use constructor arguments for mandatory dependencies and setters for optional dependencies. Note that the use of a @Required annotation on a setter can be used to make setters required dependencies. The Spring IoC creates the objects, wire them together, configure them, and manage their complete lifecycle from creation till destruction. The Spring container uses dependency injection (DI) to manage the components that make up an application.

    Spring Modules

    • Core module

    • Bean module

    • Context module

    • JDBC module

    • ORM module

    • Expression Language module

    • OXM module

    • Java Messaging Service(JMS) module

    • Transaction module

    • Web module

    • Web-Servlet module

    • Web-Struts module

    • Web-Portlet module

    Spring Framework Benefits

    • Lightweight: Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 2MB.

    • Aspect oriented (AOP): Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.

    • Exception Handling: Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.

    • Container: Spring contains and manages the life cycle and configuration of application objects.

    • MVC Framework: Spring's web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over engineered or less popular web frameworks.

    • Transaction Management: Spring provides a consistent transaction management interface that can scale down to a local transaction (using a single database, for example) and scale up to global transactions (using JTA, for example).

    • Inversion of control (IOC): Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.

    Friday, October 18, 2013

    Thursday, October 10, 2013

    Tuesday, October 8, 2013

    Google Web Designer Tool

    Create engaging, interactive HTML5-based designs and motion graphics that can run on any device.

    gwt

    Check this link