473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Tricky stuff

11,448 Expert 8TB
As everybody knows (or should know) the following is useless:

Expand|Select|Wrap|Line Numbers
  1. private static int x= 42;
  2. ...
  3. x= x++;
  4.  
The value of x will stay 42. Or does it? Have a look at the following little experiment
and try to figure out what is happening:

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
kind regards,

Jos
Jun 23 '07 #1
43 1976
prometheuzz
197 Expert 100+
It's because 42 is a special kind of integer, of course!
; )

Here's another one:

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         double a = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1;
  6.         double b = 0.8;
  7.  
  8.         System.out.println("Are a and b the same? "+(a==b));
  9.     }
  10. }
The output is "Are a and b the same? false". How is this possible?
It's not for you Jos: I know you know the answer.
Jun 24 '07 #2
JosAH
11,448 Expert 8TB
It's not for you Jos: I know you know the answer.
I don't want to participate in any contest that wants me to participate :-P

kind regards,

Jos (duh ;-)
Jun 24 '07 #3
It's because 42 is a special kind of integer, of course!
; )

Here's another one:

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         double a = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1;
  6.         double b = 0.8;
  7.  
  8.         System.out.println("Are a and b the same? "+(a==b));
  9.     }
  10. }
The output is "Are a and b the same? false". How is this possible?
It's not for you Jos: I know you know the answer.

I'm new at programming so I'm going to take a calculated guess. The answer for a = 0.7999999999999999 . The reason being double belongs to Floating-point numbers which represent numbers with fractional precision. Double doesn't round off a number.

Petra
Jun 24 '07 #4
JosAH
11,448 Expert 8TB
I'm new at programming so I'm going to take a calculated guess. The answer for a = 0.7999999999999999 . The reason being double belongs to Floating-point numbers which represent numbers with fractional precision. Double doesn't round off a number.

Petra
Very close; bookmark this document and read it when you find some spare time.

kind regards,

Jos

ps. now what about that x == 42 thingie in my original post?
Jun 24 '07 #5
sumittyagi
202 Expert 100+
As everybody knows (or should know) the following is useless:

Expand|Select|Wrap|Line Numbers
  1. private static int x= 42;
  2. ...
  3. x= x++;
  4.  
The value of x will stay 42. Or does it? Have a look at the following little experiment
and try to figure out what is happening:

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
kind regards,

Jos

Why is it useless?
x is not declared final, and thus is not a constant.

It's because 42 is a special kind of integer, of course!
; )
I didn't get this line. It would be great if you could explain this one.
Thanks!

Regards,
Sumit Tyagi.
Jun 25 '07 #6
JosAH
11,448 Expert 8TB
Why is it useless?
x is not declared final, and thus is not a constant.
So you're not surprised by the output it shows?


I didn't get this line. It would be great if you could explain this one.
Thanks!
42 is 54 using base 13.

kind regards,

Jos
Jun 25 '07 #7
r035198x
13,262 8TB
Why is it useless?
x is not declared final, and thus is not a constant.



I didn't get this line. It would be great if you could explain this one.
Thanks!

Regards,
Sumit Tyagi.
It's not a constant alright but when you do
Expand|Select|Wrap|Line Numbers
  1. while(true) {
  2.       x = x++;
  3. }
the value of x does not change since x will be assigned to the previous value always which will be the initial value. The post increment won't take any effect there. But when a thread is reading off the values of x ...
Jun 25 '07 #8
As everybody knows (or should know) the following is useless:

Expand|Select|Wrap|Line Numbers
  1. private static int x= 42;
  2. ...
  3. x= x++;
  4.  
The value of x will stay 42. Or does it? Have a look at the following little experiment
and try to figure out what is happening:

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
kind regards,

Jos

