Paul A

Ranch Hand
+ Follow
since Aug 25, 2000
Merit badge: grant badges
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Paul A

I would seriously suggest you to read some good java books like Thinking in Java ( get it for free from www.eckelobjects.com ) and the Java Tutorial on Sun site. The questions that you have asked are very fundamental. It won't do you much good even if somebody tells you the answers.
-Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
Because char is also an integral data type (which does not take -ive integers). When compiler tries to lookup a test method that takes a char, it doesn't find one so it looks for a closest (but eligible!) match, it finds the int version. So it promotes the char to int and calls that method!
HTH,
Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
Did you ever wonder how
String s = "hello";
s = s + 3; or s = s + true; or s = s + 'a';
works??
HTH,
Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
The concept of first question has been discussed a lot of times... anyway,
Point to remember is methods are overridden and vairables are shadowed.
Please see this post:
http://www.javaranch.com/ubb/Forum24/HTML/003599.html
Problem 2 is simple...isn't Pine a Tree too?? (Pine extends Tree)
so why should tree instanceof Tree ( where tree is actually refering to an object of class Pine) return false ?

HTH,
Paul.


------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
I'm sory if I hurt your feelings but I fail to understand how a fictious name which 'looks' professional is better than another fictious name which does not look professional.
I think a White collared criminal is no better than a dacoit!. In fact, a white collared criminal is far more dangerous.
But I agree with your point that this is your site, you pay the bills so you are the boss around here. I, of course, have no say and have no intention not to obey your rules but as this is a discussion group, I gave my views!

------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
Looks like the discussion is getting heated!!! (Again, this is no flame directed to anybody)
For the one who wants to talk/discuss with a 'professional'
. Consider this: A 'junkie' asks a genuine question on which he also has done some research... Posts his doubt clearly.
A 'Mr. Professional' (and there are lot of such people out here) who just dump a question a ask for an answer. He did not even bother to compile it and run the program.
I would like to answer 'junkie' rather than 'Mr. Proffessionl'.
. If somebody ask a question, I really don't think he is interesed in answerer's name. All he needs is a good answer.
Paul W, I understand that it is important to you because you are probably running the site or whatever. The reason might well be the ad revenues ( again, just a guess)...and this is perfectly understandable. But please don't give the reason of sounding 'professionalism/unprofessionalism' for use of valid names.
If you force people to do something like you suggested ...ok with me ...( I'm registered) but I have seen lots of discussion groups that have closed down because it required them to register etc.
I really appreciate this site for it's openness and I think this is a very imp. reason that this site is thriving.
I would say, don't kill the freedom...that's the spirit of the net.
You say, "Come on, am I really asking for that much in return?"
I say, "NO. It is perfectly valid and understandable to ask this. Just don't force it and do not give 'not-so-justifiable reason-of-prof/unprof to support it'.
thanks,
Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
Hi Ajith,
I understand your concern about people using 'unprofessional' names but I beg to differ from making this a strict rule.
What would you (or anybody) achieve by making a user give his true name/eid or a 'professional' name for that matter? All people need here are answers to their questions/doubts. How does it matter if I get an answer from 'Anonymous', 'Geek' or 'Paul A'?
And if I want to answer to sombody's question, I don't care if he/she calls himself XXX or whatever. Because I know that there is a genuine person behind that 'unprofessional' name.
I hope you know that in a normal classroom lots of students don't ask questions even if they do not understand what the teacher is saying. The reason is (most of the time) the fear of ambarasment( i know i spelt it wrong!). I remember, I did not ask a lot of questions because I thought that was a very silly doubt.
Such discussion forums porvide an opportunity to users to ask even silliest of question, which I think is a great benefit of being anonymous.
I would say, if somebody want's to be anonymous, that's ok. Also, as unregistered users can't modify their messages (and other lack of functions), I think it is a good built in mechanism to encourage people to register.
People are not here to show their professionalism here....there is enough scope for it in our jobs.
Come on, it's fun to write by a crazy sounding name!
These are just my views and I have no intention to flame anybody but people with 'professional' names who spread useless rumours about change of syllabus are the ones you should be concerned with rather than persons with 'unprofessional' names posting genuine questions.
thanks,
Paul.

------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
Geek, putting public in both the classes in same file is definitely a compilation error but this is probab. not what Sherri wanted to ask.
"when ever a class extends anotherclass,the sub class implicitly calls the no args constructor in the super class" is a vague and wrong statement. I don't know where did you get this quote from.
The concept is:
'Whenever a subclass's constructor DOES NOT call any of the superclass's constructor EXPLICITLY, the compiler puts super(); as the first line of that constructor'.
Eg.
class A
{
public A(int i){}
}
class B extends A
{
public B()
{
super(); //compiler will put it automatically and as there is no 'no-args' const. in A, this won't compile.
}
}
class C extends A
{
public C()
{
super(10); //compiler will NOT put anything here, as we are EXPLICITLY calling super class's constructor. This will of course compile! This is what is happening with your question.
}
}

HTH,
Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
Hi,
You have asked questions from :
Lang. Fundamantals, Threads, IO, AWT in the same post!!!
Most of these doubts can be easily clarified by looking into the API.
I would sincerely suggest you to read a good book on these topic.
BTW Aru, all of your answers except Q7 and Q8 are wrong.
I'ld love to answer the doubts but would not like to promote spoon feeding.
Hints:
1. null string is not same as empty string.
2. Your answer to 3 and 6 contradict each other.
3. Q5 says "might" (this means the Thread may or may not stop executing).
4. Asking Q8 shows 'somebody' does not know about JavaDocs!!!

HTH,
Paul.

------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
Well, we didn't think this will create so much of confusion...
String a = "java"; //1
char[ ] b = { 'j', 'a', 'v', 'a' }; //2
String c = new String(b); //3
String d = a; //4
A) (a == d)
Obviously, because of //4. and '==' checks whether both the references point to same memory location or not.
B) (b==d)
Obviously not as b is an array of chars and d is a String! (This one was for c/c== programmers.)
C)(a == "java")
Whenever you create string using just "" (ie. without using new keyword) you get an interned String. 'interned' means the JVM uses the same memory location to provide for different references which want to refer to same string (content wise).
So, this is true as both a and "java" are actually stored in the same place.
But if you do new String("java"); you are explicitly telling the compiler to create/store this string in a seperate location. so a == c is not true.
Even if :
c = new String("java"); or c = new String(a);
(Take note, Jane)
D) a.equals(c) is true.
This is a standard method which is implemented such a way that it checks whether the contents of both the references are same or not.
HTH,
Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!

