• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Vector

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
Can u please enlighten me about the follg?
1.What is granularity in code?
2.In the book "Thinking in Java" it is given
You can add objects to Vector without complaint at either compile time or at run time.
What is the meaning of saying adding objects at compile time and run time?
Thanks in advance
Indira.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
The would say that granularity of code is directly related to modularity in coding.But it has a broad meaning when related to the whole application i.e the optimized code, less memory leakage, granularity in comments and many more..
The second query that u have asked is about vectors.
See, vectors have the capabilty to increase their capacity at run time automatically and developers don't have to worry about the size of vector as in the case of array. That's why u can add the objects in it at compile time as well as at run time without bothering of the size of vector.
I think this would help u.
bye
pankaj
------------------
SCJP2
 
Indira Devi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pankaj
Thanks a lot.
Can i have some sample code to distinguish between adding objects to vectors at compile time and at run time?
Thanks once again
Indira.
 
pankaj bansal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Indira
I'm sending u this code that will surely help u to see that how the capacity of vector inc. at runtime. One thing I want to point out is that anything that is done with objects is at runtime and not at compile time.
import java.util.*;
class DemoVector
{

Vector v=null;
public static void main(String args[])
{
DemoVector d=new DemoVector();

d.v=new Vector(2,2); // will inc. by 2 automatically
System.out.println("size:"+d.v.size());
System.out.println("capacity:"+d.v.capacity());
d.v.addElement("pankaj");
System.out.println("size:"+d.v.size());
System.out.println("capacity:"+d.v.capacity());
d.v.addElement("bansal");
System.out.println("size:"+d.v.size());
System.out.println("capacity:"+d.v.capacity());
// You can use in this way
d.addToVector(d,"Prateek");
System.out.println("size:"+d.v.size());
System.out.println("capacity:"+d.v.capacity());

}
void addToVector(DemoVector d,String s)
{
d.v.addElement(s);// capacity of vector will inc at run time

}

}
------------------
SCJP2
 
reply
    Bookmark Topic Watch Topic
  • New Topic