Does System.out.println() has a limit ?

I have this little program that permuates strings
public class PermutationGenerator
     private void perm(String s, String prefix)
          int length = s.length();
          if (length== 0)
          System.out.println(prefix);
          else
               for (int i = 0; i < length; i++)
                    perm(s.substring(0, i) + s.substring(i+1, length), prefix + s.charAt(i));
     public void printPermutations(String s)
          perm(s,"");
     public static void main(String[] args)
     new PermutationGenerator().printPermutations("word") ;
The problem is that when I use a longer string like "longword", I only get 299 different permutations printed. Even if I use an "evenlongerword", I will get 299 permutations. Is this because of java? Because I can't see any errors in my code.

You probably need to change your command prompt
screen buffer size. Sounds like you have the height
set to 300 lines. You can also redirect your output
to a file to see everything.Very well spotted! The voice of experience!

Similar Messages

  • Which toString() method does System.out.println() call?

    Which toString() method does System.out.println() call? I know that if I did something like System.out.println( new myClass() ) that the toString being called would be that of the myClass class.
    My initial thought about this was that System.out.println() is the equivalent of System.out.println( new Object() ) but I remember trying that in a test program and it gave me a myClass@some_hash_code type of message when adding the new Object() part within the System.out.println().
    Could someone please tell me which toString the System.out.println() statement calls? Also, it would be great if an elaboration follows :).
    Any input woudl be greatly appreciated!
    Thanks in advance!

    s3a wrote:
    My initial thought about this was that System.out.println() is the equivalent of System.out.println( new Object() ) Huh?
    In one method call you pass no parameters in the other method call you pass one parameter. How could you possibly think that they would do the same thing?
    Could someone please tell me which toString the System.out.println() statement calls? Also, it would be great if an elaboration follows :).Yes. The toString of the class of the object which you pass to the method. If that class does not have a toString method it uses the toString method it inherits from the parent class. If the parent class does not have a toString method it uses the one inherited and so and so on all the way up to the Object class.

  • How does System.out.println(). Work inside src.zip file !

    Hello guyz,
    I was just wondering how System.out.println() worked so i opened up the src.zip file and checked the source code. But could not understand it. As written i remember
    "out is an object encapsulated in the System class."
    Thats ok. But i could not understand the code.
        public final static PrintStream out = nullPrintStream();
        private static PrintStream nullPrintStream() throws NullPointerException {
         if (currentTimeMillis() > 0) {
             return null;
         throw new NullPointerException();
        }Also when i ran the DJ Decompiler it decompiled it to this:
    public class One
         public static void main(String args[])
              System.out.println("hello world");
    import java.io.PrintStream;
    public class One
        public One()
        public static void main(String args[])
            System.out.println("hello world");
    }Also, why does it need to import PrintStream ?

    Peter__Lawrey wrote:
    I was just wondering how System.out.println() worked so i opened up the src.zip file and checked the source code.This value is a place holder. This value is changed as soon as enough of the JVM is initialised for printing to work.
    Also, why does it need to import PrintStream ? It doesn't, but it is used in the code so DJ is including it just in case.Sorry,
    But i don't understand at all.

  • Where does System.out.println go?

    Hi Everyone: I know I've seen this topic before, but I'm still having some trouble. I would like to debug my EJBs, and so I've added some System.out.println statements to them. Where does that go? I've looked at the defaultTrace.trc files in the
    C:\usr\sap\P48\JC00\j2ee\cluster\server0\log
    folder, and haven't found any of the text that I think I am writing. I appreciate any guidance! Ian.

    Hi lan,
    I was facing the same question earlier, and now I think I have figured out one possible answer. Actually, where the System.out.println goes is up to the Server Admin to config. There is a default SYSTEM.OUT log controller ( under location controller side) pre-defined to cater for all System.out.println(). All the System.out.println() output is considered as INFO type log message. However, this default SYSTEM.OUT controller is not assigned with any real log destination, thus, we cannot find the output anywhere.
    If you goes to the log configurator (using Visual Admin), you can locate this SYSTEM.OUT controller , and add in a default (Anonymous) destionation for it . (you need to toggle on the advance edit mode from the top menu , then you can add modify the destination settings of a Controller).
    For Anonymous destionation, the println() output will sure go to the defaultTrace.trc (better view it using Log Viewer, instead of viewing it from the log file ).
    Or , you can define a separate file (e.g. c:\temp\myStd.log ) as the log destination ..
    Last but not the least, you need to set the ForceSingleTraceFile setting from 'YES' to 'NO' , then you can see your "myStd.log".
    To change the ForceSingleTraceFile , go to Visual Admin, J2EE server --> Kernel --> LogManager.
    Hope you find the above useful.

  • What does System.out.println("Hello world!");  when System.console()=null?

    Hello,
    the code below:
    if(System.console()!=null)
                outStream=System.out;
            else
                outStream=new PrintStream(new FileOutputStream(new File("BasicCardReaderManagerLog.log")));
            outStream.println(System.currentTimeMillis());
            outStream.println(System.out.toString());produce the following output, in the BasicCardReaderManagerLog.log file:
    1249991451796
    java.io.PrintStream@190d11
    So it looks like System.out is valid and usable, however, since the application as no console, where I can see the output ???
    Precision: I get this situation in the main function of a console application which I launch using Process.Start. Is there any way to get a console by this mean ?
    Best regards,
    Sebastien

    Based on [http://forums.sun.com/thread.jspa?messageID=10790600#10790600|http://forums.sun.com/thread.jspa?messageID=10790600#10790600]
    import java.util.*;
    public class Java {
         public static void main(String[] arg) throws Exception {
              String[] cmd = { "cmd.exe", "/C", "start", "java.exe" };
              List<String> l = new ArrayList<String>(Arrays.asList(cmd));
              l.addAll(Arrays.asList(arg));
              cmd = l.toArray(cmd);
              Process p = Runtime.getRuntime().exec(cmd);
    }

  • Where does System.out.println("") send info?

    Under normal java execution it goes to the java console... where does it go when running a servlet under Tomcat on localhost?

    Output is written to the log file whose location is specified in server.xml. The default is the /logs directory under the tomcat root.

  • System.out.println() fn in j2me

    Hello Everbody,
    can anyone plz tell that if i write down System.out.println() in my j2me app(in many classes and and at many places) and use it on mobile that app, does it slows down the app after sometime,bcz i m running the app it goes good for half anhour or so, but slows down after that and gets slower and slower does "System.out.println()" affect it or do thread creates the prob,plz clearify it, if any one knows,
    Thanks

    ask it in the j2me forum
    http://forum.java.sun.com/forum.jspa?forumID=76

  • System.out.println does not print out anything

    I'm wonder why the dos mode does not print out the System.out.println.
    My code has:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class test extends HttpServlet {
       public void doGet(HttpServletRequest request,
       HttpServletResponse response) throws IOException,
       ServletException {
          System.out.println("Hello");
    The compilation is ok... but it does not display anything... how come?

    "System.out.print()" prints to the log file of the tomcat server. in order to print on the screen use JspWriter.
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class test extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws IOException,
    ServletException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("Hello");
    //System.out.println("Hello");
    Hope this helps!

  • Where does the logging happens for System.out.println

    Hello:
    I'm usingNetWeaver 2004sJava SP9 evaluation version. Added some System.out.println to the ejbs. Would like to know where to look for the logging details in this case.
    Thanks for your help,
    Ravi

    Hi,
      By default, if the setting has been done, then it appears in defaultTrace as mentioned. For configuration of it, refer to this link.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/db315878-0801-0010-928e-98c8283616d3
    Reward points if it helps.
    Regards,
    Vijai

  • How does one intercept System.out.println stream.

    If you want some functionality wherein when you call System.out.println - the stream gets written to System.out AND additionally does something else (e.g. send mail).
    AND
    You do not want to write a new class/method to do so and replace all System.out.println in your source base with this new class/method;
    Then how would you be able to achieve this. Thanks in advance.

    Here is the basic code, you may need to tune performance. I havent compiler or tested it, but it should give you a good idea.
    public class OutputStreamCollection extends OutputStream{
    private OutputStream[] outs = new OutputStream[0];
    public synchronized void addOutputStream(OutputStream argOut) {
    OutputStream[] old = outs;
    outs = new OuputStream[old.length + 1];
    System.arraycopy(old,0,outs,0, old.length);
    outs[outs.length - 1] = argOut;
    public syncrhonized void write(int data) {
    for(int i = 0; i < outs.length; i++) {
    outs.write();
    public synchronized void write(byte[] data, int offset, int length) {
    for(int i = 0; i < outs.length; i++) {
    outs[i].write(data, offset, length);
    nor the following code, will print and log to respective files whatever is going to stdout or stderr
    OutpputStreamCollection out = new OutputStreamCollection();
    out.addOutputStream(System.out);
    out.addOutputStream(new FileOutputStream("stdout.log"));
    System.setOut(out);
    OutpputStreamCollection err = new OutputStreamCollection();
    out.addOutputStream(System.err);
    out.addOutputStream(new FileOutputStream("stderr.log"));
    System.setOut(err);
    you can write adapter classes to process the stream in any way you need, like logging with log4J, or sending mail depending on some crieteria.
    Hope it helps.

  • 32-bit JDK 7 System.out.println not working in IDE

    Hi folks,
    I have a 64-bit Windows 7 OS.
    Due to 3rd party library/jar dependencies, i had to install the 32-bit Java JDK 1.7 and Eclipse IDE.
    I also installed NetBeans.
    So i have a 64-bit OS and am running 32-bit Java JDK/JRE & IDEs.
    The problem I am having is that my program's System.out.println("...") statements are not outputting strings to either IDE debug console.
    Executing the compiled program from a command line/prompt produces the expected string output.
    The basic "Hello, World" program is enough to cause this behaviour to start occurring.
    I have not manually / intentionally changed any IDE-specific Debug Console or Windows environment settings.
    One caveat: This same environment has worked successfully in the past ?! Yes, this is one of those "..it worked last week & yesterday and today it isn't and i swear i didn't do anything..." issue.
    Thoughts ?

    Thanks for the reply.
    The 64-bit versions of Java & Eclipse were installed first.
    When i discovered I had to use the 32-bit versions, i un-installed the 64-bit ones & installed the 32-bits.
    Even after that initial un-install 64-bit/install 32-bit process, it was working.
    I have also been installing the Windows 7 64-bit OS updates when i am informed of them.
    I'm not sure if any of these would affect how the Eclipse / NetBeans IDEs behave.
    Behaviour has been inconsistent.
    Initially it was always working.
    But over the past several days, it has been working less and less.
    I don't have any large data structures.
    This isn't a large complicated program, couple hundred lines, so i highly doubt that i'm doing anything to the resources, but something has changed.
    The main project I am working on takes command line parameters, does some initial processing, produces output using System.out.printlns [SOP] then depending on the parameters, branches into 2 different processing paths, let's call them A & B. Each of these processing paths also use SOPs. When i run the program in the IDE going thru path A, sometimes the initial SOP statements will work and the SOP statements specific to path A will also work. If i immediately change the parameters to go thru path B & re-run it, not even the initial SOP statements before the branching decision work.
    I've tried doing System.flush()s too - no affect.
    I haven't tried the re-direction option to a file option you mentioned yet.
    It always works from a command prompt - that is telling me that the Java SOPs are working properly, correct ?
    Inside an Eclipse or NetBeans IDE, SOP output to the debug console is inconsistent.
    Running from a command prompt, the SOPs always work.
    It'd help to know if this an IDE issue, a Java issue, a Windows 7 issue so i can narrow down where to try and correct the situation.
    I have a Windows XP VM set up, i'll try running the program there and see if there's a difference.
    Thanks for your reply.

  • Synchronized use of System.out.println()

    So I am again at the point of part of my program running ahead of itself out of the call stack and ruining the sequence or order of printing.
    I read that System.out.println() is synchronized so how may it be used to wait() until notified to continue and not ruin the output?

    jverd wrote:
    Always Learning wrote:
    YES SIR EJP! SIR! I thank you for the assistance because using only System.out and synchronizing worked beautifully.You said you're not using multiple threads. If this is true, then there's no reason to synchronize anything. The output will appear on System.out in exactly the order you send it there.
    Nos if only I could figure out dependencies to make it work with out and err.You have to stop and think about it for a minute. You know that when you call println() on either one of those two streams, the output may be buffered an not necessarily go immediately to the console. From that you can reason that if you call out.println() first, and then err.println(), that you could end up with err's buffer getting flushed first, and the output appearing on the console in a different order than that in which your code executed the calls.
    You are of course not surprised by this, given that you know that out and err are completely independent and just happen to end up at the same destination in this particular case.
    So, as a first guess, you might reasonably think that, since buffering is obviously the culprit here, calling flush() on each stream after each print() or println() call should eliminate the problem. In a multithreaded environment, this wouldn't be sufficient, of course, but it's a logical approach to try here.
    Another tidbit to make note of is that the System class has setOut() and setErr() calls. Since you're looking at out and err in the same console, you presumably don't care about the distinction between them (which makes me wonder why you're using them both in the first place, instead of just using one). If you're just going to mush them together into the same console anyway, then you can use setOut() or setErr() to make them the same stream, and things will be ordered as you expect.Very interesting Jverd and I think there may yet be life in what I would like to do. I did not know or was not immediately aware of these things. I will give it a try.
    To answer your question, I am using them both because, like logging, they are distinct in the Eclipse console (black for out and red for err). With your patch I just tried that distinction has faded but the output is sequenced the same so I do appreciate you noting this. Learn something new in Java each time I am doing a project. I considered using logging and putting errors in a window but I am not sure if I should do that; just not enough experience with it.
    Edited by: Always Learning on Oct 23, 2011 9:28 AM

  • System.out.println and EJBs

    Hi,
    I'm trying to develop an application that has 2 main components:
    1) A stateless session EJB, which is called by the container timer service periodically and makes some DB uptades.
    2) A servlet which basically calls the create method in the EJB.
    I've implemented a prototype of the app and the servlet code looks like this:
    try {
    Context context = new InitialContext();
    MyClassLocalHome home = (MyClassLocalHome)PortableRemoteObject.narrow(
                   context.lookup("java:comp/env/ejb/MyClass"),
              MyClassLocalHome.class);
    System.out.println("Narrowed");
    MyClassLocal timer;
    // create a new instance
    timer = home.create();
    System.out.println("Created!");
    In the ejbCreate() in MyClass callback, all I have is a System.out.println("ejbCreate() called") to show the method was called.
    My problem is the even though the servlet code runs without errors and I can see the output in the application server's SystemOut.log, I can't find "ejbCreate() called" message. Am I looking in the wrong place? Am I doing something wrong?
    Thanks in advance.
    Pedro

    Hi Pedro,
    You're not necessarily doing something wrong. Where are you actually invoking a business method on the Stateless Session bean? In the Stateless Session Bean lifecycle, the actual bean instance creation is not required to be linked to the Home.create() call. That's because Stateless Session bean instances have no client-specific state. The container can delay the bean instance creation until an actual business method is called. Only then would the bean instance's ejbCreate method be called.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Multiple Threads Using System.out.println...

    i have a client server app and each client that connects to the server has its own thread.
    i am running the server on a pc using windows xp and to run it i just use a bat file which uses cmd.exe and my output using System.out.println prints out in the cmd.exe.
    each of my threads is using System.out.println to send debug info and outs quite often.
    after the screen fills a scroll bar appears at the right and you can scroll back to see past output.
    my app is all running ok but when i had a ton of output coming in all at once i tried to scroll back to see the older output and realized that if i click down on the scroll bar and fight the new input it freezes my server app. then when i release it it continues lol.
    it made me wonder if output from multiple threads when there are many all at once (say 20 or 30 threads all outputing at the exact same time) could cause a slow down or effect the performance of the server?
    i use a debug variable so i can just turn this output 100 % off except for critical errors so there would be no output but i am just curious as to whether or not it may be causing problems when its on.

    That's not a performance issue, I guess System.out.println() simply gets blocked by the console while you're scrolling and thus your app stalls, until you stop doing that.
    Maybe you should look into logging.

  • System.out.println () is not working properly

    Hi, Why does this happens:
    Object temp=null;
    System.out.println ("temp is null? "+temp==null);
    just prints: true
    expected: temp is null? true
    Why does this happens????
    If I do System.out.println ("temp is null? "+(temp==null)); it works bu it should work without the pharentesis too

    MelGohan wrote:
    Hi, Why does this happens:
    Object temp=null;
    System.out.println ("temp is null? "+temp==null);
    just prints: trueThat is odd, mine prints "false".
    type Test126.java
    public class Test126 {
        public static void main(String[] args) {
            Object temp=null;
            System.out.println ("temp is null? "+temp);
            System.out.println ("temp is null? "+temp==null);
    }javac Test126.java
    java Test126
    temp is null? null
    false

Maybe you are looking for

  • Missing thumbnails showing up as white boxes

    I have completed transferring in my Aperture library, but the majority of the thumbnails are now empty white boxes! Clicking on them reveals the correct photo, but I am still left with a blank white thumbnail. Any suggestions beyond repairing the lib

  • Auxiliary account assignment to asset possible remove entry

    While selling f-92 asst sale iam gettign this error Auxiliary account assignment to asset possible,remove entry. Please guide me on this

  • Blue Screen (atikmpag.sys) on MSI R9 280

    Hello, i have one Video Card MSI R9 280 but with drivers problems resulting in failure to enter Windows by a Blue Screen. All the components are new, i build the P.C. a few days ago so in the first Windows installing all work fine, i installed the vi

  • PCI Express X-Fi Extreme Audio Optical In Not Working From

    I recently purchased this card to use with my Playstation 3 via Optical In. After messing around with the settings on the PS3 I was able to get sound in the Playstation menu (the clicking sound when navigating the menu), but when I try to play a movi

  • Can't sync my new ipad

    How do I transfer ipad apps to a new ipad.  I want to sync my new ipad to my itunes account, but I can't seem to figure out how.