Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

puting println in a brief variable

 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
In my program I user System.out.println() very often
There is a way to put it in a variable and use a brief name instead
Example :
System.out.println(�this print command�);
p(�this print command�);
There is a way to print it in other color??
Thanks in advance
Shay
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create a method

Then you can use it like:
p("print me");
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen many program examples where they get a new reference to the OutputStream in an interface

Then all classes can have:

(hope I got it right, I don't use System.out so I haven't tried this)
Dave.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm anticipating something here...

If you're using System.out.println()'s to provide helpful output during development, there is a "poor man's" to quickly enable and disable these statements, that also provides a very optimized class file.

If you declare a class-wide final variable LOGGING = true
And you surround your output statements with if (LOGGING) { } blocks, then two things can be gained.

One... you can very rapidly redefine LOGGING = false to turn off this output.
Two... because the variable is final, the compiler will evaluate the if() and either include the output lines into the classfiles or not. It can do this because final variables can never be changed. So if you say LOGGING = false, then the if statements will *always* be false, and the compiler does not waste time and space including your output lines in the class file.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic