Example to find maxmimum element in a Vector

>> Sunday, October 17, 2010

Example to find maximum element in a Vector

This java example shows how to find a maximum element of Java Vector using max method of Collections class.To find maximum element of Java Vector use, static Object max(Collection c) method of Collections class.

This method returns the maximum element of Java Vector according to its natural ordering.

    import java.util.Vector;
    import java.util.Collections;

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

     //create a Vector object
     Vector v = new Vector();
     //Add elements to Vector
 
     v.add(new Double("324.4324"));
     v.add(new Double("345.3532"));
     v.add(new Double("342.342"));
     v.add(new Double("357.349"));
      v.add(new Double("23.32453"));

      Object obj = Collections.max(v);
     System.out.println("Maximum Element of Java Vector is : " + obj);

     }
    }


The Output is:

Maximum Element of Java Vector is : 357.349

For Reference SCJP:

SCJP: Sun Certified Programmer for Java Platform Study Guide: SE6 (Exam CX-310-065)

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Example to Find maxmimum element in ArrayList

Example to Find maxmimum element in ArrayList

This java example shows how to find a maximum element of Java ArrayList using max method of Collections class.

To find maximum element of Java ArrayList use, static Object max(Collection c) method of Collections class.
This method returns the maximum element of Java ArrayList according to its natural ordering.

import java.util.ArrayList;
    import java.util.Collections;

    public class FindMaximumOfArrayListExample {

     public static void main(String[] args) {

     //create an ArrayList object
     ArrayList arrayList = new ArrayList();

     //Add elements to Arraylist
     arrayList.add(new Integer("327482"));
     arrayList.add(new Integer("13408"));
     arrayList.add(new Integer("802348"));
     arrayList.add(new Integer("345308"));
     arrayList.add(new Integer("509324"));

     Object obj = Collections.max(arrayList);
     System.out.println("Maximum Element of Java ArrayList is : " + obj);

     }
    }

The Output :

Maximum Element of Java ArrayList is : 802348

CoreJava Fundamentals:


Core Java™, Volume I--Fundamentals (8th Edition)

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Create a List containing n Copies of Specified Object

Create a List containing n Copies of Specified Object This java example shows how to create a list consisting n copies of specified copies using nCopies method of Collections class.

To create a List containing n copies of specified Object use,static List n Copies(int n, Object obj) method of Java Collection class.This method returns immutable List containing n copies of the specified Object.

import java.util.Collections;
import java.util.List;
import java.util.Iterator;

public class CreateListOfNCopiesExample {
 public static void main(String[] args) {
  List list = Collections.nCopies(5,"A");
  //iterate through newly created list
  System.out.println("List contains, ");
  Iterator itr = list.iterator();
  while(itr.hasNext())
  System.out.println(itr.next());
  }
    }

The Output of above program:

List contains,

    A
    A
    A
    A
    A

For Good Practice of Collections:

Data Structures in Java: From Abstract Data Types to the Java Collections Framework

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Write a program on ArrayList From Enumeration

Create an ArrayList From Enumeration

This java example shows how to create an ArrayList from any Enumeration object using list method of Collections class. To create ArrayList from any Enumeration, use

static ArrayList list(Enumeration e) method of Collections class. This method returns the ArrayList containing the elements returned by specified Enumeration object in order they are returned.

import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Enumeration;
    import java.util.Vector;

  public class CreateArrayListFromEnumerationExample {
   public static void main(String[] args) {
   //create a Vector object
   Vector v = new Vector();
   //Add elements to Vector

   v.add("A");
   v.add("B");
   v.add("D");
   v.add("E");
   v.add("F");
   
   System.out.println("Vector contains : " + v);
   //Get Enumeration over Vector
   Enumeration e = v.elements();
   //Create ArrayList from Enumeration of Vector
   ArrayList aList = Collections.list(e);
   System.out.println("Arraylist contains : " + aList);

  }
 }

Output is:

Vector Contains : [A, B, D, E, F]
Arraylist contains : [A, B, D, E, F]

For Java Books Reference:

