Monday, November 7, 2011

Adding new elements to arraylist in java while using iterator

today i had a problem with usage of arraylist along side of iterator. the problem was that i was unable to add elements to the arraylist. it gives you an error java.util.ConcurrentModificationException this is because u cant add elements to an arraylist while using an iterator. so i had used listiterator as below.

import java.util.ArrayList;
import java.util.ListIterator;
public class Test 
{
 public static void main(String args[])
 {
  ArrayList array_test= new ArrayList();
  array_test.add("a");
  array_test.add("k");
  array_test.add("d");
  array_test.add("s");
  array_test.remove("d");
  int i=1;
  for(ListIterator it=array_test.listIterator();it.hasNext();)
  { 
   String link=it.next(); 
   if(i==1)
   {  
    it.add("r");
    it.previous();
    it.add("kk");
    it.previous();
   i++;
   }
   System.out.println(link);
   
  } 
   
  System.out.println("Contents of arrays list "+array_test);
 }
 

}

In the above code i had used it.previous whenever i used it.add. this is because i want to use the added value in the loop again. while the addition of new element in array is added just before next element in arraylist.

Thursday, October 6, 2011

perl object oriented tutorial
http://www.tutorialspoint.com/perl/perl_oo_perl.htm

Wednesday, September 28, 2011

collections in java
array list algorithm (dynamic array)
map
hashmap ( unordered data)
linkedhashmap ( ordered data)
- treemap are type of linked hash map better in implementation
java iterators for getting next element link
mutable and imutable onbjects link

sql query to find data between an interval.. something like getting data for each week

SELECT MAX( STR_TO_DATE( CONVERT( `PurchaseDt`

USING utf8 ) , '%m-%d-%Y' ) ) AS maxdate, MIN( STR_TO_DATE( CONVERT( `PurchaseDt`

USING utf8 ) , '%m-%d-%Y' ) ) AS mindate

FROM `MemberEarnings`

WHERE STR_TO_DATE( CONVERT( `PurchaseDt`

USING utf8 ) , '%m-%d-%Y' )

BETWEEN STR_TO_DATE( '08-01-2011', '%m-%d-%Y' )

AND STR_TO_DATE( '08-21-2011', '%m-%d-%Y' )

GROUP BY DATE_SUB( STR_TO_DATE( CONVERT( `PurchaseDt`

USING utf8 ) , '%m-%d-%Y' ) , INTERVAL DAYOFWEEK( STR_TO_DATE( CONVERT( `PurchaseDt`

USING utf8 ) , '%m-%d-%Y' ) ) -1

DAY )

Thursday, September 15, 2011

scala (new programming language)

data types

def to define objects
val final variables
var which can be changed...

peano Axioms

http://jim-mcbeath.blogspot.com/2008/11/practical-church-numerals-in-scala.html

99 scala problems

Thursday, June 9, 2011

adding users in ubuntu

sudo useradd -d /home/testuser -m testuser

sudo passwd testuser


make him sudoer my tweaking the following file

/etc/sudoers

when auto filling doesnt work using tab.....

It is likely your default shell for adding users is Bourne shell, not bash.

Look at /etc/defaults/useradd, and change:

SHELL=/bin/sh

to

SHELL=/bin/bash

So that future user adds will default to bash.

For your current user, you should change their login shell to bash.

chsh -s /bin/bash user_name

installing mysql

sudo apt-get install mysql-server



sudo netstat -tap | grep mysql
When you run this command, you should see the following line or something similar:

tcp 0 0 localhost.localdomain:mysql *:* LISTEN -
If the server is not running correctly, you can type the following command to start it:

sudo /etc/init.d/mysql restart