Let see if I can get this right. The value stays at 42 because of the while statement. In laymans terms while x == 42 the system prints out x != 42 and the program is ended. Everytime you re-run the program you keep getting the same answer. You will never get to the second while statement.
Jun 25 '07 #9
r035198x
13,262 8TB
Let see if I can get this right. The value stays at 42 because of the while statement. In laymans terms while x == 42 the system prints out x != 42 and the program is ended. Everytime you re-run the program you keep getting the same answer. You will never get to the second while statement.
Put the program on your compiler and test it. Realize also that there are two threads running here.
Jun 25 '07 #10
sumittyagi
202 Expert 100+
So you're not surprised by the output it shows?
Yea! I am not surprized by the output, because output is as I expected it to be.
---------- java ----------
x= 42
x != 42
Normal Termination
Output completed (1 sec consumed).


42 is 54 using base 13.
But how does that make a difference. I mean does this fact have any influence on the output.
Jun 25 '07 #11
r035198x
13,262 8TB
Yea! I am not surprized by the output, because output is as I expected it to be.
...
Would you then care to explain why the value of x changes (or seems to change)?
Jun 25 '07 #12
sumittyagi
202 Expert 100+
It's not a constant alright but when you do
Expand|Select|Wrap|Line Numbers
  1. while(true) {
  2.       x = x++;
  3. }
the value of x does not change since x will be assigned to the previous value always which will be the initial value. The post increment won't take any effect there. But when a thread is reading off the values of x ...
x++ is having a side effect of incrementing the value of x.
so it will be solved as follows:
x = x++;
x = 42 (value replaced, so x becomes 42);
x++ (x++ have side effect of incrementing x, so now x becomes 43);
Jun 25 '07 #13
prometheuzz
197 Expert 100+
Yea! I am not surprized by the output, because output is as I expected it to be.
---------- java ----------
x= 42
x != 42
Normal Termination
Output completed (1 sec consumed).
Huh? Have we compiled and run the same code (from the original post)? I don't get that output!


But how does that make a difference. I mean does this fact have any influence on the output.
That was a joke of me (42 being a special kind of integer).
Jun 25 '07 #14
sumittyagi
202 Expert 100+
Huh? Have we compiled and run the same code (from the original post)? I don't get that output!
Then what output are u getting?

That was a joke of me (42 being a special kind of integer).
There are a lots of things in java that make you bite your finger, so I never take any statement as joke.

But that was nice one!!! LOL.
Jun 25 '07 #15
r035198x
13,262 8TB
Then what output are u getting?



There are a lots of things in java that make you bite your finger, so I never take any statement as joke.

But that was nice one!!! LOL.
I'm getting Sumit's output and I don't think the output is platform dependant (or is it?).
Jun 25 '07 #16
sumittyagi
202 Expert 100+
42 is 54 using base 13.
JosAH! you are having very good sense of humor.
LOL.
Jun 25 '07 #17
prometheuzz
197 Expert 100+
@sumittyagi & r035198x:

Now I'm confused...
The output I get is this: x= 42, and the application keeps running, which was what I had expected. I though that was what Jos had meant by this: the fact that the line of code "System.out.println("x= "+x);" would or wouldn't be executed. Because the lines of code before that println() gets executed in it's own thread, "System.out.println("x= "+x);" gets executed, of course. I didnt think much of it, and I didn't find it tricky at all!

But I would have been surprised if x != 42 would be printed as well. I've compiled and run the code with Eclipse, which does not use Sun's javac, and with Sun's javac. Both of them produce the same output: x= 42.
Jun 25 '07 #18
prometheuzz
197 Expert 100+
... and I don't think the output is platform dependant (or is it?).
No, I can't imagine that.
Jun 25 '07 #19
r035198x
13,262 8TB
@sumittyagi & r035198x:

Now I'm confused...
The output I get is this: x= 42, and the application keeps running, which was what I had expected. I though that was what Jos had meant by this: the fact that the line of code "System.out.println("x= "+x);" would or wouldn't be executed. Because the lines of code before that println() gets executed in it's own thread, "System.out.println("x= "+x);" gets executed, of course. I didnt think much of it, and I didn't find it tricky at all!

But I would have been surprised if x != 42 would be printed as well. I've compiled and run the code with Eclipse, which does not use Sun's javac, and with Sun's javac. Both of them produce the same output: x= 42.
I get x != 42 printed alright (vista and jdk 1.5)Which OS are you using?
I thinks that's why Jos is actually questioning whether x stays as 42 or not. Because x actually appears to change in this one and the program terminates.
Jun 25 '07 #20
sumittyagi
202 Expert 100+
@sumittyagi & r035198x:

