Results 1 to 4 of 4
Thread: System.out.println
- 03-20-2008, 10:06 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 12
- Rep Power
- 0
System.out.println
Hello,
The java application I work on has thousands of System.out.println statements. Now I have to make all these S.o.p's execute only if a condition is true and restrict executing them if the condition is false.
I cannot put the check at all the places where S.o.p statement is written in the code. Can somebody suggest a way out where I can have one common method which I can replace it with all the S.o.p's in the application?
Any help would be appreciated.
- 03-21-2008, 04:57 AM #2
System.setOut(PrintStream out)
or AOPdont worry newbie, we got you covered.
- 03-21-2008, 10:22 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 3
- Rep Power
- 0
hi sunjavaboy
You Can use Initialization Blocks
print one if statement
{
if (true)
}
like that
My Regards
- 03-22-2008, 01:30 AM #4
Member
- Join Date
- Feb 2008
- Location
- Oregon, USA
- Posts
- 49
- Rep Power
- 0
If you still need help, perhaps it would be easier to see your posted code, or if you like your privacy, an example.
I would use for statements, like in the below code
Here is an example of MyPrintObjectJava Code:/* place this code wherever is preferable, I apologize for any mistakes in my code */ // the total number of println statements, i used the name objects for MyPrintObject int objects = 20; // all the lines you don't want to print, I chose random numbers int[] exceptions = {2, 5, 7, 15, 17} // other variables MyPrintObject[] p = new MyPrintObject[objects]; boolean makeTrue = true; for (int i = 0; i <= objects; i++) { makeTrue = true; for (int x = 0; x <= totalExceptions; x++) { if (i == exception[x]) // if this object is equal to one of the exceptions, make it false makeTrue = false; } if (makeTrue) p[i] = new MyPrintObject(true); else p[i] = new MyPrintObject(false); } // print objects for (i = 0; i <= objects; i++) { if (p[i].print()) // for information on the print() method, see below System.out.println(i); }
Java Code:/* My very simple MyPrintObject class */ public class MyPrintObject { private boolean print; public MyPrintObject() { print = true; } public MyPrintObject(boolean b) { print = b; } public boolean print() { return print; } }Last edited by Bluefox815; 03-22-2008 at 01:33 AM.
Similar Threads
-
Template for System.out.println
By eva in forum EclipseReplies: 3Last Post: 01-05-2008, 12:46 PM -
shortcut of System.out.println() without netbeans
By VipinKeshri in forum New To JavaReplies: 1Last Post: 11-18-2007, 09:24 AM -
Eclipse - shortcut to System.out.println
By Java Tip in forum Java TipReplies: 0Last Post: 11-07-2007, 04:21 PM -
System.out.println shortcut
By ravian in forum EclipseReplies: 2Last Post: 11-07-2007, 10:17 AM -
Help me with system.out.println
By baltimore in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks