Problems with System.out.println()

I tried writing a simple 'Hello world'-program:
public class Test{
     public static void main(String[] args){
          System.out.println("Hello World!");
     }//main()
}//Test
But the text wouldn't appear in the DOS-window. The only text that showed up was the standard 'Press any key to close the window'. The program compiled without any problems, but didn't work when I tried to run it.
Does anyone have any idea what's wrong?

Are u sure , the main() class part is donecorrectly.
Becuse program will compile but not run without a
main() class.what do you mean by main() class???First of all main() is a method, not a class. The main() method the JRE recognizes and runs is the:
public static void main(String[] params)
If you don�t have exaclty those modifiers and receive an array of Strings parameter it will send you an runtime exception.
Your code compiles and runs fine, the problem isn�t really System.out.print() it is something with your configuration.
I have to rename the class to TestF. Here is the running:
C:\cJava>javac TestF.java
C:\cJava>java TestF
Hello World!

Similar Messages

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

  • 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 can I show a System.out.println(""); into a JSP?

    Is a simple doubt that would help me a lot to reach other thing that I wished reach with a JSP.
    Thank you!!!

    Hi!!!
    Thank you to answer me......my question�is because�my problem is a little more complicated��let me tell you�.
    My problem is that I wish to do some queries to a table of a Municipalities DB, I have read about that....and according with the exemples....my JSP...should be running and executing very well....but I haven�t had success with that...:(
    My JSP file is:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    stmt.execute("select * from cat_municipio");
    ResultSet rs = stmt.getResultSet();
    while (rs.next()) {
    System.out.println(rs.getInt("cve_municipio") + " - " + rs.getInt("cve_sepomex") + " - " + rs.getString("desc_municipio"));
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    My result obtained is the following:
    Municipalities List
    Please call Mary with any updates ASAP!
    Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    I don�t obtain nothing.....is like DB table were without information......but in reality the DB table has information.....and I can obtain it with the following JSP:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    // Fetch all records from the database in a TableDataSet
    DataSet dSet = new TableDataSet(conn, "cat_municipio").fetchRecords();
    TableElement tE = new TableElement(dSet);
    tE.setBorder(1);
    out.print(tE);
    } catch (SQLException sqle) {
    out.print("Sorry, the database is not available.");
    out.print("Exception: " + sqle);
    } catch (Exception e) {
    out.print("Exception occured: " + e);
    } finally {
    if(conn != null)
    try {
    conn.close();
    } catch(SQLException sqle) {}
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    and with this JSP I obtain all the following information:
    Municipalities List
    CVE_MUNICIPIO CVE_SEPOMEX DESC_MUNICIPIO
    1 1 ACAJETE
    2 2 ACATENO
    3 3 ACATLAN
    4 4 ACATZINGO
    5 5 ACTEOPAN
    Now...I need that the first JSP work very well, because...with that way...I can do queries and obtain the needed results for showing them in the Browser......
    So, I already find out�.that�any string that I send to the browser with System.out.println(); isn�t showed�.so it is the reason of my question�..how I can see my results of a query using a loop (like a for, while) resolving it....I think my problem would be resolved.
    So...I hope you understand me, and you could help me please...thanks.....
    Mary
    P.D. I also attempted with the following JSP...but the result is the same....I don�t obtain none result...
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select CVE_MUNICIPIO, CVE_SEPOMEX, DESC_MUNICIPIO from cat_municipio");
    while (rs.next()) {
    System.out.println(rs.getInt(1) + " - " + rs.getInt(2) + " - " + rs.getString(3));
    rs.close();
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>

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

  • Override System.out.println()

    Guys,
    I know that "System" is a final class and I can't override it.
    But "PrintStream" is not a final class and it contains "println(Object)"
    method in it. So, I can override it, right?
    My basic requirement is, when I have a program with
    System.out.println("sreedhar");
    say, it should display me something like
    Oct 11, 2007 4:05:05 PM INFO: sreedhar.
    ie. I want to override S.o.p to Logger.info (where Logger is from log4j; or for that matter from commons-logging or JDK logging).
    Can this be done by changing System.java, dropping System.class in tools.jar?

    System has this method. With its help, you can use your own (prepending, timestamping etc.) PrintStream object:
    public static void setOut(PrintStream out)
    //    Reassigns the "standard" output stream.Kaj was faster.
    Edited by: BIJ001 on Oct 12, 2007 8:43 AM

  • Printing on chars on the same line using system.out.println

    i have the following string:
    String msg = "This is a message brought to you by one and the only";
    msg.toCharArray(); //converted to a char array.
    i've written a loop which goes through each of the char elements
    and puts it in it's own array:
    int i = 0;             
    while (i < msg.length)
                    char[] test = {msg};
    System.out.println(test);
    the problem is system out println prints out each of the elements on seperate lines is
    it possible to have them in one line to reform the original string?

    No exactly sure what you are trying to do. Does this
    help?
    String msg = "This is a message brought to you by one
    and the only";
    char[] test = msg.toCharArray();
    System.out.println(test);
    not really because i want to convert the string to a char array and then reform it in another char array and then i can choose which elements i want included and not to be so that it can be printed on the same line. I can do it the following way:
    char[] test = {test[0], test[1]]};
    but say i want all the letters containing the chracter T (and again i can use the above solution and select the elements from the string but i don't want to hardcode it, say the string changes etc) in the test array so then i thought of writing a loop:
    while (test[i] == 'T')
    char[] test2 = {test[i]};
    System.out.println(test);
    i++;
    but it puts each T in a new line...

  • System.out.println() Print to JFrame

    I just wrote a rather large java application and now want to develop a GUI for it. I have never developed GUI and am trying to use the API's for help. Can anyone point me in the right direction: I am trying to take everything that is printed out with System.out.println() and print it inside a JFrame. Any help would be magnificent.
    -Alex

    Add a JTextArea to your frame, create a TextAreaOutputStream with it, and use System.setOut(...) to set System.ouot
    * Created on Mar 13, 2005 by @author Tom Jacobs
    package tjacobs;
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.swing.JTextArea;
    import javax.swing.text.JTextComponent;
    * TextAreaOutputStream creates an outputstream that will output to the
    * given textarea. Useful in setting System.out
    public class TextAreaOutputStream extends OutputStream {
         public static final int DEFAULT_BUFFER_SIZE = 1;
         JTextArea mText;
         byte mBuf[];
         int mLocation;
         public TextAreaOutputStream(JTextArea component) {
              this(component, DEFAULT_BUFFER_SIZE);
         public TextAreaOutputStream(JTextArea component, int bufferSize) {
              mText = component;
              if (bufferSize < 1) bufferSize = 1;
              mBuf = new byte[bufferSize];
              mLocation = 0;
         @Override
         public void write(int arg0) throws IOException {
              //System.err.println("arg = "  + (char) arg0);
              mBuf[mLocation++] = (byte)arg0;
              if (mLocation == mBuf.length) {
                   flush();
         public void flush() {
              mText.append(new String(mBuf, 0, mLocation));
              mLocation = 0;
              try {
                   Thread.sleep(1);
              catch (Exception ex) {}
    }

  • Difference between System.out.println(..)and PrintWriter.println(..)

    Hello every one
    With System.out.println(..) we can print to Console.
    But System.out internally creates PrintWriter object.So why cant we use
    PrintWriter.println(..) directly to write to console.
    Is there aany disadvvantage with PrintWriter.println(..).
    If so can anyone please tell me what is that and
    what is the advantage we r going to get with System.out.println(..) method of writing to console.

    kirn291 wrote:
    With System.out.println(..) we can print to Console.If you want to be very precise, then you have to say that System.out.println() writes to the default output stream. This is usually shown at the console, but can equally well go into a file (if you've redirected it) or nowhere (when running without a console).
    But System.out internally creates PrintWriter object.Not exactly. It refers to a PrintStream object.
    So why cant we use
    PrintWriter.println(..) directly to write to console.Because if you create a PrintWriter it is just another PrintWriter that writes to whatever you specified at the constructor. It is not the same thing as the one PrintStream that is used in System.out.
    what is the advantage we r going to get with System.out.println(..) method of writing to console.The advantage is that it's the only way to do it. Could you post an example of how you'd think of a different way to write to the console?

  • System.out.println and Network Adapter problem

    Hello,
    I am encountering a 2 strange problems. I have 2 oracle application server instances, one dev and one production.
    The first problem is when I type System.out.println in the JSP's i am able to see the output in both \opmn\logs\oc4jinstance. But the System.out.println in the java classes or bean show up only in development logs but not in production box.
    Is there a setting I am missing here?
    The second problem is on our development machine the application works fine, but as soon as we deploy the application on production I encounter:
    could not open new connection: Io exception: The Network Adapter could not establish the connection
    I have a class called DBUtils, which uses a 3rd party library to get connections from the connection pool as below. Using JSP I call the getConnection(). On my dev Oracle Application Server Instance it works fine, but on production I get the error. Can it be there is a setting that I am missing on the production box?
    When I use a JSP and connect to the database without using the DBUtil class. I can connect to the database fine. Also using the DBUtil class with production oracle IP address on the development machine lets me connect with no problem, but production machine does not let me.
    public class DBUtils {
    static ConnectionPoolBean pool;
    static {
    System.out.println("DBUtils() - before connection pool bean");
    pool = new ConnectionPoolBean();
    pool.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    pool.setdbURL("jdbc:oracle:thin:@IPADDRESS:PORT:SID");
    pool.setUser("USERNAME");
    pool.setPassword("PASSWORD");
    pool.setInitialConnections(1);
    pool.setIncrement(1);
    pool.setSoftMaxConnections(40);
    public static Connection getConnection() throws SQLException {
    System.out.println("Getting Oracle Connection");
    return pool.getConnection();
    public static void returnConnection(Connection conn) throws SQLException {
    System.out.println("Returning Connection");
    pool.returnConnection(conn);
    Thanks for your help in advance.

    Hi
    System.out.println is a method of PrintStream in IO which is used to print the output on console in java progs.Here in jsp ,the o/p is printed on server's console window.But out.println is totally different as, out is implicit object derived from JspWriter and is used sly to PrinWriter 's object is used in servlets.It's work is to write upon Browser.
    System.out.println() is normally used in jsp for debugging purposes only.
    Ashish

  • How use system.out.println with a Java Swing Applet?

    Hi guys,
    I was just wondering what can I use to view output on the Java console with a Java Swing Applet?
    At the moment I'm using a JTextArea within the Applet for debugging but I want output to appear in the browser java console but system.out.println doesn't work.
    I'm viewing the Swing Applet on Netscape 4.7 browser.
    Any ideas?

    System.out.println()s work fine! I'm guessing that your problem is that you are looking at the wrong console window!
    You're using the Java Plug-in, right? On Windows, go to your Control Panel and double click "Java Plug-in". You should find a checkbox option to "Show Java Console" - make sure this is checked. Next time you fire up you JApplet, you should see a Java Console window popup.
    Hope this helps!

  • System.out.println() problem

    When I use operator + for concatenate the following Strings
    md.getDriverName() + md.getDriverVersion()
    as follow in a try block:
    try {
    con = DriverManager.getConnection(sourceURL,user,pass);
    md = con.getMetaData();
    System.out.println(md.getDriverName().+md.getDriverVersion());
    when I have tried run java -cp postgresql.jar errors message appers :
    Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: conx
    at java.lang.VMClassLoader.transformException(java.lang.Class, java.lang.Throwable) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)
    Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:postgresql.jar,file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
    at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.6.0.0)
    But when I have used netBeans IDE v 4.0 it works fine.
    Might somebody help me for solve it.

    Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in
    gnu.gcj.runtime.SystemClassLoader{urls=[file:postgresql.jar,file:./],
    As I noted in your other post, your computer is configured to use gnu.gcj, not Sun's Java - and it appears that gcj doesn't have the StringBuilder class; it was added to Sun Java in Java 5.

  • Problem with "System.in.read()" read() method!

    import java.io.*;
    import java.lang.*;
    class Count {
    public static void main(String args[]) throws IOException
    int count = 0;
    while (System.in.read()!=-1)
    count++;
    System.out.println("Input has " + count + " chars.");
    in this code the loop stucks and it increments the count variable infinitely of course as long as i hit enter. I am trying to understand the problem with read() method of system class's in object. in its definition it says; when the inputstream ends it returns -1, but in this code it does not return -1 ever. another question of mine is that what args[] array do? what does it store??

    Java doesn't bother much with the dos console and it a bit limited and limiting - no pretty colours /graphics options - just text - that's because java graduates to GUI's where there is laods of power and object /component support to do everything and everything you could imagine and more. System.in.read() ??? - thats a fine start!
    what args[] array do? what does it store??
    Good question !
    It provides a means of passing a parameter argument from the command line to the program - consider this;-public class HelloWithArgs {
       public static void main(String[] args) {
          System.out.println("Hello I am " + args[0]);
    }What does it do and how does it work? Or this;-public class HelloWithArgs2 {
       public static void main(String[] args) {
          try{
             String myName = args[0];
          catch(ArrayIndexOutOfBoundsException aob){
              System.out.print("No names: program will end");
              System.exit(0);
          System.out.println("Hello I am " + myName);
    }Study them and have fun. Though to answer the question -
    " public static void main(String[] args) {" // or
    " public static void main(String[] parameters) {"
    is the 'entry point' of all java programs, in order to do something it has to have a main() method and if youre going to pass on parameters, then why not a String array? If you think about it anything else would be fairly useless.

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

  • System.out.println in SAP J2EE Engine - Config Tool

    Hi everybody.
    I was having problems with viewing my System.out.println sentences in my NetWeaver's J2EE applications.
    It's supposed that I can't see the files because I have to assing a log archive for System.out controller in SAP J2EE Engine - Config Tool.
    The problem is that I can't find the place to modify the property of that controller!
    I've edited the log-configuration.xml file, but when I restart the server to reload the new configuration, the files I've added to this file, disapear.
    Any idea about this???
    Any answer is well accpeted.
    Thanks,
    Alberto.

    Nobody knows something about this System.out problem??
    Thanks!

Maybe you are looking for