Many times i was facing problem of Out of Memory error for Tomcat while developing applications.
Sometimes IDE failed to stop tomcat. And if you try to start tomcat again on same port, you get error that "port is already in use". In such cases, below are steps to release Tomcat port to restart tomcat again on same port.
1. Find out which process is using Port using command
sudo netstat -lpn |grep :8080
You will get output like
tcp6 0 0 :::8080 :::* LISTEN 6749/java
2. Process Id 6749 is using port 8080.
3. Kill the process using command
kill 6749
Now you can again use port 8080 to run tomcat on this port.
Tuesday, May 12, 2009
Tuesday, March 31, 2009
Sample Android application using Netbeans on UBUNTU
Sample Android application using Netbeans on UBUNTU
Step 1. Download Android SDK from
http://developer.android.com/sdk/1.1_r1/index.html
Unzip distribution.
Step 2. Setting Netbeans plugin for Android :
You can get details installing plugin for Android at
http://kenai.com/projects/nbandroid/pages/Install
Step 3.
Netbeans menu
Tools -- Java Platform
Click Add Platform button
Select Google Android Open Handheld platform.
Set Android SDK directory as Platform folder. (downloaded and unzipped in step 1)
Click next and set name as "Android".
Click finish.
Step 4. Create new Android Project
File -- Project --
Android -- Android Application
Set project Name as HelloAndroid for example.
click finish
Step 5.
Open Source packages
org.me.helloandroid.MainActivity.java file.
there is oncreate method as follows
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
}
Change it by adding few lines of code to display "Hello Android".
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
Step 6.
Run Application.
You will get "Hello Android" text on Android Emulator screen.
If You get Following Exception while running application :
trouble processing:
invalid constant pool index 0000
...while parsing attributes[1]
...while parsing Code attribute at offset 0000013e
...while parsing attributes[0]
...while parsing methods[0]
...while parsing org/me/helloandroid/R$layout.class
...while processing org/me/helloandroid/R$layout.class
Check java -version on console and set it as java-6
Here are steps how to set this:
on console window type : sudo update-alternatives --config java
It will give installed versions and option to set java version.
If java 6 is not in list use following link to install and set as default version
https://help.ubuntu.com/community/Java
Step 1. Download Android SDK from
http://developer.android.com/sdk/1.1_r1/index.html
Unzip distribution.
Step 2. Setting Netbeans plugin for Android :
You can get details installing plugin for Android at
http://kenai.com/projects/nbandroid/pages/Install
Step 3.
Netbeans menu
Tools -- Java Platform
Click Add Platform button
Select Google Android Open Handheld platform.
Set Android SDK directory as Platform folder. (downloaded and unzipped in step 1)
Click next and set name as "Android".
Click finish.
Step 4. Create new Android Project
File -- Project --
Android -- Android Application
Set project Name as HelloAndroid for example.
click finish
Step 5.
Open Source packages
org.me.helloandroid.MainActivity.java file.
there is oncreate method as follows
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
}
Change it by adding few lines of code to display "Hello Android".
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
Step 6.
Run Application.
You will get "Hello Android" text on Android Emulator screen.
If You get Following Exception while running application :
trouble processing:
invalid constant pool index 0000
...while parsing attributes[1]
...while parsing Code attribute at offset 0000013e
...while parsing attributes[0]
...while parsing methods[0]
...while parsing org/me/helloandroid/R$layout.class
...while processing org/me/helloandroid/R$layout.class
Check java -version on console and set it as java-6
Here are steps how to set this:
on console window type : sudo update-alternatives --config java
It will give installed versions and option to set java version.
If java 6 is not in list use following link to install and set as default version
https://help.ubuntu.com/community/Java
Wednesday, March 18, 2009
Sort Objects of ArrayList
We use ArrayList many times to store list of Objects.
How to Sort records of ArrayList of objects using Collections.sort method based on particular field.
Suppose we have Class Employee as :
public class Employee {
private String empName;
private String empDept;
private double salary;
public String getEmpDept() {
return empDept;
}
public void setEmpDept(String empDept) {
this.empDept = empDept;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
main method to demonstrate sorting of ArrayList which contains few Employees.
eg:
public static void main(String[] args) {
ArrayList empList = new ArrayList();
Employee e1 = new Employee();
e1.setEmpName("Abcd");
e1.setEmpDept("ACCT");
Employee e2 = new Employee();
e2.setEmpName("Ssss");
e2.setEmpDept("HRD");
Employee e3 = new Employee();
e3.setEmpName("rrrr");
e3.setEmpDept("MKTG");
Employee e4 = new Employee();
e4.setEmpName("bbbb");
e4.setEmpDept("ACCT");
Employee e5 = new Employee();
e5.setEmpName("mmmm");
e5.setEmpDept("DEVP");
empList.add(e1);
empList.add(e2);
empList.add(e3);
empList.add(e4);
empList.add(e5);
System.out.println("Before Sorting:");
for (Employee employee : empList) {
System.out.println("Employee :"+employee.getEmpName());
}
Collections.sort(empList, new Comparator(){
public int compare(Object obj1, Object obj2) {
Employee emp1 = (Employee) obj1;
Employee emp2 = (Employee) obj2;
return emp1.getEmpName().compareToIgnoreCase(emp2.getEmpName());
}
});
System.out.println("");
System.out.println("After Sorting:");
for (Employee employee : empList) {
System.out.println("Employee :"+employee.getEmpName());
}
}
Output is:
Before Sorting:
Employee :Abcd
Employee :Ssss
Employee :rrrr
Employee :bbbb
Employee :mmmm
After Sorting:
Employee :Abcd
Employee :bbbb
Employee :mmmm
Employee :rrrr
Employee :Ssss
How to Sort records of ArrayList of objects using Collections.sort method based on particular field.
Suppose we have Class Employee as :
public class Employee {
private String empName;
private String empDept;
private double salary;
public String getEmpDept() {
return empDept;
}
public void setEmpDept(String empDept) {
this.empDept = empDept;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
main method to demonstrate sorting of ArrayList which contains few Employees.
eg:
public static void main(String[] args) {
ArrayList
Employee e1 = new Employee();
e1.setEmpName("Abcd");
e1.setEmpDept("ACCT");
Employee e2 = new Employee();
e2.setEmpName("Ssss");
e2.setEmpDept("HRD");
Employee e3 = new Employee();
e3.setEmpName("rrrr");
e3.setEmpDept("MKTG");
Employee e4 = new Employee();
e4.setEmpName("bbbb");
e4.setEmpDept("ACCT");
Employee e5 = new Employee();
e5.setEmpName("mmmm");
e5.setEmpDept("DEVP");
empList.add(e1);
empList.add(e2);
empList.add(e3);
empList.add(e4);
empList.add(e5);
System.out.println("Before Sorting:");
for (Employee employee : empList) {
System.out.println("Employee :"+employee.getEmpName());
}
Collections.sort(empList, new Comparator(){
public int compare(Object obj1, Object obj2) {
Employee emp1 = (Employee) obj1;
Employee emp2 = (Employee) obj2;
return emp1.getEmpName().compareToIgnoreCase(emp2.getEmpName());
}
});
System.out.println("");
System.out.println("After Sorting:");
for (Employee employee : empList) {
System.out.println("Employee :"+employee.getEmpName());
}
}
Output is:
Before Sorting:
Employee :Abcd
Employee :Ssss
Employee :rrrr
Employee :bbbb
Employee :mmmm
After Sorting:
Employee :Abcd
Employee :bbbb
Employee :mmmm
Employee :rrrr
Employee :Ssss
Subscribe to:
Posts (Atom)