Clean Java

There is always a bigger game

Posts Tagged ‘java

MongoDB – Add an Element to an Array using Java Driver.

with one comment

Written by cleanjava

March 20, 2013 at 12:39 pm

Creating user registration page in ATG using DSPs and Handler.

with 9 comments

How to add users in ATG using ACC?

with 7 comments

On development phase, you may have to set up users with valid credential to do authentication test in your ATG e-commerce web-site. I will explain you every step required to setup user using ATG ACC and how to verify if the user is indeed setup properly.

1. load dynamo admin tool using the below given URI.
http://host-name:port/dyn/admin

2. On the dynamo admin console click on Admin ACC link. (Third one from the top)

3. Click on “Start ACC in Server VM” button.
4. Now you should see a thick GUI written in java swings titled ATG Control Center. Default credential for ATG ACC is admin/admin
5. On the left hand site you should see a collection of menus.
6. Select the first item in left pane named People and Organization.

7. Now you should see six other items under the People and Organization main item
8. Select Users item. (Third one from the top)

9. This should bring up the user window. Punch in all users details and click on OK button.

10. Click on the save icon on the top right side of ACC window.
11. Now you can verify if the user is really added in the database.
12. Select JDBC browser from Dynamo Admin Page. (see the first step to load dyn admin page)
13. Select “Execute Query” under database operations.
14. Write “select * from dps_user” in the query text area and click execute button.
15. You should be able to the user you have added thru the ACC new user window.

How to write ATG includes query (RQL)?

with 12 comments

Wildcard File Filter in java.

with one comment

Splitting tasks among threads.

with 2 comments

Recently in an interview I was asked to write a program which prints running positive numbers, odd number shall be printed by one thread and even number shall be printed by another thread. I thought to share the program with you guys.


package org.sanju;

/**
 *
 * @author sanju.org
 *
 * Example program which prints odd number by one thread
 * and even number by another thread.
 *
 *
 */
public class SplitTaskExample {

	private volatile Integer i = new Integer(0);

	private void printRunningNumbers(){

		//odd thread
		new Thread(new Runnable() {
			public void run() {
				while(true){
					if(i % 2 == 1){
						System.out.println("odd thread :"+i);
						i++;
					}
					try{
						i.wait();
						i.notifyAll();
					}catch (Exception e) {
					}
				}
			}
		}).start();

		//even thread
		new Thread(new Runnable() {

			public void run() {
				while(true){
					if(i % 2 == 0){
						System.out.println("even thread : "+i);
						i++;
					}
					try{
						i.wait();
						i.notifyAll();
					}catch (Exception e) {
					}
				}
			}
		}).start();

	}

	public static void main(String[] args) {
		new SplitTaskExample().printRunningNumbers();
	}

}

/local/opt/java SplitTaskExample

even thread : 0
odd thread :1
even thread : 2
odd thread :3
even thread : 4
odd thread :5

Written by cleanjava

March 21, 2012 at 7:36 pm

Multiple attributes to compare objects.

with one comment

There would be cases you would want use a second attribute to compare two objects of same type if the first attribute comparison is not good enough. In the compareTo method you can choose to go a second attribute to compare two objects of same type. Here is a simple example where the compareTo method used the lastName to compare two objects of Employee if the firstName of two employee objects are same.


package org.sanju;

/**
 *
 * @author sanju.org
 *
 * Multiple attributes to compare Objects.
 * Multiple attributes in cmpareTo method.
 *
 */

public class Employee implements Comparable<Employee> {

	private Name name;

	class Name{
		private String firstName;
		private String lastName;
	}

	public int compareTo(Employee o) {
		if(this.name.firstName.compareTo(o.name.firstName) == 0){
			return this.name.lastName.compareTo(o.name.lastName);
		}
		return this.name.firstName.compareTo(o.name.firstName);
	}
}

Iterating forward and backward using java iterator.

leave a comment »

Written by cleanjava

March 21, 2012 at 6:58 pm

How to use java.util.concurrent.BlockingQueue?

with 4 comments