Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Very interesting question

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He All!
Please take a look at this question from Brainbench (Java 2 Fundamentals):

Which one of the following keywords has the highest associated active CPU usage?
a) Throw
b) Final
c) Break
d) Continue
e) While

What answer is right and why?
Give me any advice about this, please!
[ September 06, 2005: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this an SCJP question?

Swapna.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not an interesting question, because it is irrelevant to SCJP.
Moving to Java in General (Intermediate).
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I vote for throw and while.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alexey

Welcome to Javaranch!

First, I don't think this is right forum for this question. (Duh... To late - moved )

Second, all java keywords are lowcase.

Third, I believe that the question is not correct. For me that is for sure.

Forget about Brainbench. Look what we've got here for you.
[ September 06, 2005: Message edited by: George Bolyuba ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well "Continue" has got more letters, perhaps it takes more CPU cycles to scan that? Java is an interpreter is it not?
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"continue", "break" and "final" are all basically gotos.

Usually a "throw" throws a new exception, so I'd say that the throw statement includes the instantiation of a new Exception object, probably with a String argument.

The CPU usage for a "while" depands on the condition. Loading a simple boolena variable and either branching or not is pretty damn quick, but evaluating a complicated expression that contains a bunch of method calls could take indeterminately long.

I guess I'd vote that a "while" with a complicated expression would take the most CPU, but the question is so poorly defined it's hard to answer definitively.
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well "Continue" has got more letters, perhaps it takes more CPU cycles to scan that? Java is an interpreter is it not?





psssst... javac takes care of "continue", not java.
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea what the question aims at. The inclusion of the final keyword seems like a red herring. The thing in the rest of the group that doesn't belong is the throw keyword. throw is most goto-like, in that it allows a jump in flow control outside the current method context. That change in control is certainly more expensive than other forms of flow control, all other things being equal.

Way back in the early days of Java we threw out the unfounded horror story that exception handling was more expensive than in-method flow control by an order of magnitude. The idea at the time, I guess, was to tell everyone not to use exceptions unless they wanted to -- and that we didn't trust them to do the right thing, which is why we had to scare them.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alexey Korneychuk:
He All!
Please take a look at this question from Brainbench (Java 2 Fundamentals):

Which one of the following keywords has the highest associated active CPU usage?
a) Throw
b) Final
c) Break
d) Continue
e) While

What answer is right and why?
Give me any advice about this, please!



Bizzare question and rather pointless I think, but I'll give it a shot anyway...

c), d) and e) all will translate into JMP instructions ultimately. Not sure how many cycles the JVM takes but in x86 assembler it is just 1 cycle. I can't think of b) in terms of CPU usage but a) looks like the best choice as mentioned above creation of the Exception object etc. Anyway, I think it is a stupid question to ask.
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kevin Arouza:


Bizzare question and rather pointless I think, but I'll give it a shot anyway...




Originally posted by Kevin Arouza:

c), d) and e) all will translate into JMP instructions ultimately. Not sure how many cycles the JVM takes but in x86 assembler it is just 1 cycle.


Are your sure?

I think I've found right answer here.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic