This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes get fooled with this programs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "get fooled with this programs" Watch "get fooled with this programs" New topic
Author

get fooled with this programs

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
referring to Burkhard Hassel post
this is his program




i ran this program but unable to get the output (and also runtime exception)

if i remove lineX from this program it runs correctly..(displays the ouput)

thanks


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Petrus Pelser
Ranch Hand

Joined: Feb 20, 2006
Posts: 132
You created an infinite loop which results that your program runs out of memory. Change the > to <.

Also remove the lineX: label as you are only allowed to label loops.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
No ..

Change i++ to i-- and change list.add(i); to list.add(new Integer(i));

int != java.lang.Integer
[ October 10, 2006: Message edited by: B L Scholtz ]
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Objection, your honor!


Saikrishna Cinux wrote:
referring to Burkhard Hassel post
this is his program]

No, you changed it a bit, see here.



And, I also posted in the original thread:
"I know, what's wrong with this code snippet. So you don't need to post it here!"

My intention was something else. Fortunately, Harshad Khasnis just wrote it (also on the original thread).



Objection 2:
Petrus Pelser wrote:
Also remove the lineX: label as you are only allowed to label loops.

This is wrong.
The following snippet compiles and runs happily:

But, admitted, these labels don't make any sense.

And, by the way, Petrus said also
Change the > to <.

Nice trap. See why?




Objection 3:
B L Scholtz wrote:
Change i++ to i-- and change list.add(i); to list.add(new Integer(i));
int != java.lang.Integer

True, but as you can see from the use of generics, the code must be java 5, not earlier. And in java 5, autoboxing would do that job.


Yours,
Bu.


all events occur in real time
Harshad Khasnis
Ranch Hand

Joined: Jun 06, 2006
Posts: 48
Bu wrote:


Saikrishna Cinux wrote:

quote:referring to Burkhard Hassel post
this is his program]


No, you changed it a bit, see here.



And, I also posted in the original thread:
"I know, what's wrong with this code snippet. So you don't need to post it here!"

My intention was something else. Fortunately, Harshad Khasnis just wrote it (also on the original thread).




Hi Sai,
The original topic was a total different issue of discussion.
It was not a technical issue at all.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Originally posted by saikrishna cinux:
referring to Burkhard Hassel post
this is his program




i ran this program but unable to get the output (and also runtime exception)

if i remove lineX from this program it runs correctly..(displays the ouput)

thanks


It depends on how much heap space you have as to whether it will throw an OutOfMemoryError at runtime.

Remember that the int primitive is not the same as an integer.

With a real integer, i+1 > i for all i.

But if int i = Integer.MAX_VALUE, i+1 is a negative number.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Originally posted by Burkhard Hassel:

True, but as you can see from the use of generics, the code must be java 5, not earlier. And in java 5, autoboxing would do that job.


Very nice stuff. I am still from the world called Java 1.4. But at the end of this year I have the chance to do the SCJP for Java 5. There's changed a lot in the generics.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get fooled with this programs
 
Similar Threads
LinkedList problem
LinkedList using Generics
Adding null values into a LinkedList
List
Saving to a txt file