Skip to main content

Posts

Showing posts from January, 2011

How to sort an ArrayList using Collections class in Java

The ArrayList class does not have any method to sort the objects stored in it.So we have can use java.util.Collections.sort(aList); where aList is an ArrayList instance. But the question arises as to how the sorting is being done by the sort method of Collections class in Java. If one looks at the code of sort method of Collections class in Java API then we can see the following code: 1 2 3 4 5 6 7 8 9 public static void sort(List list) {     Object a[] = list.toArray();     Arrays.sort(a);     ListIterator i = list.listIterator();     for ( int j= 0 ; j< a.length; j++) {        i.next();        i.set(a[j]);     } } The sort method of Arrays class is being called so we see the code for sort method in the Arrays class: ?

How to initialize variables in Java?

Initializing your variables to proper value is must because it pays you better to initialize your variables properly while declaring them. If you don't initialize the variables then either they will cause compiler error or will be initialized with default values. Getting a compiler error for uninitialized variable is better because it will result in making you properly initialize your variable but if you are careless then you may initialize your variables to null to avoid the compiler error. The variables which will result in compiler error are method local and final variables. The problem with null initialized variables is that they will cause NullPointerException if you forget to initialize them even by the time you try to access them. The biggest issue here is that the JVM does not point out the variable which is Null. You need to debug your Java application to be able to find the variable which caused NullPointerException.

What is Aspect-oriented programming in Spring and its benefits compared to other J2EE technologies

AOP is a programming technique adopted in spring framework to allow programmer to modularize crosscutting issues like logging and transaction management. In a typical oops development approach programmer usually implements logging functionality by putting logger statements in all your methods of Java classes. In an AOP approach one can instead modularize the logging services and apply them declaratively to the components that required logging.

What is Inversion of control concept of Spring Framework

The basic concept of the Inversion of Control pattern (dependency injection) is that programmers don’t need to create your objects but describe how they should be created. 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 (in the case of the Spring framework, the IOC container) is responsible for all this. In a IOC scenario, the container creates all the objects, connects them together by setting the necessary properties, and determines when methods will be invoked. The implementation pattern types for IOC used by SpringFramework are as follows: ·          Dependencies can be assigned through JavaBeans properties (setter methods). ·          Dependencies are provided as constructor parameters and are not exposed as JavaBeans Setter properties.

What are Different Web Services Technologies and Tools

There are a variety of tools available for the Web Services. Microsoft Has C# as the development language for Web services and .NET framework. Sun Microsystems has JAX/RPC (Java API for XML Remote Procedure Calls) and JAXR (Java API for XML Registries). IBM also has Web Services Toolkit (WSTK), WSDL Toolkit, and Web Services Development Environment (WSDE). Apache Axis is an implementation of the SOAP ("Simple Object Access Protocol")