Now I'm confused...
The output I get is this: x= 42, and the application keeps running, which was what I had expected. I though that was what Jos had meant by this: the fact that the line of code "System.out.println("x= "+x);" would or wouldn't be executed. Because the lines of code before that println() gets executed in it's own thread, "System.out.println("x= "+x);" gets executed, of course. I didnt think much of it, and I didn't find it tricky at all!

But I would have been surprised if x != 42 would be printed as well. I've compiled and run the code with Eclipse, which does not use Sun's javac, and with Sun's javac. Both of them produce the same output: x= 42.
I really don't know how u r getting that output. that is really strange.
Now its out of my knowledgebase.
so one thing we can do is....

SOS... signals to josAH!!!!
Jun 25 '07 #21
sumittyagi
202 Expert 100+
I really don't know how u r getting that output. that is really strange.
Now its out of my knowledgebase.
so one thing we can do is....

SOS... signals to josAH!!!!
Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
  19.  
the kind of output you are saying is only possible in case when control doesn't leave main thread till main thread vanishes (i.e non-preemptive scheduling at OS level).

try executing this code, and tell us what the output u r getting.

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         while(true) {
  16.            x=x++;
  17.            System.out.println("x= "+x);
  18.         }
  19.     }
  20. }
  21.  
Jun 25 '07 #22
sumittyagi
202 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
  19.  
the kind of output you are saying is only possible in case when control doesn't leave main thread till main thread vanishes (i.e non-preemptive scheduling at OS level).

try executing this code, and tell us what the output u r getting.

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         while(true) {
  16.            x=x++;
  17.            System.out.println("x= "+x);
  18.         }
  19.     }
  20. }
  21.  
Sorry! I think I misunderstood the concept, and went on saying according to that. I think the thing I said about non-preemptive scheduling is not the cause.

And now I got it, why josAH said it is tricky stuff.
try this code.

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static volatile int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
  19.  
I think now you should get the same output as we are getting.
Jun 25 '07 #23
blazedaces
284 100+
This is my output:

Expand|Select|Wrap|Line Numbers
  1. --------------------Configuration: <Default>--------------------
  2. x= 42
  3. x != 42
  4.  
  5. Process completed.
I'm still confused though, why is this tricky? Shouldn't ++ following a variable tell the compiler do this variable = variable + 1 only after you complete the statement on this line? So wouldn't x = x++; tell the compiler ok, x = x, now that you're done, do x = x + 1?

Is this not exactly what happens? I would be surprised if it didn't happen and I'm getting the impression that there are situations where that is the case from you guys?

Interesting topic anyway...

-blazed
Jun 25 '07 #24
prometheuzz
197 Expert 100+
Sorry! I think I misunderstood the concept, and went on saying according to that. I think the thing I said about non-preemptive scheduling is not the cause.

And now I got it, why josAH said it is tricky stuff.
try this code.

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static volatile int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
  19.  
I think now you should get the same output as we are getting.
Nope, still the same: only x= 42 is printed to the console. Both Eclipse and Sun's compiler do this. Also, before recompiling with javac, I removed all .class files, just to be sure.
Jun 25 '07 #25
prometheuzz
197 Expert 100+
I get x != 42 printed alright (vista and jdk 1.5)Which OS are you using? ...
I can't imagine it's the OS, but here's what I use:
Windows XP
Eclipse SDK 3.2.0
Sun's JDK 1.6

I'll also try my Linux box when I get home.
Jun 25 '07 #26
r035198x
13,262 8TB
I can't imagine it's the OS, but here's what I use:
Windows XP
Eclipse SDK 3.2.0
Sun's JDK 1.6

I'll also try my Linux box when I get home.
Bart, look at Jos' thread again (I mean Java thread), when started it simply does
Expand|Select|Wrap|Line Numbers
  1. System.out.println( "x != 42" );
