Powered by Blogger.

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

Reference Books:

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

Reference Books: 

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 nCopies(int n, Object obj) method of Java Collection class.This method returns immutable List containing n copies of the specified Object.
List Containing N copies of Specified Object_JavabynataraJ

Enumerate Vector using java.util.Enumeration

Enumerate through a Vector using Java Enumeration Example.This Java Example shows how to enumerate through elements of a Vector using Java Enumeration.

Enumeration provides two methods to enumerate through the elements. It's hasMoreElements method returns true if there are more elements to enumerate through otherwise it returns false. Its nextElement method returns the next element in enumeration.

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]

Reference Books:

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. */

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.

Copy Elements of ArrayList to Vector Example

Copying ArrayList elements from Vector is so simple by using predefined method in Collections class.
Collections.copy(vector,arrayList);
Java Collections_ArrayList to Vector Example_JavabynataraJ
/*This java example shows how to copy elements of Java ArrayList to Java Vector using
copy method of Collections class.
*/

Copy Elements from one ArrayList to Another ArrayList

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) 

DeployingWAR FileWith Sun Java SystemApplication Server

>> Saturday, October 16, 2010

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

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.

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.