Skip to main content

How to delete skype android history ?

· One min read
Sandeep Bhardwaj

Easy steps to delete skype chat history off your mobiles.

  1. Sign out of skype from your mobile.
  2. Sign into skype on your computer.
  3. Go to tools-options- privacy settings.
  4. Click on clear history.
  5. Sign out of skype from your computer.
  6. On your mobile go to settings-applications manager-skype and clear data.
  7. Sign back on to skype on your mobile and your message history should be deleted.

Convert java.util.Collection to java.util.List

· One min read
Sandeep Bhardwaj
List list;  
if (collection instanceof List)
{
list = (List)collection;
}
else
{
list = new ArrayList(collection);
}

Generic way (java 1.5<=)

public <E> List<E> collectionToList(Collection<E> collection)  
{
List<E> list;
if (collection instanceof List)
{
list = (List<E>) collection;
}
else
{
list = new ArrayList<E>(collection);
}
return list;
}

Without Generics (java 1.4>=)

public List collectionToList(Collection collection)  
{
List list;
if (collection instanceof List)
{
list = (List) collection;
}
else
{
list = new ArrayList(collection);
}
return list;
}

How to convert java.util.List to java.util.Set

· One min read
Sandeep Bhardwaj

Removing duplicate items from a list is pretty simple in java just convert the list to java.util.Set it will automatically remove the duplicate items and create a set for you.

Syntax

Set<E> alphaSet  = new HashSet<E>(<your List>);  

Example

import java.util.ArrayList;  
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ListToSet
{
public static void main(String[] args)
{
List<String> alphaList = new ArrayList<String>();
alphaList.add("A");
alphaList.add("B");
alphaList.add("C");
alphaList.add("A");
alphaList.add("B");
System.out.println("List values .....");
for (String alpha : alphaList)
{
System.out.println(alpha);
}
Set<String> alphaSet = new HashSet<String>(alphaList);
System.out.println("\nSet values .....");
for (String alpha : alphaSet)
{
System.out.println(alpha);
}
}
}

Several ports (8005, 8080, 8009) required by Tomcat 6 at localhost are already in use

· One min read
Sandeep Bhardwaj

Several ports (8005, 8080, 8009) required by Tomcat 6 at localhost are already in use.

Today ,I faced a problem while running the tomcat with in the eclipse a popup appears
and it says:-

"Several ports (8005, 8080, 8009) required by Server (Tomcat 6) at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s)."  

so it means we have kill that process which is running on that port says (8080).A pretty simple solution isrun the below commands on commands on command prompt.

Step 1

netstat -a -o -n and it will bring up a network list,search for the local address like 127.0.0.1:8080 and note the PID (eq 3624)

C:\>netstat -a -o -n

Step 2

taskkill /F /PID 3624 . Run this command to kill that process.

C:\>taskkill /F /PID 3624

Hurry now you are able to run your server.

Un Deploy Ext plugin in liferay

· One min read
Sandeep Bhardwaj

Un Deploy Ext Plugin in Lifeay 6.0

Un deployment of ext plugin in liferay is a tricky task, so i found a simple solution for doing this instead of deleting all the ext files from tomcat. I made a bat file for this this bat file remove all the ext plugin related files from your tomcat directory.

@echo off  
set app_name=%1
if "%app_name%" == "" goto end
set tomcat_home=<Your tomcat home direcory>

rmdir /S /Q %tomcat_home%\temp
rmdir /S /Q %tomcat_home%\webapps\%app_name%-ext
rmdir /S /Q %tomcat_home%\webapps\ROOT\html\portlet\ext
del /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\classes\portal-ext.properties
del /S /Q %tomcat_home%\lib\ext\ext-%app_name%-ext-service.jar
del /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\lib\ext-%app_name%-ext-util-bridges.jar
del /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\lib\ext-%app_name%-ext-util-taglib.jar
del /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\lib\ext-%app_name%-ext-util-java.jar
del /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\lib\ext-%app_name%-ext-impl.jar
del /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\ext-%app_name%-ext.xml
del /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\tiles-defs-ext.xml

:end

just change the tomcat_home with your tomcat home directory and paste the code in a notepad and save as undeployment.bat .
For running the bat pass your ext application name (with our ext) as command line argument.

C:/>undeployment.bat <application name>  

Specified VM install not found:- Eclipse

· One min read

Specified VM install not found: type Standard VM, name jre6

Some times when we are trying to run build.xml using ant in eclipse it will gives an error "Specified VM install not found: type Standard VM, name jre6"

There is a simple solution for this just delete the launch file of that project.

Solution

Delete the file from the location given below

"<Your eclipse workspace location>\.metadata\.plugins\org.eclipse.debug.core\.launches\<projectname>.xml.launch"

Finally restart your eclipse.

Hurray !!! now your problem solved. :)

Delete saved SVN stored password from eclipse

· One min read

If you wanted to delete the stored subversion (svn) password from Eclipse IDE.

Then follow these steps :-

SVN stores the authentication in physical files. The easiest way is to delete those files physically from the directory.

On windows XP, these files are located in the following two folders:

Step 1 : Delete keyring file from the location given below