His while is of no importance because he has a semi colon after it. So as long as that thread starts, the program exits printing x != 42 when x actually is 42.
Jun 25 '07 #27
prometheuzz
197 Expert 100+
...
His while is of no importance because he has a semi colon after it.
...
I don't see why it is of no importance. It keeps looping on that while in the java.lang.Thread.
When I execute this code:

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff {
  2.  
  3.     private static int x = 42;
  4.  
  5.     public static void main(String[] args) {
  6.         (new Thread() {
  7.             public void run() {
  8.                 while(x == 42){ System.out.println("x is the same"); }
  9.                 System.out.println("x != 42");
  10.                 System.exit(0);
  11.             }
  12.         }).start();
  13.  
  14.         System.out.println("x = "+x);
  15.  
  16.         while(true) { x = x++; }
  17.     }
  18. }
First x = 42 is printed and then x is the same keeps being printed to the console. It never reaches x != 42. At least that's what's happening here. Really.
Jun 25 '07 #28
r035198x
13,262 8TB
I don't see why it is of no importance. It keeps looping on that while in the java.lang.Thread.
When I execute this code:

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff {
  2.  
  3.     private static int x = 42;
  4.  
  5.     public static void main(String[] args) {
  6.         (new Thread() {
  7.             public void run() {
  8.                 while(x == 42){ System.out.println("x is the same"); }
  9.                 System.out.println("x != 42");
  10.                 System.exit(0);
  11.             }
  12.         }).start();
  13.  
  14.         System.out.println("x = "+x);
  15.  
  16.         while(true) { x = x++; }
  17.     }
  18. }
First x = 42 is printed and then x is the same keeps being printed to the console. It never reaches x != 42. At least that's what's happening here. Really.
It's definitely platform dependant then. When I run that version I get different results each time.
The first statements are either "x = 42"
or "x is the same" with "x is the same" repeated sometimes then it prints "x != 42" and exits.


I've got "x = 42" printed after "x is the same" sometimes (but I have it printed only once both times). Your output assumes that Jos' thread is the only thread that getting executed once it starts.
Jun 25 '07 #29
nomad
664 Expert 512MB
As everybody knows (or should know) the following is useless:

Expand|Select|Wrap|Line Numbers
  1. private static int x= 42;
  2. ...
  3. x= x++;
  4.  
The value of x will stay 42. Or does it? Have a look at the following little experiment
and try to figure out what is happening:

Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff {
  2.  
  3.  
  4. public static void main(String[] args) {
  5.  
  6. (new Thread() {
  7. public void run() {
  8. while(x = 42);
  9. System.out.println( "x != 42" );
  10. System.exit(0);
  11. }
  12. } ).start();
  13.  
  14. System.out.println("x= "+x);
  15. while(true) { x=x++;}
  16. }
  17. }
kind regards,

Jos
System.out.println( "x != 42" ); just prints x!=42 it has no value other than printing out text.

while(true) { x=x++;} is skiped durning the run.

nomad
Jun 25 '07 #30
JosAH
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
When I run this code (Eclipse 3.2 Java 1.6.0_01) I get as output:

Expand|Select|Wrap|Line Numbers
  1. x= 42
  2. x != 42
  3.  
and the process never stops; the other thread has terminated but the main
thread keeps on running. When I change the 'while (true)' thing in the main
thread to, say:

Expand|Select|Wrap|Line Numbers
  1. boolean flag= true;
  2. while (flag) ...
  3.  
I only get the output 'x= 42'. It is tricky stuff; when the compiler compiles whithout
optimizing anything x does become 43 for a very short moment and after the
old value (42) is stored in x again. If in that very short moment the other thread
tests for the value of 'x' it can terminate its while loop. The main thread never
terminates though.

It all depends on thread scheduling and when the values of 'x' are written back
to main memory where all (both) threads can access it. It is tricky stuff indeed ;-)

kind regards,

Jos
Jun 25 '07 #31
blazedaces
284 100+
Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
When I run this code (Eclipse 3.2 Java 1.6.0_01) I get as output:

Expand|Select|Wrap|Line Numbers
  1. x= 42
  2. x != 42
  3.  
and the process never stops; the other thread has terminated but the main
thread keeps on running. When I change the 'while (true)' thing in the main
thread to, say:

