Friday, June 21, 2013

Spring property file loader


SPring Hibernate


Spring vs EJB


Spring : AspectJ Annotation


Spring : Transaction Managament

Programatic vs Declarative


why people choose Declarative

Spring : Event Handling


Spring : Types of Advice

  • Before advice – Run before the method execution
  • After returning advice – Run after the method returns a result
  • After throwing advice – Run after the method throws an exception
  • Around advice – Run around the method execution, combine all three advices above.

1. Before advice

implements MethodBeforeAdvice
public void before(Method method, Object[] args, Object target)

 

 id="" 
                 class="org.springframework.aop.framework.ProxyFactoryBean">
 
   name="target" ref="customerService" />
 
   name="interceptorNames">
   >
    >interceptor name
> > > >
 

2. After returning advice

implements AfterReturningAdvice
public void afterReturning(Object returnValue, Method method,
  Object[] args, Object target) throws Throwable {
 
 

3. After throwing advice

public class HijackThrowException implements ThrowsAdvice  
public void afterThrowing(IllegalArgumentException e) throws Throwable

4. Around advice

public class HijackAroundMethod implements MethodInterceptor
Object result = methodInvocation.proceed(); 

 

 

 
 

 

Spring : AOP terminologies

What is AOP


Aspect


Advice

Pointcut

Join Point



Spring : Bean Post Processor / Bean Factory Post Processor


Spring : Life Cycle callbacks


Spring : Bean Defintion Inheritance


Spring : Application Context Aware


Spring Bean Scopes


Wednesday, June 12, 2013

Spring - AutoWiring

Auto wiring how you want to relate the dependencies in spring xml file
1) Default

2)By Name

3) By Type

4)Constructor

5)Auto-Detect:
autowire="autodetect" dependency-check="objects />


Spring - Ambiguities in Constructor Dependency Injection

IF you are using constructor injection sometimes you need to explicitly specify data type along with constructor arguments as spring converts values like 120, 245 from String to int.
Hence add type property to constuctor-arg tag


188

Spring - Multiple Spring xml files

If you have modules in your code or if you want to break your large spring xml in smaller parts



or you can use @import in HelperClass
@Configuration

@Import({ CustomerConfig.class, StaffConfig.class })

Declare Beans
@bean and name attribute to declare beans




Spring Interview Questions

Spring Interview Questions

Spring - A normal Spring appliation

You will have a interface like
public interface Vehicle{
   public void noOfWheels();
}

You will have classes implementing the interfaces
public class Car implement Vehicle{
 public void noOfWheels(){

}
}
public class Truck implement Vehicle{

public void noOfWheels(){


}

}

A Helper  Class

public class transport {
1)Vehicle vehicle;
2)setter for vehcile
public wheel(){
vehicle.noOfWheels();
}

}
A Calling Class
public class SpringDemo{

ApplicationContext app = new ClassPathApplicationContext ("spring.xml");
Transport transport= (Transport )app.getBean("transport");
transport.wheel();
}

Spring configuration file










Spring - Advantages and features of Spring

1)Ligtweight, less overhead
2)Spring IOC
3)Loose coupling
http://javaqafaq.blogspot.in/2013/06/spring-normal-spring-appliation.html
Here in this example tomorrow if apart from car or truck , you want to introduce new vehicle say Bus.
You just need to add the interface and make changes only to Spring.xml
4)Good integration with ORM tool like Hibernate, Ibatis
5)Good integration with Struts and Struts framework which are widely used in industry.

Spring - Modules in Spring

Spring - Types of Dependency Injection

Constructor Injection
The Helper class should have a Constructor







Setter Injection

The helper class should have a setter which will be set in spring.xml






Spring - Dependency Injection / Inversion of Control

Dependency Injection or Inversion of control means giving the control or task of injecting dependencies i.e object creation to the container. Instead of creating objects in code let container handle it for you.
In spring, you can have a normal xml file where you declare all your objects and services and which services are required by which object inside the xml. The Spring container will wire them and create those objects for you.

Sunday, June 2, 2013

What is IOC.

Inversion of Control or Dependency Injection means passing on the control to Spring container.
In IOC, the objects are not created in code but it is described in a configuration file, how the objects are to be created. the container takes the responsibilty

Inner Classes

Anonymous Inner Class
Static Inner Class
Inner Class

Collections Interview Questions

IdentityHashMap
CopyOnWriteArrayList
ConcurrentHashMap

Saturday, January 26, 2013

Singleton in Java

Singletion , usage , example, how to use.Enum Singleton

New features of Java 1.5


Enum in Java


How does a map work in java


Memory in Java

Stack memory
object itself : encapsulation

Heap Memory
variables of objects : encapsulation

Context Memory

static variables are placed in seperate memory called context memory hence no need to create variables/instances or objects to access static variables

Monday, January 21, 2013

Static in Java

Static in Java

Static variables and their use


Static methods and their use


Static Class and their use


Static Block

Final in Java

Final means immutable. Final classes cannot be inherited or instantiated. Final methods cannot be overriden and final variables cannot be changed

Final Classes and use
Final classes is a perfect class where nothing needs to be modified , changed , anything need not be added or deleted from the class. for e.g String class in java is final. We cannot override any methods from string class or instantiate the class.

Final Variables and use
Final variable can be used to declare constants which cannot be modified ever. To declare constants like PI. Final variables are read only.

Final methods and use

Final methods cannot be overriden. If you think you have written perfect method or if u dont want to change the method functionality and it should remain same for all the subclasses method should be made Final

Advantages
1) Final methods, variables are faster as they are cached by JVM at compile time
2) In multithreaded environment they are safe and overhead is avoided w/o using synchronization.