This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!

Rajinder Yadav

+ Follow
since May 13, 2003
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rajinder Yadav

an anonymous class does extend the Object class, an anonymous class is simply an un-named class
you can try this yourself, create an anonymous class and check it against the Object class using the instanceof operator.
I would like to correct S Goyal about heaps and stacks.
It seems like s/he was taking about data structures, in which case a heap is a data structure based on the "weight" of the element, either the min or max weighted element can be popped off the top (root), a heap is a tree sturucture, and does not work in a first in last out manner.
The stack data studcture is first in, last out, not 1st in 1st out.
In terms of java:
the heap is an area of memory that is allocated dynamically (at runtime) where object are created.
so String s = new String("hello"); will created a string object s on the heap
the stack can mean the call stack, when one function call another function, java places the return call address on top of the stack. when a function return, java pop the stack and get the address of where the last call came from.
So if function A call function B which in terms class function C.... then the call stack will look like this
call stack:
[c] <- top
[a] <- bottom (1st in last out)
items are pushed and popped from the top of the stack... picture stacking a plate of dishes... the order you can get them back is in reverse... 1st in last out
Hope this helps!

Originally posted by S Goyal:
Pool is an unorganised group.. any one item /objectcan be picked when u request for one.. like for example connection pool
Heap is first in last out
Stack is First in First out

Was there something more to that line, hard to tell what context this statement was being used in?
The word 'invariant' means unchangable, something that is constant.
Read what Corey said earlier
s1 is created on constant string constant pool
s2 and s3 are created on the heap
s1 -> "ABC"
s2 -> "ABC"
s3 -> "ABC"
Also one should know how the java.lang.Math functions behave with the inputs:
Have fun
Here are some more interesting boundry cases.
the instanceof operator works up a class hierarchy, not acorss
peter is right, the compiler is able to see this and thus gives you an error

class a and b are both instances of class base
class a is not an instance of class b and vice versa
I don't have Dan's url but i do have a link to this site which you may find helpful.
Take a look at this program

Lets take a look at the output for string s2:
The reason s2 outputs, 'nullhello' is because two key things: a) operator precedence, b) how the overloaded '+' operator works with strings.
1 the '+' operator get evaluated 1st
2 since '+' is overloaded to perform string concatenation, null is converted into a string object (see output for s1), this result is appended with "hello"
3 the assignment operator assign s2 the newly constructed string "nullhello"
also note the output for strings s3 and s4, the + operator is evaluated left to right!
so in s3, integer arithmetic is performed 1st and the sum is converted into a string when it's added to the string "sum"
the operation is done in the following order
((2+2) + "sum")->(4 + "sum")->("4" + "sum") = "4sum"
in s4 since we have a string object on the left side of the + operator the other literals are converted into a string, the operation is done in the following order
(("sum" + 2) + 2) -> ("sum2" + 2) = "sum22"
I hope this clears things up
[ May 20, 2003: Message edited by: Rajinder Yadav ]
from what the java compiler is telling me it seems static methods do get inherited and that one can override a static method :roll:

1. if you run the program below, you will see that static method are not polymorphic
2. in class foo, if you add final to the who method you will get an error, which seems to indicate static methods do get inherited
Compiler error who() in foobar cannot override who() in foo; overridden method is
static final
public class test{ static public void main(String[] arg) {
test t = new test(); t.showWhoCalled(new foo()); t.showWh
oCalled(new foobar()); } void showWhoCalled(foo f) {
System.out.println(f.who()); }}class foo{ final static String who() { retu
rn "foo"; }}class foobar extends foo{ static String who() { return "foobar"; }
3. if you removed the keyword static from the who() method in class foo and foobar, you will see the polymorphic behaviour
(*) conclusion: class static methods to get inherited, can be overridden but are not polymorphic

[ May 19, 2003: Message edited by: Rajinder Yadav ]
only string literal contants are placed in the runtime string constant pool
String s1 = "This is a string literal";
String s2 = s1.SB.substring(0,16);
s2 references a String object created on the heap at runtime
The call to SA.substring(0,6) returns a temporary String object, so you are comparing the reference values of two temp String objects that will be different in your code.
String comparison should be done using the:
String.equals(Object obj)
This method is inherited from the java.lang.Object class
In your code example, SA and SB end up creating a single String object in the java rutime String constant pool. That is the references SA and SB are pointing to the same object, so the 1st reference comparison ends up being true!
If you created the string on the heap then the 1st comparision would be false... run this modified code to see what I mean

[ May 19, 2003: Message edited by: Rajinder Yadav ]
I read on Jane's website that:
* main() is inherited and can be overridden if not declared as final
This does not make sense to me? because main needs to be declared as a class static method. When I think inheritance, I think polymorphic behaviour, so how can a static method be inherited and overridden? You are not allowed to use the 'this' or 'super' keyword inside of main.
[ May 18, 2003: Message edited by: Rajinder Yadav ]
If you examine the code class Test has access to a reference of class Outer which is ok. Also the method 'int getI()' in not declared private inside the Inner class, it has default access privilege. So the code should compile and run ok.
If you add private to the:
int getI()
then you should see a compile time error like so: getI() has private access in Outer.Inner
System.out.println( outer.getInner().getI() );
1 error

My guess is that declaring Class Inner as private has to do with visibility when subclassing is invloved? Can someone clear this up for me??
Ryan it's helpful ... That was quick, Thank you, but I still need the visibility information between packages.
[ May 16, 2003: Message edited by: Rajinder Yadav ]