Wednesday, January 22, 2014

Word Puzzle - Android Application

This is a simple android application where the letters are shuffled and user has to find the meaningful word by arranging the given letters in the correct order. Can type the letters using the key pad or by clicking the letters. After finish press the Done button.


APK file can be downloaded by clicking on the following link.

Download

Have fun and do not forget to leave a comment.

Saturday, July 20, 2013

Stop sharing an already shared folder in Windows 7


  1. Open Computer Management. (Click Start, then right-click Computer, and then click Manage).
  2. In the console tree, click System Tools, then click Shared Folders, and then click Shares.
  3. In the details pane, right-click a shared folder, and then click Stop Sharing

Friday, July 19, 2013

Mockito: Some regularly used features

        Mockito is a very useful unit test framework and it has now become vastly famous in java software developers community. Few advantages of Mockito from its predecessors  is that Mockito can create mock objects of concrete classes (earlier unit test frameworks only could mock interfaces) and it is very simple and understandable.
        This article only highlights few useful techniques that are used when using Mockito and is only for the readers who already has experience in Mockito. But for beginners, there are many small tutorials available on the web to get things going.

Mock a method using Mockito

ConcreteClass mockObject = ConcreteMockito.mock(ConcreteClass.class)
Mockito.when(mockObject.testMethod()).thenReturn(testObject);

Check whether a given method is invoked
    
In the following code we check whether testMethod() is called once.

Mockito.verify(concreteClass, Mockito.times(1)).testMethod();

Check whether an exception is thrown

In following code the test will fail if testMethod() does not throw an exception.

try
{
         instance.testMethod();
         fail();
}
catch(SpiderException )
{
         assertTrue(expectedMessage.equals(ex.information));
}

Mock to return the same argument that passed into the method

In the following method the testMethod() is mocked in a way that it returns the same String array which was passed to it as a parameter.

Mockito.when(instance.testMethod(Mockito.any(String[].class)))
        .thenAnswer(new Answer<String[]>() {

        public String[] answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                return (String[]) args[0];
       }


}); 

Sunday, June 23, 2013

Tomcat Configurations

Defining Users for Tomcat Server

We can add users for tomcat server in following way.

1. Open <tomcat-home>/conf/tomcat-users.xml


2. Add following entries or just uncomment and edit existing entries as shown below. 


<?xml version='1.0' encoding='utf-8'?>

<tomcat-users>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="tomcat" password="tomcat" roles="admin,manager"/>
</tomcat-users>

Note: manager must be added as a role to allow access to <Tomcat Manager> menu


Source: http://www.mkyong.com/tomcat/tomcat-default-administrator-password/ 


Remote debugging Tomcat 6 using Eclipse

With Tomcat 6 you could quite easily debug server side codes using Eclipse.

Step 1: What you fist have to do is, start the Tomcat using the following command.


          Tomcat6\bin>catalina.bat jpda start

Step 2: Next create a remote application configuration as shown in the following figure and run it.


Spring-Framework-3 and Hibernate-Framework-4 Integration: Common Exceptions and Solutions

Exception: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session

Spring has dropped HibernateDaoSupport/HibernateTemplate from their Hibernate4 support package.
So anyone of you who is using above classes with Hibernate4 will get a java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session.
The simple solution for this is to, directly use hibernate classes instead of above mentioned Spring classes. This is illustrated in the following example.

Ex:
@Repository
public class UserDAOImpl implements UserDAO {

@Autowired
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

@Transactional
public void saveUser(User user) {
sessionFactory.getCurrentSession().saveOrUpdate(user);
}

@Transactional
public List<User> listUsers() {
return sessionFactory.getCurrentSession().createCriteria(User.class).list();
}
}

Here @Transactional spring annotation added to the data base access methods for transaction handling. For example if a runtime exception is thrown in middle of a data base access operation the changes done within the transaction will be rolled back in the data base.
When using @Transactional one needs to add following jars to the lib folder and to the class path.

1. aopalliance.jar
2. spring-aop-3.2.1.jar

And should add following tags to the configuration file

1. For beans <beans xsi:schemaLocation="..."> property append following

 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-2.5.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

Ex:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-2.5.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

