Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

debugging

 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just wondering if when you do this:
int debug = 1;
and then somewhere down in your program you do:
if(debug == 1)
System.out.println(mydebuginfo);
if you happen to want to set debug to 0 as in
int debug = 0;
and you compile your program, are the if statements automatically ignored by the compiler, or is the program going to check every time to see if debug == 1 or not and slow my app down?
P.S. Plz don't welcome me to the forums... i've been snooping around a while before registering, and i personally consider it lame. thanks for the consideration (and yes I know you weren't going to...)
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi A.,
Welco... Uh, sorry. Don't want to be lame :roll:
If a constant boolean condition can be evaluated at compile time, Java compilers are indeed allowed to optimized out a branch to a block of unreachable code. That said, I'm not sure they do enough induction to optimize out something based on integer comparison to a constant. Jikes and javac definitely will optimize out tests of boolean constants, so if you use the more idiomatic

Then the test will definitely be optimized away.
You can answer this question for yourself, along with many related ones, using the "javap" tool that comes with the J2SDK. "javap -c MyClass" will disassemble MyClass to bytecode, and it's easy enough to check this kind of thing out.
 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. thanks! yes it looks like i'll have to fix my if statements with booleans.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34423
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not just an int vs boolean thing. In your example, the debug flag is not final. The compiler may not be able to guarantee that the flag does not change between assignment and the if statement.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WELCOME TO JAVARANCH A. WOLF!!!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i personally consider it lame.

Which part do you consider lame? The welcome part, or just our entire site?
Mark
 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WELCOME TO JAVARANCH A. WOLF!!!

NOOHOOHOHHOHOOO
Which part do you consider lame? The welcome part, or just our entire site?

the welcome part. what made you think i meant "our entire site?"
since I was talking about being welcomed, the "it" refers back to the subject although my punctuation may have been the cause for your confusion. The previous post makes me think I hurt someone's feelings and I hope this clears up any misunderstandings. ->
Sorry.
Welco... Uh, sorry. Don't want to be lame

He got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic