210 likes | 429 Vues
A proactive approach to programming . An Architect’s Perspective. Roadmap. Recommendations for Smart Programming. Java Programming Working alongside Spring QA. What ?. Intelligence. Smart. Smart Skills - Programming. Effective Programming Jargons. Accurate Brick Better Design
E N D
A proactive approach to programming An Architect’s Perspective
Roadmap Recommendations for Smart Programming • Java Programming • Working alongside Spring • QA
What ? Intelligence Smart
Smart Skills - Programming Effective Programming Jargons • Accurate Brick • Better Design • Performance • Multi-threading • Security • Design Patterns
Smart Skills - Accurate Bricks • Identify - Start Line • Automatic Build (Ant, Maven), Log Monitoring • Identify- End Line • Unit Testing, JUnit, Functionality Validation Tests
Smart Skills - Better Design • Type safety (Generics) • Enforcing encapsulation • Simplifying adaptation to interfaces • Design patterns • Flexibility, OOD, Strategy, Singleton, Composite, Factory, Inversion of control • Exception Handling • Framework or guidelines
Smart Skills - Performance • Measuring performance • Applying performance profiling tools for response time, load and stress, and identification of performance bottlenecks • Strategies for improving performance • GC, JVM settings, NIO, Reordering loops • Effective use of the Collections API • Identify weak references, best collection classes
Smart Skills - Multi-threading • Improving response time by parallelization • Thread-safe, avoiding deadlocks • Improvising a threaded application • Synchronization & Data Sharing • Managing the performance implications of synchronization
Smart Skills - Security • Handle with care • Secure coding in Java • Programming defensively • Authentication and authorization • Applying role-based security • Restricting access to protected resources • Establishing security policies
Smart Skills – Design Patterns • Limiting the impact of changes • Centralizing properties using Singleton • Inserting transparent behavior with Proxy • Wrapping external libraries using Adapter • Modern design patterns • Inverting control (IoC) through bean factories • Injecting behavior with aspects • Adding scripting abilities to an application • Scripting end-user behavior
Smart Skills – Alongside Spring Spring Programming Jargons • Spring Core • Data Layer • XML Configuration
Smart Skills – Spring Core • Using Spring’s “Bean Container” nature and Dependency Injection. • Spring will act as a real container of Beans and creates bean instances at the time of requirement • Prefer ApplicationContext over BeanFactory • Once at start time or at time of instantiation • Prefer setter-based dependency injection over constructor-based dependency • Strong Vs Weak dependency • Singleton beans and Prototype beans
Smart Skills – Spring Core (Contd.) • Aspect Oriented Programming in the necessary situations • Spring AOP and AspectJ AOP • Comparison • Declarative caching services for Spring • Example • Text Search • Lucene only· Compass/Lucene· Hibernate Search/Lucene
Smart Skills – Spring Core (Contd.) • Configuring Spring Application context for different locations • Prefer static pointcut over dynamic • Dynamic are slower to evaluate • Use regular expression advisors to fine tune interceptor scope • Aware of thread safe issues with AOP advice • Example
Spring AOP Vs AspectJ AOP Pro Con • Spring AOP doesn’t require any special java compiler or special build process. AspectJ requires special compiler. • Different advice could be applied to different instance of the same class. This is not possible with AspectJ. • Target object is not modified. AspectJmodiefies target object behavior. • Spring AOP can not be applied to final methods. Spring generates subclass of the target class and weave advuce around overriden method. • Spring only supports method joinpoints. AspectJ and JBoss AOP supports field joinpoints as well. • Targets are not proxied which means that the method calls on this object is not advised. • Lazy initialization of Spring Beans
Smart Skills – Declarative Caching <bean id="customerDaoTarget“ class=“dao.CustomerDao” /> <coherence:proxy id="customerDao" refId="customerDaoTarget“> <coherence:cachingmethodName="load" cacheName="customerCache" /> <coherence:flushingmethodName="update" cacheNames="customerCache" /> </coherence:proxy> <bean id="customerManager“ class=“business.CustomerManager" /> <property name="customerDao" ref="customerDao" /> </bean>
Smart Skills – AOP Advice public class CountingMethodAdvice implements MethodInterceptor { // The next serial number to be assigned private static long nextSerialNum = 0; private static ThreadLocalserialNum = new ThreadLocal() { protected synchronized Object initialValue() { return new Long(nextSerialNum++); } }; private static long getCount() { if(serialNum!=null){ return ((Long) (serialNum.get())).longValue(); } } public Object invoke(MethodInvocationmethodInvocation) throws Throwable { System.out.println(”This method is called ” + getCount + ” times”); } }
Smart Skills – Data Layer • Prefer to use apache Connection pooling bean (commons.apache.org/dbcp) • Handling Exceptions • Prefer to use Springs Declarative Transaction Capability • Transaction Attribute Settings • Better to perform unit testing in the DAO layer
Smart Skills – XML Configuration • Avoid using spring’s ‘autowiring’ • Use shortcut forms • Prefer type over index for constructor argument matching • Reuse bean definitions, if possible • Prefer assembling bean definitions through ApplicationContext over imports
Smart Skills – Advantages • Spring Provides Better Leverage • Spring Enables POJO Programming • Dependency Injection Helps Testability • Inversion of Control Simplifies JDBC • Spring‘s Community Thrives