Results 1 to 4 of 4
  1. #1
    sunjavaboy is offline Member
    Join Date
    Mar 2008
    Posts
    12
    Rep Power
    0

    Question 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.

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    System.setOut(PrintStream out)

    or AOP
    dont worry newbie, we got you covered.

  3. #3
    eljarrah is offline Member
    Join Date
    Nov 2007
    Posts
    3
    Rep Power
    0

    Default

    hi sunjavaboy

    You Can use Initialization Blocks

    print one if statement

    {
    if (true)
    }

    like that


    My Regards

  4. #4
    Bluefox815 is offline Member
    Join Date
    Feb 2008
    Location
    Oregon, USA
    Posts
    49
    Rep Power
    0

    Default

    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

    Java 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);
    }
    Here is an example of MyPrintObject

    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 02:33 AM.

Similar Threads

  1. Template for System.out.println
    By eva in forum Eclipse
    Replies: 3
    Last Post: 01-05-2008, 01:46 PM
  2. shortcut of System.out.println() without netbeans
    By VipinKeshri in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 10:24 AM
  3. Eclipse - shortcut to System.out.println
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-07-2007, 05:21 PM
  4. System.out.println shortcut
    By ravian in forum Eclipse
    Replies: 2
    Last Post: 11-07-2007, 11:17 AM
  5. Help me with system.out.println
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 09:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •