It's not a secret anymore!
The moose likes Beginning Java and the fly likes puting println in a brief variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "puting println in a brief variable" Watch "puting println in a brief variable" New topic

puting println in a brief variable

Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
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
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
create a method

Then you can use it like:
p("print me");

"JavaRanch, where the deer and the Certified play" - David O'Meara
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

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)
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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.

I agree. Here's the link:
subject: puting println in a brief variable
jQuery in Action, 3rd edition