Functionality of System.out.println()

Hello,
can some one please explain me what happens
an System.out.println(); is called
for example when we are pass an Object reference of some class
it prints the address
what functionality is taking place internally.
which methods are called.

You can look for yourself. The source code for the classes in the core API is in src.zip in the JDK download.

Similar Messages

  • System.out.println capture to buffer

    Hi All,
    My application runs other application in back. How can I capture system.out.println() written by another application & display via dialog box.
    Like :execl() or execv() function in C runtime library. Where every printf() message printed to passed buffer.
    Thank you,
    Avin Patel

    If i understand your question correctly, you should execute command for you help.html file. The system will run default browser.
    such as:
    void runBrowser(String file)
    {String cmd = null;   
         Process p;   
              try  {       
                   String os = System.getProperty("os.name");            
                   if (os != null && os.startsWith("Windows")) {           
                        if (os.startsWith("Windows 9") || os.startsWith("Windows Me")) 
                        // Windows 9x/Me               
                             cmd = "start " + file;
    else
                        // Windows NT/2000/XP               
                             cmd = "cmd /c start " + file;
    p = Runtime.getRuntime().exec(cmd);            
    catch(IOException x)
    // couldn't exec browser
    System.err.println("Could not invoke browser, command=" + cmd);
    }

  • Linux System.out.println()

    I am porting some JSP's from Windows to SUSE Linux. These JSP's call functions that are embedded in JAVA classes, which in turn output error messages with System.out.println() to the console. It appears that in Linux, the bash Konsole doesn't print these errors, so they are invisible.
    I suppose that if I wrote JSP's in the future, errors could be printed in the browser, but I would really like to be able to see my errors in bash or which ever shell. Any help would be appreciated.

    If you ever intend to use more than one webserver, I would suggest you look towards something like JMS. Messages can be sent to the queue from which you can pick them up and deal with them as necessary in your own time, be that real-time or delayed.
    If you think you will never need more than one, why not write a little log file reader? Remember though that the catalina.out file will grow and grow unless you stop Tomcat, rename the old file and restart Tomcat.

  • Strange behavior with System.out.println

    I was working with the following code:
    1. public class DemoChar {
    2. public static void main(String args[]) {
    3.
    4. char buf[] = new char[50];
    5. buf[0] = 'a';
    6. buf[1] = 'b';
    7. buf[2] = 'c';
    8. buf[3] = 'd';
    9. buf[4] = 'e';
    10. System.out.println( buf);
    11. }
    12. }
    if you print "buf", it really works; however if you change line 10 by :
    System.out.println("--->" + buf );
    The method "println()" doesn't write "--->abcde". The functionality doesn't the same. It will appear "----> [C@3e25a5"
    Could you help me?
    I don't understand that behavior. I am using "java version 1.6.0_07"

    buf's an array and thus is an object. object's don't inherently know how to represent themselves as Strings, so you have to do other things to make sure that they print out ok. To get a char array to print well, you could use the String method valueOf(...):
    public class DemoChar
      public static void main(String args[])
        char buf[] = {'a', 'b', 'c', 'd', 'e'};
        System.out.println(buf);  // this seems to call implicitly String.valueOf(buf)
        System.out.println("--->" + buf);  // this however seems to call buf.toString() with different results
        System.out.println("--->" + String.valueOf(buf));
    }Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you can will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:
    [code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    [/code]or
    {code}
      // your code block goes here.
      // note here that the tags are the same.
    {code}Edited by: Encephalopathic on Aug 21, 2008 9:40 AM

  • How do you change system.out.println colour?

    Hi, I am developing some basic rmi client/server applications, I have an 2D array on a central server being read/written by remote clients. all the development is using system.out. statements at the moment (hopefully being replaced by GUI later) my question is when a client remote calls a read operation, and reads an array location, eg x3, y4 I want to print the location contents in a different colour to indicate the read, at the moment the displayArray() simply has nested for loops to cycle through the array and System.out.println statements to get it to the screen. I wonder is there a simple way to change the colour of system.out type statements? thanks for any help

    I could be wrong, but I don't think that is possible. The System.out and other streams are just streams of characters, and doesn't contain any data about the characters. You could possibly get it to work if you knew which terminal the stream was going to and if the terminal had escape commands that could set colors. BBS browsers have that functionality, but I think that would be a hard path to follow.
    If you are printing out a lot of data and need some color to aid it's readability, try printing directly to your graphic context:
    Graphics g = getGraphics();
    g.setColor(Color.white);
    g.drawString("Hello",100,100);

  • Why System.out.println not PrintStream.println ?

    Hi, just a beginner question
    I just wonder why should we use System.out.println, not PrintStream.println ?
    the field out in the System class is the instance of PrintStream class, isn't it?
    So why don't we just use the PrintStream class directly?
    Thanks..
    Edited by: riff_almighty on Oct 27, 2007 3:27 AM

    According to the api:
    A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently. Two other features are provided as well. Unlike other output streams, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the checkError method. Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written.
    So there is nowhere mentioned about the PrintStream associated with the user console. System.out is the one instance of PrintStream which is associated with the console...
    Also println() is not a static method and cant be called upon the class...
    Edited by: VijayBabu on Oct 27, 2007 12:51 AM

  • Can't run java apps with System.out.println on any builder.

    Hello,
    I'm currently using Vista RC2, which is the immediate problem.
    Classes with System.out.println won't launch the console window. As I'm a student and practicing on these steps, I do have quite a problem on my hands. I click on run, build succesfull, nothing happens.
    I have tried Netbeans and Jcreator, and gave up on trying different builds, as I reckon I'll have to find some other way to counter this; any way to get println messages working in vista?

    It is run as a desktop app, and other runs with commands such as JOptionPane do function, only the println windows don't appear at all. So I think JRE is installed and working.
    I did notice there was one command for input where I'd be able to enter it at the bottom of Netbeans.
    Like just now I clicked build and run for the following code
    import java.util.*;
    public class FirstProgram
        public static void main(String[] args)
            System.out.println("Hello out there.");
            System.out.println("I will add two numbers for you.");
            System.out.println("Enter two whole numbers on a line:");
            int n1, n2;
            Scanner keyboard = new Scanner(System.in);
            n1=keyboard.nextInt();
            n2=keyboard.nextInt();
            System.out.println("The sum of those two numbers is");
            System.out.println(n1+n2)
    }Resulting in a brief flash of "input" in the output window (which is below the coding window) and it dissapears. But this also occurs when I don't include system scanner code.
    Using commands in cmd
    java -jar "C:\Users\Alegis\Netb\MyApp\dist\MyApp.jar"
    Does not yield desired results either. Nothing happens.

  • Intercepting System.exit() and System.out.println() calls

    hi there,
    I have often problems when working with code that uses System.exit() and System.out.println() extensively, because it becomes difficult to debug.
    Basically I do have wrappers for System.exit() (my own static exit function) and for System.out.println() (log4j).
    Still not all programmers are using these methods; Probably the only way to enforce this is some kind of code warrior, but I was hoping to be able to intercept the two System.XXX calls (and throw an appropriate Exception). is this possible ??

    Why not simply make your own security manager andhandle checkExit() and checkWrite?
    Does anyone have a simple example of this? Please?System.exit() can be intercepted using a security manager, but not System.out.xxx.
    Here is a short example:
    //set your security manager
    static{
         SecurityManager s = new OwnSecurityManager();
         System.setSecurityManager(s);
    //redirect the out stream
    try{
         PrintStream ps = new PrintStream(new FileOutputStream("output.txt"));
         System.setOut(ps);
    }catch(IOException ioe){
         ioe.printStackTrace();
    //some tests
    System.out.println("Test");
    System.exit(2);
    //your security manager
    class OwnSecurityManager extends SecurityManager{
         public void checkExit(int code){
           if(code > 0){
             super.checkExit(code);
             throw new SecurityException("Not allowed here->" + code);
         public void checkRead(FileDescriptor fd){
         public void checkRead(String file){
         public void checkRead(String file, Object context){
         public void checkPermission(Permission perm){
           if(perm.getName().equals("exitVM")){
             System.out.println("exitVM");
    }

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

  • Is there a way to make system.out.println() scroll down as it goes?

    I am writing a program where I want to be able to read what's printed out in the console of my IDE through System.out.println() as the program runs/after the program runs. However, right now I run the program, the message prints out, and then when I go to read it the scroll bar is all the way up so I can see only the top of the print-out (the first thing printed out). Is there any way I can get the console to scroll along with the text, kind of like floating boxes you see on various websites for various reasons? In other words, can I get it so that when I look in the console at any given moment of the program running, I am looking at the newest text printed out (the text at the bottom of the "page")? Thank you!

    That would be an IDE problem and not a Java one. You could redirect output into a text file so you can read at your leisure and scroll up and down as much as you like.

  • Is there a way to force System.out.println to run when called

    I working on my first threaded program and having a hard time debugging. I've used System.out.println to let me know what's going on but due (I assume) to the nature of threads the output is not sequential. Is there a way to force println to execute immediatly so that they show up in the order they were called?
    Thanks --- Mike

    mjs1138 wrote:
    endasil, Thanks for the reply. I'm currenlty running the program from within the NetBeans IDE. It is the output displayed by in NetBeans "output" that I'm looking at.
    --- MikeI don't use Netbeans, but I would guess that it too pipes Standard Out and Standard Error to the same console. You didn't address my comment. Are you printing to System.err as well? This happens implicitly if you use Exception.printStackTrace(), for example.

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

  • How can i put a system.out.println into txt file

    i want to generate a txt file instead of system.out.println. for the output How can i do that and what code can i use for that??
    Edited by: crystalarun on Oct 14, 2007 11:40 AM

    suppose u ant output in "Output.txt"
    then code can be
    PrintStream out = new PrintStream(new FileOutputStream("Output.txt"));
    System.setOut(out)

  • 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

  • System.out.println in Web Dynpro Java

    I call System.out.println in some components in web dynpro java.  But I cannot find the standard console output file of SAP J2EE Engine. Anyone know where is the location of standard output file?

    Thanks Deepak. Your link blog is working.
    Sreeni: I cannot find a start-up log file. Could you please tell me the real path?
    Edited by: Nuttakorn Boonthamtanarung on Apr 1, 2010 6:58 AM

Maybe you are looking for