Expand|Select|Wrap|Line Numbers
  1. boolean flag= true;
  2. while (flag) ...
  3.  
I only get the output 'x= 42'. It is tricky stuff; when the compiler compiles whithout
optimizing anything x does become 43 for a very short moment and after the
old value (42) is stored in x again. If in that very short moment the other thread
tests for the value of 'x' it can terminate its while loop. The main thread never
terminates though.

It all depends on thread scheduling and when the values of 'x' are written back
to main memory where all (both) threads can access it. It is tricky stuff indeed ;-)

kind regards,

Jos
Wow, really cool to know. Good stuff man...

-blazed
Jun 25 '07 #32
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. public class TrickyStuff  {
  2.  
  3.     private static int x= 42;
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         (new Thread() {
  8.             public void run() {
  9.                 while(x == 42);
  10.                 System.out.println( "x != 42" );
  11.                 System.exit(0);
  12.             }
  13.         } ).start();
  14.  
  15.         System.out.println("x= "+x);
  16.         while(true) { x=x++;}
  17.     }
  18. }
When I run this code (Eclipse 3.2 Java 1.6.0_01) I get as output:

Expand|Select|Wrap|Line Numbers
  1. x= 42
  2. x != 42
  3.  
and the process never stops; the other thread has terminated but the main
thread keeps on running. When I change the 'while (true)' thing in the main
thread to, say:

Expand|Select|Wrap|Line Numbers
  1. boolean flag= true;
  2. while (flag) ...
  3.  
I only get the output 'x= 42'. It is tricky stuff; when the compiler compiles whithout
optimizing anything x does become 43 for a very short moment and after the
old value (42) is stored in x again. If in that very short moment the other thread
tests for the value of 'x' it can terminate its while loop. The main thread never
terminates though.

It all depends on thread scheduling and when the values of 'x' are written back
to main memory where all (both) threads can access it. It is tricky stuff indeed ;-)

kind regards,

Jos
It has to be a very short period of time indeed because when I put
Expand|Select|Wrap|Line Numbers
  1. while(x == 42);
  2.                 System.out.println(x+ " x != 42" );
it always printed "x = 42 x != 42".
Your sleeves are tricky place to be Jos.
Jun 25 '07 #33
JosAH
11,448 Expert 8TB
It has to be a very short period of time indeed because when I put
Expand|Select|Wrap|Line Numbers
  1. while(x == 42);
  2.                 System.out.println(x+ " x != 42" );
it always printed "x = 42 x != 42".
Your sleeves are tricky place to be Jos.
Could very well be: the System.out Stream is shared too between the two threads.
I have never seen that output but it isn't impossble. You stated that your process
terminates in a previous reply; that's the part I don't understand: the main thread
should loop until hell freezes over ;-)

kind regards,

Jos
Jun 25 '07 #34
JosAH
11,448 Expert 8TB
Your sleeves are tricky place to be Jos.
ps.

One should always explore the darkest corners of a (programming) language to
really get to know the language ;-)

kind regards,

Jos
Jun 25 '07 #35
r035198x
13,262 8TB
...You stated that your process
terminates in a previous reply; that's the part I don't understand: the main thread
should loop until hell freezes over ;-)

kind regards,

Jos
Isn't it that after "x != 42" is printed then System.exit(0); terminates the program?
Jun 25 '07 #36
JosAH
11,448 Expert 8TB
Isn't it that after "x != 42" is printed then System.exit(0); terminates the program?
Ah, yes, of course (I'm a bit tired), I was wrong of course; forget that remark.
What also surprises me is that Prometheuzz doesn't get that output; tricky stuff ...

kind regards,

Jos
Jun 25 '07 #37
r035198x
13,262 8TB
Ah, yes, of course (I'm a bit tired), I was wrong of course; forget that remark.
What also surprises me is that Prometheuzz doesn't get that output; tricky stuff ...

kind regards,

Jos
There's quite a few tricky areas in Java too. Remember that JFrame named Ghost?
Jun 25 '07 #38
JosAH
11,448 Expert 8TB
There's quite a few tricky areas in Java too. Remember that JFrame named Ghost?
Erm, nope; enlighten me please; I like tricky things ;-)

kind regards,

Jos
Jun 25 '07 #39
r035198x
13,262 8TB
Erm, nope; enlighten me please; I like tricky things ;-)

