This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes interview question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interview question" Watch "interview question" New topic
Author

interview question

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
in some interview question ...
i found someone...
can you pls give me the detail answer of each...
I didn't understand thier answer thats why posting here..


Q1. What comes to mind when someone mentions a shallow copy in Java?

A. Object cloning.

???

Q2. How can you minimize the need of garbage collection and make the memory use more effective?

A. Use object pooling and weak object references.



Q3. What comes to mind when you hear about a young generation in Java?

A. Garbage collection.




Q4. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?

A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.


Thanks and Regards, Amit Taneja
ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
hi
i will give ans to u r 1st question
what is mean by shallow copy
it is funda of object serialization and cloninig
u might know what is mean by cloaning most of the time we want to create
copy of object which has same initial state in that case we are using cloaning
class has attributes and properties
whereas object has state and behaviour
instance variables might be primitive or non primitive
when we clone object of class which has non primitive variables only
reference get copied not actual object
this is known as shallow copy
i think u get more accurate and ans in graphical form in Head first java
ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
ans to ur 2 nd question
try to create anonymus object
Arjun K
Ranch Hand

Joined: Mar 09, 2005
Posts: 39

Taken From: amit taneja
Q2. How can you minimize the need of garbage collection and make the memory use more effective?
A. weak object references.

Check this good link for java object references.
http://www.ociweb.com/jnb/archive/jnbJune2000.html


Taken From: amit taneja
Q3. What comes to mind when you hear about a young generation in Java?
A. Garbage collection.

The allocated objects are divided in generations according to their ages, and young generations are checked more often than the older ones. On young generation fill up the objects will be moved up to old generation and permanent generations.

Also you can decide on young generation partitions and sizes with
-XX:NewSize
-XX:MaxNewSize
-XX:NewRatio
-XX:SurvivorRatio

HTH,
Arjun.
ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
Thanks arjun for sending such a wonderful site
actually i am also looking for diff types of reference
Philip Heller
author
Ranch Hand

Joined: Oct 24, 2000
Posts: 119
Suppose you have the following class:


A shallow copy clones an instance's instance variables. So when copying an instance of Aaa, the values of i, f, and c would be duplicated. That's what you would expect for the primitives i and f, but what's happening with c, which is a reference? Since c is duplicated, the copy points to the same Color object as the original.

Often that's what you want, and when that's the case you can use the version of clone() that you inherit from Object(). But you might want to use a clone of the Color object, instead of referencing the original. (This would happen when you want to modify the clone, without affecting the original.) In this case you're on your own: you have to override clone().


Consultant to SCJP team.<br />Co-designer of SCJD exam.<br />Co-author of "Complete Java 2 Certification Study Guide".<br />Author of "Ground-Up Java".
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
hello,

one question from a not-so-native english speaker:

hi
i will give ans to u r 1st question
what is mean by shallow copy
it is funda of object serialization and cloninig
u might know what is mean by cloaning most of the time we want to create
copy of object which has same initial state in that case we are using cloaning
class has attributes and properties
whereas object has state and behaviour
instance variables might be primitive or non primitive
when we clone object of class which has non primitive variables only
reference get copied not actual object
this is known as shallow copy


can we try to stick a bit with the english we all learned at school? answers like this add an additional level of difficulty for me, this sort of acronym-morse-style is really really hard to understand. at least for me ;-)

would be very very nice & cool,

greetings from germany,
jan
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
I agree jan, and I am a native english speaker.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
You are not alone: http://faq.javaranch.com/view?UseRealWords


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
sorry friends
i regret it 's my mistake from next time onward i will try to post topics not in shortforms.
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
Originally posted by Arjun K:

The allocated objects are divided in generations according to their ages, and young generations are checked more often than the older ones. On young generation fill up the objects will be moved up to old generation and permanent generations.

Also you can decide on young generation partitions and sizes with
-XX:NewSize
-XX:MaxNewSize
-XX:NewRatio
-XX:SurvivorRatio

HTH,
Arjun.


didn't get it what do u mean by this ??
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
Originally posted by amit taneja:
didn't get it what do u mean by this ??


i'm not really sure what you meant, since parsing non-standard english can be a treacherous and difficult job — this is only my third language, after all. but i think the person you were quoting was talking about certain features of a generational garbage collector, such as the one used by Sun's JVM.
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
good link there arjun...cleared up the idea of weak/strong/soft and phantom references


"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: interview question