2. Add following tags after the sessionFactory bean definition

<bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager">
          <property name="sessionFactory" ref="sessionFactory"/>
</bean>
       
<tx:annotation-driven transaction-manager="transactionManager" />
<context:annotation-config/>
<context:component-scan base-package="example" />


Note: Any miss configuration will throw an exception: No session found for current thread

Exception: java.lang.NoClassDefFoundError: org/hibernate/cache/CacheProvider

If you use org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean with Hibernate4,

Ex:
<bean id="sessionFactoryId" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

you will end up with a java.lang.NoClassDefFoundError: org/hibernate/cache/CacheProvider exception.
Reason for this is CacheProvider class is removed from Hibernate4. So you should use org.springframework.orm.hibernate4.LocalSessionFactoryBean instead.

EX:
<bean id="sessionFactoryId" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

Exception: java.lang.NoSuchFieldError: TRACE

This is due to a class confliction caused by log4j-1.2.8.jar. Removing it from the lib folder and class path will solve this issue.

Sunday, February 24, 2013

How to set up a wireless connection in Windows

This article describes how to set up a Wireless connection to a LAN in Windows and then connecting to internet using a Broadband (PPPoE) connection.

First of all make sure that WLAN, LAN and ADSL indicators are blinking in your wireless router. If not, restart the wireless router. Sometimes restarting the modem will also be required. If so first restart the Modem and then the wireless router.

Also make sure that the Wireless button in your laptop is switched on.

Then open, “Control Panel\Network and Internet\Network and Sharing Center” and click on “Set up a new connection or network” option.


Then select the “Connect to the Internet” option and click next.

    
Select “Create new connection” option and click next.


Now select Wireless to create a wireless connection.


Now you can connect to the LAN using this connection. But this will not get you connected to the internet and for that you have to create another Broadband (PPPoE) connection.


To create a Broadband (PPPoE) connection follow steps up to "Create new connection". Then instead of selecting Wireless, you have to select Broadband (PPPoE)


You will be prompted to fill the ISP information. Here you have to add the ISP username password and suitable name for the connection. Then press connect.


Now you are connected to the LAN through the wireless connection and you are connected to internet via the Broadband (PPPoE) connection.




Few short cut keys (hot keys) for Windows, Chrome and Microsoft One Note


Here are few short cut keys (hot keys) for Windows, Chrome and One Note which I find useful.

Windows Hot Keys

Win+Home
Clear all but the active window
Win+Space        
All windows become transparent
Shift+Win+Left/Right    
Move the window to the monitor
Win+T
Focus and scroll through items on the taskbar
Win+B
Focuses the System Tray icons
Ctrl+Shift+Enter
Open as Administrator
Ctrl+Shift+N
New Folder
F2
Rename
Alt+Left/Right
Go previous folder or next folder
Shift + F10
Right Click Menu
\
Types the \ in Google search box

Chrome Hot Keys

Ctrl+N
New window
Ctrl+T
New tab
Ctrl+Shift+Enter
Opens the selected link in a new tab
Ctrl+Shift+T
Reopens the last tab you've closed
Ctrl+Tab
Next tab
Ctrl+W
Closes the current tab or pop-up
F10
Opens the Chrome menu
Ctrl+Shift+B
Toggles the bookmarks bar on and off
Ctrl+Shift+Delete
Opens the Clear Browsing Data dialog
Esc
Stops the loading of your current page
Ctrl+F
Opens the find bar
Ctrl+G or F3
Finds the next match
Ctrl+Shift+G, Shift+F3
Finds the previous match
Ctrl+D
Saves your current webpage as a bookmark
Ctrl+H
History page
Ctrl+J
Downloads page
Alt+D
Focus the address bar

One Note Hot Keys

Ctrl+M
Open new window
Ctrl+Shift+O
Numbered list
Ctrl+Shift+L
Bulleted list
Ctrl+Shift+F,Up,Down
Select Font
Ctrl+Shift+P,Up,Down
Select Size
Alt+I,P
Insert Picture
Alt+I,F
Insert File
Ctrl+Tab
Traverse Tabs

Eclipse Hot Keys

Ctrl+Shift+E
Switch to editor
Alt+Shift+Q,P
Package viewer