Waez Ali

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

Recent posts by Waez Ali

Hi David,
I was waiting for your reply,
I got it now how to make marker Interface.

Thanks...
20 years ago
Hi Ernest,

Can you expalin it with some example.
When do we need to interrupt a thread when we already know that it will
throw exception if we do so

Thanks.
Hi Ernest,

Can You Please provide me sample Code.

Waiting For sample Code...
Thanks.
20 years ago
Hi Ernest,
Actually I read in khalid mughals book that

* Daemon Threads exist to serve child threads.
* First child thread that jvm creates when app starts is called as main thread.This Thread executes main().

-------------------Question?---------------------------------------------
So my question was what if there is no main()?
PLEASE EXPALIN ME WHAT DOES MAIN THREAD DO IN THIS SITUATION?
------------------------------------------------------------------------
And I also read

"Calling setDaemon(boolean) method in the Thread class marks the current thread as Daemon Thread or Child Thread(main Thread),but this must be done before Thread is started"

I am not getting
----------------------------------------------------------------------
how can we create Daemon Thread or Main Thread using that function?
PLEASE PROVIDE ME SAMPLE CODE....
----------------------------------------------------------------------

There can be only one Daemon Thread and one Main thread M I RIGHT?
like
Daemon
|
Main
__|__
| | |
t1 t2 t3

Am I correct about above fig?

waiting for your reply

Thanks.
Hi,
when a thread (in Non-Runnable state) gets interrupted by some other thread ,throws InterruptedException when transited to the Runnable state.
My question is
How one thread can be interrupted by some other thread.
How does it happen practically,I mean can we do it,it happens accedently?

Please Explain me

Thanks...
Hi,

I just want to know can i create my own marker interface(that doesn't contain any thing) for my class.
As Cloneable,Serializable are...

So Please Let me know.

Thanks.
20 years ago
Hi,
Is it possible to create user threads in a class that doesn't contain
main().
My understanding about threads is,main thread is just to serve user threads now if I have class that doesn't have main()....(eg. Applets)
Can i make any of my user thread as daemon or main thread so that they could serve remaining threads.
(if yes then Please provide sample code)


Thanks
Hello David,

Yes I got it.
Well I am very happy today,bkz I got to learn this cool concept of "protected".It became possible just bkz of you sir.
Thank you very much for your coopration
and thanks to Ernest Friedman-Hill also.
bye
20 years ago
Hello David,
When I try to compile your code it is showing two errors.
1 - as you have commented.
2 - as follows

B b = new B();
B bClone = (B) b.clone(); // ok, C is subclass of B
error-> ^clone() has protected access in Object class.

This error is really bothering me.I've also tried following declaration

class B implements Cloneable { }

for class B but still it does nothing.

Same thing i have been trying since from my first example.
please reply me soon about this error.

And thank you very much David for such a good explanation of Multi-Dim array question and helping me to learn about this Clone()

Thanks
20 years ago
Hi David,
As you said,
-----------------------------
Technically no. If you want to be able to have other methods call clone() on an object, you must override Object.clone() and give it public access
------------------------------
I have one question bothering me,

class Test{// Just like Object
protected void display()//just like clone() protected
{
System.out.println("Helo");
}
}
class CloneTest extends Test{
public static void main(String arg[]){
CloneTest obj = new CloneTest();
obj.display();//???
}
}

as the statement--> obj.display(); Is valid
then why not statement--> obj.clone();

I mean if CloneTest implements Cloneable and why not following stm.
--> CloneTest clone = (CloneTest) obj.clone();

Why protected clone() can not be called on an object as it is available to that object(as an instance method derived from Obect Class)
even in your code

public static TestCloneable clone ( TestCloneable tc ){
return (TestCloneable) tc.clone();}

you have called clone() on the object of that class,
at stmt--> return (TestCloneable) tc.clone()
But why have you called it indirectly ?I mean why it is not possible to call it like

TestCloneable tc = new TestCloneable();
TestCloneable clone = (TestCloneable) tc.clone();

Please explain it David.

Thanks.
20 years ago
hello Jeroen & David,
I am really sorry for that,I just misunderstood
actually I dont have work exp as I am a student & about to pursue my PG. But I like java very much and so preparing for SCJP1.4.
Well i have done(followoing code) what i was trying to do but still I have 3 more questions for you please dont mind.

class TestCloneable implements Cloneable{
public static void main(String arg[]){
TestCloneable obj1 = new TestCloneable();
obj1.display("Orignal");
try{
TestCloneable obj2 = (TestCloneable) obj1.clone();
obj2.display("Clone");
}
catch(CloneNotSupportedException cnse){
System.out.println(cnse);
}
}
protected Object clone()throws CloneNotSupportedException{
return super.clone();
}
void display(String message){
System.out.println("This is "+message);
}
}
output
This is Orignal
This is Clone
----------------
Question?
-1-------------------------------------------------------------------------
Is there any other way to create clone object without overriding clone() method(i mean just using it, as it is available to this class)?If yes then please consider the above code for modification.

Question?
-2-------------------------------------------------------------------------
Please check out the following code

class Amber {
public static void main(String[] args) {
int[][] a = {{1,2},{0,1,2},{-1,0,2}}; // 1
Object[] obj = (Object[])a.clone(); // 2
for(int i = 0; i < obj.length; i++) { // 3
int[] ia = (int[])obj[i]; // 4
System.out.print(ia[i]); // 5
}
}
}
--------
output
112

* How "a"[][](2Dim) can be assigned to "obj"[](OneDim)array at line 2 ?

* What exactly obj array is holding (refrences or elements) ?

* Howcome the output 112 ?


-3-------------------------------------------------------------------
Can you please provide me sample codes or examples that shows need or advantage of making clones.

Please Reply soon

Thanks.
20 years ago
class A13 implements Cloneable {
void disp(){
System.out.println("Cloned method");
}
}
public class clone{
public static void main (String[] args) {
A13 a = new A13();
A13 b = (A13) a.clone();
b.disp();
}
}

Error----------------------------------------------------------------------
clone() has protected access in java.lang.Object
---------------------------------------------------------------------------
To use a clone() on an object, class has to implement Cloneable Interface
I did that but i am not getting error as it says clon() has protected access

I have read that if a class doesn't have "extends" keyword in its
declaration then it implicitly extends Object.

So doesn't that mean, A13 & clone classes are subclasses of Object
so they should have access to clone().

May this concept is vague to me
Plese explain it.

Thanks.
20 years ago
HI,
If it allows [3][3] = [2][1]
then why it doesn't print ...
Plese check out this code.

class A13{}
public static void main (String[] args) {
A13[] a1 = new A13[1]; // 1
A13[][] a2 = new A13[2][1]; // 2
A13[][][] a3 = new A13[3][3][3]; // 3
a1[0] = new A13(); // 4
a2[0] = a2[1] = a1; // 5
a3[0] = a3[1] = a3[2] = a2; // 6
System.out.print(a3[2][0][0]); // 7
// System.out.print(a3[2][2][2]); // 8 Array index exception
}
output
------------
A13@1ea2
Why it doesn't print NULL at line 7 ?
Please explain it.

Thanks
20 years ago
Hi Peter,
Thanks for such a good explanation.
You are just great.

Thak you once again.
20 years ago