Posts

Showing posts from March, 2012

Concurrency in Java

Process: A process runs independently and isolated of other processes. It cannot directly access shared data in other processes. The resources of the process are allocated to it via the operating system, e.g. memory and CPU time. Threads: threads are so called lightweight processes which have their own call stack but an access shared data. Every thread has its own memory cache. If a thread reads shared data it stores this data in its own memory cache. Threads exist within a process — every process has at least one. Threads share the process's resources, inclu

Core - Java Notes

1. Normal printing of the hashcode will print the Class Name and @hexadecimal value which is default. Inorder to get a custom String on printing the object then override the toString() Method. 2, String and Wrapper class overrides the equals method so that comparison is the same. 3. if we dont override the equals method then the objects wont work properly in sets and cant be used as keys in hashtable. 4.it is possible to use an object as a key in a hashtable but the objects equals property should be overridden else we will never be able to create that key as every object creation will create a seperate hashcode. 5.HashCodes are typically used to increase the perfomance of large large collection of data. 6. in real life hashing also it is not required that one bucket contains only 1 value one bucket can have 2 values with identical hashcode so retrieving froma hashing set is a 2 step process. 1. Find the right bucket and use equals operator. 7. If 2 objects are equal the

Why Spring Over EJB?

1. EJB is Complicated - To implement any functionality we need to touch at least 4 files business Interface,Home Interface,Beans and Deployment Descriptor.However with Spring it works on POJO and can use AOP for further services. 2. EJB is Invasive - In order to implement an interface in EJB we need to use Javax.ejb interface.There is a tight coupling with the EJB and code always requires an EJB container for it to work.however in the case of Spring there is no such direct dependancy on Spring code. 3. Entity Ejb's are not as mature as the ORM frameworks avaliable like Hibernate etc.Spring provides an excellent integration with these ORM frameworks.

Spring AOP

An Enterprise Application has many components and each performing its own function.Some times one component has to perform the function of another like logging,Security,transaction Management all goes into different component to manage.These are called Cross cutting Concerns as they cut into other functionality. AOP Helps us to make these functionalists a different layer and these layer can be applied declaratively.So we add an Aspect to a functionality whose responsibilty is to do its job. The Acegi security system uses Spring’s AOP support as the foundation of a framework that adds declarative security to Spring-enabled applications

File Not Found Exception

banging the head trying to find why the file is not loaded even after adding to classpath. The Simple thing to do is Add the below lines so that the system shows where the classpath location it is trying to access. File file = new File("file.txt"); System.out.println(file.getCanonicalPath());