Asif Garhi

Greenhorn
+ Follow
since Jul 24, 2007
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 Asif Garhi

Run the below code to get that exception.
Never heard of it and cant find the reason too.
Please help.

import java.util.*;
class genn
{
public static void main(String ... X)
{
List<String> l = new ArrayList<String>();
l.add("namaste");
for(String s:l)
{
l.add("howDoUDo");
}
System.out.println(l);
}
}
Hehe.Nice one.
Thanks Dhwani.
Ranchers .. how to remember all the keywords there are 50.
Is there any technique other than memorizing?
Thanks Robert,
Hope to be doing classpath questions dead right in the exam.
Might appear on the 30th of this month.
Pray for me friend.
Dude keep this dream sequence in mind when you do a new()

1.Instance variables are given their Default values.
2.Super constructor is called.
3.Other instance variables that are given initial value as a part of declaration are assigned values or init block is run --- *whichever appears first in the code*.
4.Rest of the constructor finishes.

Try to do these while solving your query you will get the answer.

Also remember that static initializer if there in your code are the first thing to happen before any of the above activities.

Right Ranchers?
Consider JVM as an old lady.
Consider the try block as a strong guy.
The strong guy is trying to hit the old lady with a ball.
But catch who's a good guy catches the ball and saves the lady.
Now the good guy catch turns bad and decides to throw either the same or any other ball to the old lady.
You need to save the lady now.
Because our previous catch has turned bad we need some other good soul to save the lady.
That other good soul would be either specified using throws or what you can do is define a nested try catch in the good turned bad catch and throw the new ball in this nested try and catch it in the nested catch.

All right ranchers?
Robert nice explainations,thanks.
One more doubt though.
why in a and b is xcom being searched?
Is it bcoz we have specified package xcom at the top of both the classes.
As far as i know this happens when you use the -d option with javac.
[ July 25, 2007: Message edited by: Asif Garhi ]
Nothing better than object diagrams.
e.g.
String s1 = new String("Asif");
make a diagram where you make a say circle,put "Asif" in it and make s1 to point to it.
Suppose now you have
String s2 = new String("Garhi");
s1=s2;
just break the arrow (pointing from s1 to "Asif") and make it to point to "Garhi".
Now 2 arrows point to "Garhi" one each from s1 and s2 and nothing points to the "Asif" object.Keep doing this till the end of your program (or till a place where you intend to) and all the circles or objects to which nothing is pointing are all eligible for GC.

It always works for me.
Ranchers .. are there any exceptions to above rule?

[ July 25, 2007: Message edited by: Asif Garhi ]
[ July 25, 2007: Message edited by: Asif Garhi ]
Hey the above was a cool way of sorting things out.
Here is what i did

class A{}
class B extends A{}
class C extends B{}

public class overloaded
{
static public void ovMe(A a,A b){}
static public void ovMe(A a,B b){}
static public void ovMe(A a,C b){}
static public void ovMe(B a,B b){}
static public void ovMe(B a,C b){}
static public void ovMe(C a,B b){}
static public void ovMe(C a,A b){}
public static void main(String...S)
{
ovMe(new C(),new C());
}
}

In accordance with above explainations i always knew this was asking for trouble.But just couldnt understand the way compiler slapped:

overloaded.java:16 reference to ovMe is ambigous,both method ovMe(A,C) in overloaded and ovMe(C,B) in overloaded match.

Why did the compiler chose these two methods finally before throwing the error?
Given the default class path /foo
and the following dir structure
foo
test
xcom > A.class and B.java in xcom

And these two files

package xcom;
public class A{}

package xcom;
public class B extends A{}

Which allows B.java to compile?

A.Set the current directory to xcom and invoke
javac B.java

B.Set the current directory to xcom and invoke
javac -classpath . B.java

C.Set the current directory to test and invoke
javac -classpath . xcom/B.java

D.Set the current directory to test and invoke
javac -classpath xcom B.java

E.Set the current directory to test and invoke
javac -classpath xcom: . B.java


Can any1 tell me 1 by 1 why does B,D and E fail?
See dude ..
I think you hvnt studied C++ ..
Consider a situation where your boss asks you to write a sorting algorithm that works for all the data types i.e. pass it say ten chars or ten ints it should work equally well for both.The only thing you can do is make use of generics.You write your class or function in such a way that it changes its behaviour according to what data type you pass to it.

List<String> is a list of Strings as opposed to List<Integer> that would work for Integers.

So List interface is generic,it will act according to what you pass it.
This way the coders of List interface had to write the code only once using generics and it can be used according to need.
Apart from the above explainations ..
I guess the only place you can call sizzle() is the pop() method itself!!!
I v bin preparin since a couple of months
and now the condition is such,i cant solve more than 10 questions at a stretch...the concentration just fades after that...I v my date on the 31st.Shall i take a break of say a couple of days or put in more as it comes close???
Dude jus keep preparing and remember that exam owners can make any topic difficult or easy!!!