[This message has been edited by Paul A (edited September 14, 2000).]
In other words:
b += 2; //is equivalent to
b = (byte) (b + 2); if b is byte etc.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
. Primitives are always passed by value.
. Object "references" are passed by value. So it looks like the object is passed by reference but actually it's the value of the reference that is passed.
A crude example:
Object o1 = new Object(); //say, the object is stored at memory location 15000. So o1 actually contains 15000.
now, when you call someMethod(o1); the value 15000 is passed.
Inside the method someMethod
someMethod( Object localVar)
{
......localVar contains 15000 so, whatever method you call or modication you do to this varibale, it is done on the original object. But when you try to change it's value, for eg. make it null, it then contains 000000 (say). But the original variable o1 still contains 15000 so it still points to the same object.
}

The next question is based on the above concept.

You created two objects in main method:
s1 ------------> [ EMPTY ] STACK 1 OBJECT
s1 actually contains 15000 (say)
s2 ------------> [ EMPTY ] STACK 2 OBJECT
s1 actually contains 25000 (say)
inside the method assign() :

Step 1:
s1 ----> [ EMPTY ] STACK 1 OBJECT <----x1 Local variable<br /> s1 and x1 both contain 15000 (say)<br /> s2 ----> [ EMPTY ] STACK 2 OBJECT <----x2 Local variable<br /> s2 and x2 both contain 25000 (say)<br /> <br /> Step 2;<br /> s1 -----> [ 100 ] STACK 1 OBJECT <----x1 Local variable<br /> Because x1 is refering to the same memory location.<br /> s2 -----> [ EMPTY ] STACK 2 OBJECT <---x2 Local variable<br /> Step 3: After doing x2 = x1<br /> s1 ---> [ 100 ] STACK 1 OBJECT <---- x1 and x2 Local variables<br /> s1 and x1 both contain 15000 (say) and x2 now also contains 15000.<br /> <br /> s2 ------------> [ EMPTY ] STACK 2 OBJECT
But s2 still contains 25000.
Note that it's the local variable x2 that is pointing to the same object as x1, which is s1 stack object. The original s2 (of the main method) is still pointing to the same object which is empty.
So when you come back to the main method, you print s1 (which has now 100) and s2( which is still empty)
HTH,
Paul.

------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
Because the compiler has no way to tell whether 'f' can or cannot possibly refer to an object of class CClass. And as there is an explicit cast, it believes the coder that the object refered to by 'f' 'may' actually refer to an object of class CCLass.
The point here is, if a compiler can figure out that some thing is just not possible in any case then it generates an error. For eg. had 'f' been of class CFace instead of interface Face, it would know that f can NEVER point to an object of class CClass as there is no relation between them ( none is a sub/super class of the other). So it would generate an error.
But as f is of interface Face, it just can't figure out whether
it can/cannot point to an object of class CClass. So it passes it. It will fail at run time though!
HTH,
Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!