SCJP Sun Certified Programmer for Java 6 Exam 310-065

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Copy Elements of Vector to Java ArrayList Example

  1. /*
  2. Copy Elements of Vector to Java ArrayList Example
  3. This java example shows how to copy elements of Java Vector to Java ArrayList using
  4. copy method of Collections class.
  5. */
  6. import java.util.ArrayList;
  7. import java.util.Collections;
  8. import java.util.Vector;
  9. public class CopyElementsOfVectorToArrayListExample {
  10. public static void main(String[] args) {
  11. //create a Vector object
  12. Vector v = new Vector();
  13. //Add elements to Vector
  14. v.add("1");
  15. v.add("2");
  16. v.add("3");
  17. //create an ArrayList object
  18. ArrayList arrayList = new ArrayList();
  19. //Add elements to Arraylist
  20. arrayList.add("One");
  21. arrayList.add("Two");
  22. arrayList.add("Three");
  23. arrayList.add("Four");
  24. arrayList.add("Five");
  25. /*
  26. To copy elements of Java Vector to Java ArrayList use,
  27. static void copy(List dstList, List sourceList) method of Collections class.
  28. This method copies all elements of source list to destination list. After copy
  29. index of the elements in both source and destination lists would be identical.
  30. The destination list must be long enough to hold all copied elements. If it is
  31. longer than that, the rest of the destination list's elments would remain
  32. unaffected.
  33. */
  34. System.out.println("Before copy ArrayList Contains : " + arrayList);
  35. //copy all elements of Vector to ArrayList using copy method of Collections class
  36. Collections.copy(arrayList,v);
  37. /*
  38. Please note that, If ArrayList is not long enough to hold all elements of
  39. Vector, it throws IndexOutOfBoundsException.
  40. */
  41. System.out.println("After Copy ArrayList Contains : " + arrayList);
  42. }
  43. }
  44. /*
  45. Output would be
  46. Before copy ArrayList Contains : [One, Two, Three, Four, Five]
  47. After Copy ArrayList Contains : [1, 2, 3, Four, Five]
  48. */

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Copy Objects from One Vector to Another Vector using Java

Copy Elements of One Java Vector to Another Java Vector Example

This java example shows how to copy all elements of one Java Vector object to
another Java Vector object using copy method of Collections class.

import java.util.Collections;

    import java.util.Vector;

    public class CopyElementsOfVectorToVectorExample {

  public static void main(String[] args) {

  //create first Vector object

  Vector v1 = new Vector();

  //Add elements to Vector

  v1.add("1");

  v1.add("2");

  v1.add("3");

  //create another Vector object

  Vector v2 = new Vector();

  //Add elements to Vector

  v2.add("One");

  v2.add("Two");

  v2.add("Three");

  v2.add("Four");

  v2.add("Five");
  
  System.out.println("Before copy, Second Vector Contains : " + v2);

  //copy all elements of Vector to another Vector using copy

  //method of Collections class

  Collections.copy(v2,v1);

  System.out.println("After copy, Second Vector Contains : " + v2);

  }

    }

To copy elements of one Java Vector to another use,
static void copy(List dstList, List sourceList) method of Collections class.
This method copies all elements of source list to destination list. After copy
index of the elements in both source and destination lists would be identical.
The destination list must be long enough to hold all copied elements.
If it islonger than that, the rest of the destination list's elments would remain unaffected.

Please note that, If destination Vector object is not long enough to hold all elements of source Vector,it throws IndexOutOfBoundsException.

Output would be


Before copy, Second Vector Contains : [One, Two, Three, Four, Five]

After copy, Second Vector Contains : [1, 2, 3, Four, Five]

For  Reference Books:

Beginning Programming with Java For Dummies

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Copy Elements of ArrayList to Vector Example

Copy Elements of ArrayList to Java Vector Example

