Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

umang bhartia

Ranch Hand
+ Follow
since Sep 29, 2000
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by umang bhartia

Hello every1,
Why answer is 3? transient values can not b retrived, so the answer should b 4.
import java.io.*;
public class TransientWriter implements Externalizable
{
private transient String s = "Hope I can ever be persistant!";
public void writeExternal(ObjectOutput oOut) throws IOException
{
oOut.writeObject(s);
}
public void readExternal(ObjectInput oIn) throws IOException,
ClassNotFoundException
{
s=(String)oIn.readObject();
}
public String toString()
{
return s;
}
}
class K
{
public static void main(String args[]) throws IOException,
ClassNotFoundException
{
TransientWriter tw = new TransientWriter();
ObjectOutputStream out = new ObjectOutputStream(new
FileOutputStream("tw.out"));
out.writeObject(tw);
ObjectInputStream in = new ObjectInputStream(new FileInputStream("tw.out"));
TransientWriter tw2 = (TransientWriter) in.readObject();
System.out.println(tw2);
}
}
Attempting to compile and run the above code
1. will cause a compiler error due to the attempt to write a transient object.
2. will cause a runtime exception when an attempt is made to write a transient
object.
3. will not cause any runtime error and the transient object is writen to the
file named "tw.out".
4. will not cause any runtime error and the transient object is not written to
the file named "tw.out". The program prints a blank line on the screen.

Hello every1,
here is the code
import java.awt.*;
public class TestFrame extends Frame
{
Button bNorth = new Button("North");
Button bSouth = new Button("South");
Button bEast = new Button("East");
Button bWest = new Button("West");
Button bCenter = new Button("Center");
public TestFrame()
{
setLayout(new FlowLayout());
add(bNorth);
add(bSouth);
add(bWest);
add(bEast);
add(bCenter);
setLayout(new BorderLayout());
validate();
setSize(300,300);
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
Attemping to compile and run the above code
1. Will cause a compilation error - a Layout cannot be set after a component
has been added with a preset Layout Manager.
2. Will cause a Runtime Exception - a Layout cannot be set after a component
has been added with a preset Layout Manager.
3. Will compile cleanly and throw no runtime Exception. Only the button with
label "Center" is visible and occupies the whole screen.
4. Will compile cleanly an throw no runtime Exception. All the buttons are
arranged in a single line. Any other component added in future will follow the
rules of the BorderLayout Manager.
5. Will compile and run cleanly, but no component is visible.

Answer is 5:
But when i use BorderLayout in case of flow layout in case1 and changing all the five buttons added to different location of BorderLayout, and then changing the layout to flowLayout. Doing this it is showing the buttons in a row ie in FlowLayout, then why it is not showing other way round.
Hello every1,
Here is the code
interface One
{
public void someMethod();
}
public class One_impl implements One
{
public native void someMethod();
}
Assuming that the native method is not provided in any local library, an
attempt to compile and run the above lines of code will cause
1. Compilation error - implimentations can never be native.
2. Compilation error - method not found in local libraries.
3. Runtime Exception - method not found in local libraries.
4. Compilation successfull but runtime error is thrown if and only if the
method someMethod of class One_impl is called.

Answer is 4:
I thought that as the interface is extended and its given that the native method is not provided in library, then it would b compiler error. Can any one explain me why the answer is 4
Can any one explain me what r Daemon Thread. Well i have read that Daemon thread dies when the thread taht created them dies, and if a thread is a daemon then any thread it creats will automatically be daemon. But i can't actually understand what this Daemon is, how can v invoke them.
thank u.
Hi every1
when i try the code as under it prints true.
System.out.println("abc".replace('a','a')=="abc");

Well i dont have any problem with this, but when i modify this code like
System.out.println(1+ "abc".replace('a','a')=="abc");
it gives me false, please can any one tell me the reason of change in output.
thank u
i agree with Ash,
as it is asked number of objects eligible for GC at line 6, so the answer would b 10, as even though temp is out of scope in line 6, the local variable still has reference.
GC
Hello every1,
can we know when a thread is elegible for GC. If the answer is yes then please explain me with reason. What i think is that we can never know about the thread being GC.
thanks
Hello every1
code:
case 1:
final int j =10;
byte b =j;// no error

case 2:
int i =10;
final int j = i;
byte b = j;//error
In first case it compiles fine, and b is assigned the value of j. But in second case it gives me error. Can some one throw some light as to why this is giving error in one case but not in another.
thank u
IF v go according to Bill, then the output should b "A" ie prints "Sample". This is because of the semicolon after the if statement. So even though if condition is false it will execute sample(). Correct me if i m wrong.
class end
{
public static void main(String[] args)
{
if("String".endsWith(""))
System.out.println("True");
else
System.out.println("False");
}
}
Output: True
Can any one explain how the output is true
Anil,
the object created at line 2 will b eligible for GC, as u have asigned a new reference to object b, so now there is no reference to the object which has been created at line 2. This is the reason that it will b eligible for GC.
Hi Nasir,
I think that only one object is created in the above code and that is after appending s1 and s22 a new String object is returned to s3. I dont think that the empty StringBuffer that u are talking about will b considered.
No doubt in any case the string object will b available for GC only after '}' of the main method. Please correct me if i m wrong.
Sarim the reason for this error is that when it comes accross the throw line then it directly jump to the catch statement and the println line is never executed, so it is giving u this error. Give the statement of throw in if block, and then try the code it will not give u this error any more.
gridwidth and gridheight specify the number of cells occupied by the component horizontally and vertically in the grid. while weightx and weighty is used to set the % of increase in the component size with respect to that of the container. the default value for weightx and weighty is zero, meaning that the area allocated to the component does not grow beyont the preferred size fo the component.
Yes sarim u r right, the number of characters visible in a text field depends on the font u r using. If u provide a text field for 40 characters then its not possible to view 40 characters even if u change the font. The number of columns is a measure of the size of the text line according to the particular font used for rendering the text. However for a fixed pitch fonts, the number of columns is equal to the number of characters in the text line. Hope i m clear