Posts

Java Performance

How to check the Memory used by Java class CheckMemory{ public static void main(String[] a) { Runtime rt = Runtime.getRuntime(); System.out.println(" Free memory: " + rt.freeMemory()); System.out.println("Total memory: " + rt.totalMemory()); while (true); } } To cehck its usage at Client and Serverside run them like:- Client Side - JVM Usage:- C:\>\progra~1\java\jdk1.6.0_02\bin\java LongWhile Free memory: 4997088 Total memory: 5177344 ServerSide JVM usage:- C:\>\progra~1\java\jdk1.6.0_02\bin\java -server LongWhile Free memory: 4997088 Total memory: 5177344

Exceptions encountered during Development

Miscellaneous Exceptions :-  You might encounter various exceptions while developing a Project with Spring and Hibernate. I have depicted few of them here and their solutions:- 1. SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap Solution:-      Use commons-collections.jar 2. SEVERE: Servlet.service() for servlet spring threw exception org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'org.springframework.transaction.interceptor.TransactionInterceptor#0' must be of type [org.aopalliance.aop.Advice], but was actually of type [org.springframework.transaction.interceptor.TransactionInterceptor] Solution:-  It might be due to  ...

MOBILE

Check satellite signal status To check how many satellites your device has found, and whether your device is receiving satellite signals, select Menu > Applications > Location and GPS data > Options > Satellite status. If your device has found satellites, a bar for each satellite is shown in the satellite info view. The longer the bar, the stronger the satellite signal. When your device has received enough data from the satellite signal to calculate your location, the bar colour changes. To view the positions of found satellites, select Chg. view. Initially your device must receive signals from at least four satellites to be able to calculate your location. When the initial calculation has been made, it may be possible to continue calculating your location with three satellites. However, the accuracy is generally better when more satellites are found.

Singleton - Double locking mechanism

Let us see the Singleton code which we use generally to create a singleton instance: public static synchronized Singleton getInstance() { if (instance == null) //1 instance = new Singleton(); //2 return instance; //3 } The code in Listing 2 works fine for multithreaded access to the getInstance() method. However, when you analyze it you realize that synchronization is required only for the first invocation of the method. Subsequent invocations do not require synchronization because the first invocation is the only invocation that executes the code at //2, which is the only line that requires synchronization. All other invocations determine that instance is non-null and return it. Multiple threads can safely execute concurrently on all invocations except the first. However, because the method is synchronized, you pay the cost of synchronization for every invocation of the method, even though it is only required on the first invocation. In an effort to mak...

How to use Derby database

Well, I directly jump into the subject matter instead of taking you through its history and detail; because you may be already aware or if not you can google it. Please follow these following steps:- 1. Download the Apache Derby binary distribution (e.g., v10.6) from the Apache Derby web site ( http://db.apache.org/derby/ ) and extract it to a directory of your choice to complete the installation. Say for instance you have extracted it into 'c:\derby' folder. 2. Set ‘DERBY_INSTALL’ as user environment variable in you computer first. 3. Go to the physical location of ‘DERBY_INSTALL’ .and start the bat file ‘C:\derby\bin\startNetworkServer.bat’ by double clicking it . This will start the database server. Minimize this started command prompt. 4. Now, open a new command prompt 5. set CLASSPATH=%DERBY_INSTALL%\lib\derby.jar;%DERBY_INSTALL%\lib\derbytools.jar;%CLASSPATH% 6. To run the sysinfo utility, type the following in a command window or shell: java org.apache.derby.tools.sysin...

How to see what ports are open in my computer

Image
To find out what ports are open or exposed, follow these steps: Start >Run >type "cmd" At the command line type " netstat -a > c:\portsStatus.txt " {enter) This will create a file called portsStatus.txt in c: drive. Open this file, you will get the list of each ports in your computer. Interesting, eh ? The list displayed shows "Listening ports" and established "Who is on the other end" connections to your computer. Also, Who is listening: netstat -an |find /i "listening" Who is established: netstat -an |find /i "established" Also, if yourcomputer's operating system is XP and want to see what are the open ports at this mements, then type:-> netstat -ao |find /i "listening" This will give the detail against some Process Ids (PID)s. Till now you have identified the list of ports that are in use at this moment. And somehow you smelled that one of the port is in use which really should not be (this may be ...

Spring

   Today we all know that Spring is being widely used in enterprise applications because of its easy of development and layered architecture.  Which enable us to integrate its various layers with other technologies and API(s), like - JMS, MVC, Junit, EJB, Hibernate and so on.   This framework is very popular because of  its great feature of Dependency Injection (DI). Let us look a simple example to understand DI:- I have a class A (singleton class) that has some parameters that sets at start up time. Also. I have a class B (prototype) that needs the parameters in class A. Now, I am trying to figure out how to get the instance of A which is to be use in B later sometime. class A { //singleton class       String a; } class B {      //prototype class      A a;     String b;     public B createB() {  //for method lookup          return null; ...