Steve Aldrich

Greenhorn
+ Follow
since Jan 31, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Steve Aldrich

See Question From KAM on >>> and >> Operators for the explanation. Shifts of int when the operand is a multiple of 32, or shifts of long when the operand is a multiple of 64 don't shift the value at all.
"01234".substring(2,2) returns ""
class Test1
{
public static void main (String[] args)
{
String a = "0123456";
String b = a.substring(2,2);
System.out.println(b.equals("") );
System.out.println(b );
System.out.println("0123456".substring(2,2).equals("") );
}
}
By the way, shifting never rolls the number back, unless you are shifting zero with << or >>>, or FFFFFFFFF with >>, in which case the shifts are useless.
>> will eventually fill any negative value with 111111111 and any positive value with 0000000.
>>> will eventually fill any value with 00000
<< will fill any value with 0000 too.
When you shift with >>> the bit shifted into the high bit, the most significant bit is always zero, therefore the result is always positive, as long as you shift at least one bit.
When shifting an int, the shift operand is mod 32, so x >>> 35 means shift x right, shifting in zeroes, 3 times.
x >>> 32 means shift x right zero times! No shift at all.
When shifting a long however, the shift operand is mod 64.
So, the reason that the value is always positive except when the shift operand is divisible by zero is because when you shift by a multiple of 32, (when shifting an int) you don't shift any bits at all!
If you shifted a long value, and you shifted by 96, you would shift 32 bits! because 96 % 64 is 32.
The thread can run even if ThreadQuickSort quits. When the method quits, all local variables no longer have meaning, their stack space is gone. The final variables and parameters of the method will still exist after the local variables have gone away, and will still be available, and valid, for use by the thread.
main is static. Main can run with no instance of Outer ever existing. Even is Outer were abstract you could still run main.
The construction of
Inner i = new Outer().new Inner(); creates an unnamed reference to Outer, through that instance the constructor of Inner is then called. So, there is an instance of Outer and Inner holds an implicit reference to it. Outer won't get garbage collected until the reference to Inner ( "i" ) is gone.
You can say Inner i = new Outer().new Inner(); instead of Outer.Inner i = new ... because Inner is in scope.
You can't use Inner i = new Inner(); within main because main is static. In main, there is no instance of Outer. There is no "this"
Inner can never be constructed without an instance of Outer, whether that instance of Outer is held by anything or not doesn't matter.
All the way up to Object, with any set of parameters along the way.
Ex. b extends a b () { super (1,2)}
a extends base a(int i, int j) { super ("oh boy")}
base base("String s") { super( "name", "address") } etc. etc.