kind regards,

Jos
If you call a JFrame or awt Frame "Ghost" on some windows platforms (windows XP is one of them) it wont be displayed even if you do setVisible(true);
Jun 25 '07 #40
r035198x
13,262 8TB
If you call a JFrame or awt Frame "Ghost" on some windows platforms (windows XP is one of them) it wont be displayed even if you do setVisible(true);
Something like

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. public class Test {
  3.   private static JFrame ghost = new Ghost(); 
  4.  
  5.   public static void main(String[] args) {
  6.       ghost.setVisible(true);
  7.       System.out.print("You can't see me");
  8.   }
  9.  
  10. }
  11.  
  12. class Ghost extends JFrame { }
  13.  
Won't show on both 1.4 and 1.5 on XP
Jun 25 '07 #41
JosAH
11,448 Expert 8TB
Something like

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. public class Test {
  3.   private static JFrame ghost = new Ghost(); 
  4.  
  5.   public static void main(String[] args) {
  6.       ghost.setVisible(true);
  7.       System.out.print("You can't see me");
  8.   }
  9.  
  10. }
  11.  
  12. class Ghost extends JFrame { }
  13.  
Won't show on both 1.4 and 1.5 on XP
Cute! I have Java 1.6 and the window does show; tomorrow at the office I'll try it
on a previous Java version. I like those Easter Eggs ;-)

kind regards,

Jos
Jun 25 '07 #42
r035198x
13,262 8TB
Cute! I have Java 1.6 and the window does show; tomorrow at the office I'll try it
on a previous Java version. I like those Easter Eggs ;-)

kind regards,

Jos
It's always good to see the program disobey you for once. I'm tempted to stick this so people can people can keep the treats coming.
Jun 25 '07 #43
sumittyagi
202 Expert 100+
It's always good to see the program disobey you for once. I'm tempted to stick this so people can people can keep the treats coming.
Great!!!!!
It was a yummy thread!!!! So many surprizing things.
I enjoyed it a lot.
Jun 26 '07 #44

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Felipe Gasper | last post by:
I'm trying to make some "sub-cells" in an HTML table and to control their positioning and content presentation via CSS. In the table at the following URL: ...
19
by: Kai-Uwe Bux | last post by:
Hi folks, I have trouble writing a class, derving from stringstream, that collects item and once it's done will write them to std::cout in one go. It works fine except when I use it as a...
25
by: PyPK | last post by:
What possible tricky areas/questions could be asked in Python based Technical Interviews?
3
by: Chris Capel | last post by:
I want to do something along the lines of this: class someclass { static void Main() { int i = 5; int j = 3; changevalue(ref i, j); Console.WriteLine(i.ToString()); //I want this to output 3...
6
by: Thomas Tomiczek | last post by:
Ok, working my way through a complex library conversion to .NET 2.0 and C# 2.0 with generics I am totally stuck on one thing -if anyone sees the issue I would be more than glad. The situation is...
5
by: Sebastian | last post by:
Here's the thing I have a web aplication (1.1) and one of my classes has an array as a property (let's say Class A, has an ArrayList of Bs). On the other side I have a win form app which uses web...
11
by: seberino | last post by:
How extract the visible numerical data from this Microsoft financial web site? http://tinyurl.com/yw2w4h If you simply download the HTML file you'll see the data is *not* embedded in it but...
17
by: joebenjamin | last post by:
This is a problem I was trying to help a few friends figure out for fun. I am not sure how to go about this, but there is something I am missing here. Here is what we want the output to be: Need...
7
by: Osiris | last post by:
Just something I would like to share: I just learned the hard way (2 days detective work on a bug) that foreach loops are not at all like for loops, not intuitive at all. BEWARE: arrays and...
9
by: raylopez99 | last post by:
Just an observation: pens for drawing lines in Win Forms are tricky when assignment is inside the paint handler. inside of the Paint handler, but not inside a "using" brace (that is, outside of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.