<Your eclipse installation path>\Eclipse\configuration\org.eclipse.core.runtime\.keyring

Step 2 : Delete all file from the location given below :-

C:\Documents and Settings\<your user name>\Application Data\Subversion\auth\svn.simple

Step 3 : Restart your Eclipse IDE, now all saved password will gone and a new prompt dialoge box will open for asking new password.

Comparing two list and removing duplicate elements

· One min read

Comparing two list and removing duplicate elements.

import java.util.ArrayList;
import java.util.List;

public class CheckList
{

public static void main(String[] args)
{

List<string> a = new ArrayList<string>();
a.add("a");
a.add("b");

List<string> b = new ArrayList<string>();
b.add("c");
b.add("a");
b.add("d");
b.add("f");

b.removeAll(a);

for (String str : b)
{
System.out.println(str);
}
}
}

Common BeanUtils to set html form values in Java Bean

· 4 min read
Sandeep Bhardwaj

Hi All,
Today I am going to discuss about a important jar commons-beanutils used by struts framework and demonstrating how to use this important jar in our servlet and jsp project.

If you worked with struts1 or struts2 then you noticed that the ActionForm or Action (in Struts2) linked with your Jsp page or html page when you clicked on submit button the values of html form with same property name is set by calling the setter method of your POJO or FormBean automatically.

But when we worked with only servlet and Jsp without using any MVC framework then we need to set the values using below line :-

String userName=request.getParameter(“userName”);

If we had 10 field on a form then we need to create 10 variables and we have to write the above line 10 times by passing the form filed name as argument.

Also another problem then we have to cast the filed values according to our need like

int age=Integer.parseInt(request.getParameter(“age”));  

About application


This application contains a simple form a Java Bean and a Servlet to display the form values submitted by user using Common BeanUtils jar.

  1. Simple Jsp with two input boxes and a submit button.
  2. LoginForm simple Java bean containing setter and getters of form fields.
  3. FormUtil class used to set the Jsp form values in Java Bean.
  4. LoginActionServlet to process from values.

Package Structure

jar needed

index.jsp


index.jsp containing a form with username and password textboxes and a submit button. When user clicked on submit button LoginActionServlet called.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<form action="loginActionServlet" method="post">
<table>
<tbody>
<tr>
<td>Username</td>
<td>
<input name="userName" type="text">
</td>
</tr>
<tr>
<td>Password</td>
<td>
<input name="password" type="password">
</td>
</tr>
<tr>
<td>
<input type="submit">
</td>
</tr>
</tbody>
</table>
</form>

LoginForm.java


LoginForm class with setters and getters of userName and password these fields names are same as form fields in jsp.

package form;

public class LoginForm {

private String userName;
private String password;

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}

FormUtil.java


FormUtil class used BeanUtils class populate method for setting the form values in Java beans. I made this class a generic class so that we do not need to write same lines again and again in each servlet, just we need to pass the class of java bean and request in populate method of FormUtil.
LoginForm loginForm = FormUtil.populate(LoginForm.class, request);

package util;

import java.lang.reflect.InvocationTargetException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.beanutils.BeanUtils;

public class FormUtil {

public static <T> T populate(Class<T> clazz, HttpServletRequest request) {
T object = null;
try {

object = (T) clazz.newInstance();
BeanUtils.populate(object, request.getParameterMap());

} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return object;
}
}

LoginActionServlet.java


LoginActionServlet used to process the values of LoginForm and display the values.

package action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.FormUtil;
import form.LoginForm;

public class LoginActionServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

PrintWriter out = response.getWriter();

LoginForm loginForm = FormUtil.populate(LoginForm.class, request);

out.println("User name is :" + loginForm.getUserName());
out.println("Password is :" + loginForm.getPassword());

}
}

web.xml


web.xml with LoginActionServlet servlet mapping.

<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>DemoApp</display-name>
<servlet>
<display-name>LoginActionServlet</display-name>
<servlet-name>LoginActionServlet</servlet-name>
<servlet-class>action.LoginActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginActionServlet</servlet-name>
<url-pattern>/loginActionServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Now paste these files according to package structure and run it by typing http://localhost:8080/DemoApp.

Enum in java

· One min read
Sandeep Bhardwaj

Enum: Get value using enum

enum Day {  
SUNDAY(1), MONDAY(2), TUESDAY(3), WEDNESDAY(4), THURSDAY(5), FRIDAY(6), SATURDAY(7);
private final int dayCode;
private Day(int dayCode)
{
this.dayCode = dayCode;
}
public int getCode() { return dayCode; }
}

public class EnumValueOfDay {
public static void main(String[] args) {

Day day = Day.SUNDAY;
System.out.println("Day = " + day.getCode());
}
}

also you can use enum in this way to get the value of enum . Here is one more example to print the names by using toString method.

enum Name {  
S("Sandeep"),
A("Aditya") ,
R("Rambrij"),
M("Meenakshi");

private final String name;

private Name(String name) {
this.name = name;
}

public String toString() {
return name;
}
}

public class NameDisplay {
public static void main(String[] args) {

Name name = Name.A;
System.out.println("Name = " + name);
}
}