Hamraj Kulshreshtha

Ranch Hand
+ Follow
since Oct 06, 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 Hamraj Kulshreshtha

Please help me out to download db2jcc.jar.
I need it very urgently.I have already searced it out,but not getting any result.
Quick response will be appreciated.

Regards,
Hamraj Kulshreshtha
13 years ago
In the below program why all the threads are running even if exception appears in the first thread.
As per my thinking the program should terminate after the first thread and no more thread should run.

public class Threadtest implements Runnable{
public static void main(String args[]){
Threadtest threadtest = new Threadtest();
Thread t1 = new Thread(threadtest);
Thread t2 = new Thread(threadtest);
Thread t3 = new Thread(threadtest);
Thread t4 = new Thread(threadtest);
t1.start();
t2.start();
t3.start();
t4.start();
}
public void run(){
int i=0;
System.out.println(5/i);
i++;
System.out.println("thread is : "+ Thread.currentThread()+" running ");
}

}
Why the result of the below code is false??


import java.util.*;
class Test
{
public static void main(String[] args)
{
int[] a = new int[]{1};
int[] b = new int[]{1};
System.out.println(a.equals(b));
}
}
Hi All,

Please tell me how combination of these quantifiers works:

import java.util.regex.*;
class Regex1
{
public static void main(String[] args)
{
Pattern p = Pattern.compile("\\d*+");
Matcher m = p.matcher("ab34ef");

while(m.find()){
System.out.println(m.start() +" "+m.group());
}
}
}

As i know that:
* -------> zero or more occurrence
+ -------> one or more occurrence
? -------> Zero or one occurrence

suppose my input string is "ab34ef" and comparing string is "\\d*","\\d+" and "\\d?" then i will get the output if i put these comparision in the above code:

for "\\d*" -------output will be 01234456
for "\\d+" -------output will be 234
for "\\d?" -------output will be 012334456

But what will be the output if i use comaprision string like "\\d*+","\\d*?".
I am not able to draw conclusion from the output ,how exactly combinations of these quantifier working.
Please help.

Also please explain me the exact difference between greedy, reluctant and possessive quantifiers with some real example.



[ January 09, 2008: Message edited by: Hamraj Kulshreshtha ]
[ January 09, 2008: Message edited by: Hamraj Kulshreshtha ]
Hi Sweety,

Since static methods doesn't behave polymorphically ,so it is said that redefining the method or hiding the method.

For example:

class Parent{
static void add(){System.out.println("In Parent");}
}
class Child extends Parent{
static void add(){System.out.println("In child");}

public static void main(String[] args){
Parent p = new Child();
p.add();
}
}

Here on calling p.add() method parent class method will be called, unlike the Overriding .
Please give the explanation why the output is not coming as "ab" in this code??
Instead the code is running without any output.

class ExceptionTest
{
public static void main(String args[]) throws Exception
{
try
{
throw new Exception("a");
}
catch(Exception e)
{
throw new Exception("b");
}
finally
{
return;
}
}
}
Regards,
Hamraj
In K&B page 476 & 477, the following expression is given:

0[xX][0-9a-fA-F] // 1st

0[xX]([0-9a-fA-F])+ // 2nd

First expression is clear. Second expression is not clear because i don't find example related to 2nd expression.

Can anyone provide any example of pattern so that i can understand it clearly.


Regards,
Hamraj
Below is the code:

import java.util.regex.*;
class RegexTest123
{
public static void main(String... args){
Pattern p = Pattern.compile("\\w*");
Matcher m = p.matcher("ab234 ab5_6ba");
while(m.find()){
System.out.println(m.start() +" "+m.group());
}
}

}
Output is 0 ab234
5
6 ab5_6ba
13
My string length is (0-12) ,but why i am getting the index 13 in the output.

And also as per my understanding, * means zero or more occurance.
So "w*" should be a greedy quantifier.
So 0 will tends to ab234
5 will tends to space
6 will tends to ab5_6ba.

Please correct me, if i am wrong???
Since the instance init blocks run right after the call to super() in
a constructor,so r3 will be printed first and then r2.

And if more than one init blocks(Static or Instance) occurs in a class they run in the same order as they are defined i.e. from top to down.

Regards,
Hamraj
Since String Buffer is mutable and string is immutable so both behaves differently.

And please see the funda of String Pooling .You will be very clear after that.

Regards,
Hamraj
Thanks a lot, Marc.

I understood this very well.

Thanks once again.
Hi Marc,

I am explaining the things what i am understanding with this code,so i hope you will able to understand my problem.

In method(Fizz x, Fizz y) f1, f2 are passed.
Since f1 is marked as final,so we can't change the
value of f1.
but in method, method(Fizz x, Fizz y)

f1 is passed to x, so final Fizz z = x means final Fizz z = f1.

So z.x = 6 shouldn't be changed as it is assigned as final.
Why the code is not giving the compile time error.Since final variable can't be changed.

One thing more which i am doubtful is how final object works, because here its not a final variable its a final object(final Fizz f1 = new Fizz();)?
Because i know about final variable, final method and final class.
Hi Yehia,

Thanks for your reply.

Regards,
Hamraj
Sorry for my typo.
My answer was c1 and c3 will be eligible for garbage collection.
Since when go method is called,it returns null. which is referenced by c3.
so c1 and c3 should be correct.

But what does this mean that(as per K&B explanation) "C is correct.Only one CardBoard object (c1) is eligible, but it has an associated Short wrapper object that is also eligible."
Please help me for this doubt.
This question is from K&B 3rd chapter, 8th question.
What will be the output on the line,System.out.println();
The correct answer is A.
I am not getting the explanation given in K&B.
The explanation is as "The references f1, z, and f3 all refer to the same instance of Fizz. The final
modifier assures that a reference variable cannot be referred to a different object, but final
doesn�t keep the object�s state from changing."


class Fizz {
int x = 5;
public static void main(String[] args) {
final Fizz f1 = new Fizz();
Fizz f2 = new Fizz();
Fizz f3 = FizzSwitch(f1,f2);
System.out.println((f1 == f3) + " " + (f1.x == f3.x));
}
static Fizz FizzSwitch(Fizz x, Fizz y) {
final Fizz z = x;
z.x = 6;
return z;
} }
What is the result?
A. true true
B. false true
C. true false
D. false false
E. Compilation fails.
F. An exception is thrown at runtime.

Regards,
Hamraj