/*This java example shows how to copy elements of Java ArrayList to Java Vector using
copy method of Collections class.
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Vector;
public class CopyElementsOfArrayListToVectorExample {
public static void main(String[] args) {

//create an ArrayList object

  ArrayList arrayList = new ArrayList();
  //Add elements to Arraylist
  arrayList.add("1");
  arrayList.add("4");
  arrayList.add("2");
  arrayList.add("5");
  arrayList.add("3");
  //create a Vector object
  Vector v = new Vector();
  //Add elements to Vector
  v.add("A");
  v.add("B");
  v.add("D");
  v.add("E");
  v.add("F");
  v.add("G");
  v.add("H");

  System.out.println("Before copy, Vector Contains : " + v);
  Collections.copy(v,arrayList);
  System.out.println("After Copy, Vector Contains : " + v);
 }
}



To copy elements of Java ArrayList to Java Vector use,
static void copy(List dstList, List sourceList) method of Collections class.
This method copies all elements of source list to destination list. 

After copy  index of the elements in both source and destination lists would be identical.
The destination list must be long enough to hold all copied elements. If it is
longer than that, the rest of the destination list's elments would remain
unaffected.

copy all elements of ArrayList to Vector using copy method of Collections class

Please note that, If Vector is not long enough to hold all elements of
ArrayList, it throws IndexOutOfBoundsException.

Output would be
Before copy Vector Contains : [A, B, D, E, F, G, H]
After Copy Vector Contains : [1, 4, 2, 5, 3, G, H]

For Java Programming References:
Head First Java, 2nd Edition

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Copy Elements from one ArrayList to Another ArrayList

>> Saturday, October 16, 2010

Here is the Program to copy the values from one ArrayList to another ArrayList.

package collect;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


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

  List l1=new ArrayList(); 
  
  l1.add("hi");
  l1.add("brother");
  
  ArrayList al=new ArrayList(); 
  al.add("hello");  
  al.add("guru");   
  
  Collections.copy(al,l1);   
  Iterator i= al.iterator();  
  
  while(i.hasNext()){ 
   i.hasNext();  
   System.out.print(" "+i.next()); 
   //System.out.println(al);  
  }   
 }  
}

This is the procedure to copying the objects from one list to another.

For Java References:
Effective Java (2nd Edition) 

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

DeployingWAR FileWith Sun Java SystemApplication Server

After you install Directory Server Enterprise Edition, you can deploy theWARfile to access
DSCC. The following procedure contains the deployment instructions to deploy theWARfile:

▼ To DeployWAR FileWith Sun Java SystemApplication

Server
Create theWAR file for DSCC.

$ install-path/bin/dsccsetup war-file-create
For native packages installation, theWARfile is created in the /var/opt/SUNWdsee7/ directory.
For zip distribution installation, theWARfile is created in the install-path/var directory.
Initialize the DSCC registry.

$ install-path/bin/dsccsetup ads-create
Choose password for Directory Service Manager:
Confirm password for Directory Service Manager:
Creating DSCC registry...
DSCC Registry has been created successfully
To create server instances on the same host where DSCC is deployed, register the DSCC agent in
CommonAgent Container.
$install-path/bin/dsccsetup cacao-reg
Type the following command to check the location and other statistics of yourWARfile and
DSCC registry:
$ install-path/bin/dsccsetup status
Create an application server instance.
$ mkdir /local/domainroot
$ cd app-server-install-path/bin
$ asadmin create-domain --domaindir /local/domainroot --adminport 3737 \
--user admin dscc7
Edit the server.policy file.
a. Open the server.policy file.
$ vi /local/domainroot/dscc7/config/server.policy
1
2
3
4
5
DeployingWAR FileWith Sun Java System Application Server
Sun Directory

b. Add the following statements to the end of the file:
// Permissions for Directory Service Control Center
grant codeBase "file:${com.sun.aas.instanceRoot}/applications/j2ee-modules/dscc7/-"
{
permission java.security.AllPermission;
};
The addition configures the application server to grant all the Java permissions to the DSCC
application.

Deploy theWAR file in your application server instance.

$ asadmin start-domain --domaindir /local/domainroot --user admin dscc7
$ cp install-path/var/dscc7.war /local/domainroot/dscc7/autodeploy
For more information about creating and configuring application server instances and
deploying theWARfile, refer to the Sun Java System Application Server OnlineHelp.
Open DSCC.
Use http://hostname:8080/dscc7 or https://hostname:8181/dscc7 based on the
configuration of your application server.
The Directory ServiceManager Login page displays.

click here to download the fulll pge

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

What is Normalization..?How many types are there.?

>> Sunday, October 10, 2010


Normalization:

Normalization is a design technique which helps to design the relational database.
Normalization is essentially a two step process that puts data into tabular form by removing redundant data from the relational tables.

Normalization has been divided into following types.

1.First Normal Form (1NF): A Relational table all column values are atomic.It means that it contains no repeating values.

(or)

A Relational table should not be any multivalued column.

2.Second Normal Form (2NF) : A Relational table is in second normal form if it is in First Normal form and every Non-Key Column is fully dependent on PrimaryKey.

(or)

The table should be in 1NF and every non key column must fully functional dependent on primaryKey.

3.Third Normal Form (3NF): A Relational table is in third Normal Form (3NF) if it is already in 2NF and every non-key column is non transitive dependent upon its primary key.

(or)

The table should be in 2NF and every non-key column should not be any transitive dependencies.

4.Boyce Codd Normal Form (BCNF) : The Relational table is in BCNF if it is already in 3NF and every non key column should not be overlapping between candidate keys.

(or)

The table should be in 3NF and the columns should not be overlapping between any candidate keys.

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Related Posts Plugin for WordPress, Blogger...

Random Posts

JavabynataraJ - Find me on Bloggers.com Find me on blorner.com Technology Blogs JavabynataraJ Backlinks Blogarama - The Blog Directory

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP