System.out.println()
Not only the novices but also a few Programmers do not aware of the meaning of System.out.prinltn() statement. Following is the description of each word in the statement.
What is System.out.println()?
- out is an object PrintStream class defined in System class. out is declared as public, static and final.
- println() is a method of PrintStream class.
- The println() method is called with out object.
- The out object is called with System class.
To say simple, println() is a method of PrintStream class. out is an object of PrintStream class defined in System class.
So, we are calling println() with out object and out object with System class.
About "out"
We know out is an object of PrintStream class defined in System class. Internally the out object is connected to the "standard output stream" of underlying operating system. So, any data given to out object goes to the OS out stream and prints at the DOS prompt.
About "error"
We know earlier, the object out of PrintSteam is connected to the standard output stream of the underlying operating system. Similarly, there exist another object err of the same PrintStream that is connected to the standard error stream of the underlying operating system. The data given to err also goes to the DOS prompt.
The following two statements do the same job of writing to the destination DOS prompt.
System.out.println("Hello"); // observe, out
System.err.println("Hello"); // observe, err
The first one is preferred to display any messages at DOS prompt, useful to the client, by the programmer. The second one is best suitable to display error messages at DOS prompt as in a catch block etc.
A similar program exists on PrintWriter that prints data at DOS prompt.
Dear Sir
Your Explanations is very helpfull to us thanking you..
Generally we call a method with object. Same is done as we write – out.println() . But why we mention the class name System?
If not called, where out is defined. Where JVM checks the meaning or availability of out? out is defined System class.
Sir,
println() method is defined in the printstream class.To call println() method we create an object called out.here we are defining out object in printstream class itself but you said out object defined in the System class.I’m confused with PrintStream and System class.could you please explain in detail?
PrintStream object “out” is defined in System class. Refer System api.
Sir,Actually what does System.out.println(); prints?
hii sir..
why we use 3 dots after String like in public static void main(String… a)?
what does it mean??
Stands for variable arguments, a feature introduced with JDK 1.5. See this link.
http://way2java.com/java-versions-2/jdk-1-5-java-se-5-version/
its a good platform for everyone even better than books
hi!,I love your writing so so much! share we keep up a correspondence extra approximately your article on AOL?
I need a specialist on this house to solve my problem. Maybe that’s
you! Taking a look forward to look you.
Sorry, I may be a wrong person to you.
i’m confused in stringargs[]……tell me more about it why we mention it in java program?
It is to read the command-line arguments. See this link:
http://way2java.com/arrays/command-line-arguments/
What is the meaning of ArrayListcities=new ArrayList();
You are creating an object of ArrayList class by name cities.
best site to learn core java.
sir can u send me the link of call by value and call by reference, bcz i didn’t find till now
http://way2java.com/arrays/java-passing-arrays-to-constructor/
http://way2java.com/arrays/passing-arrays-to-methods/
sir, your site is very helpful for clearing doubts …
could you tell me that what are the factors or causes that makes c/c++ platform dependent ….i have little knowledge of microprocessor and assembly language and i guess that answer will be somewhere related with these two things ……..
To understand this, you need not know about MP design. C/C++ compiler generates executable binary code whose order of 0 and 1s is different for different platforms. For this reason, the pattern of binary code generated one OS will not work on other. That is binary code is platform dependent.
To understand the internals of Java, the knowledge of microprocessor design is not essential. The .exe file of C/C++ generate binary code which is OS dependent. For this reason, on which OS the .exe file is generated, on the same OS it must be executed.
hellow sir i like your website …because the best stuff is given by you about system.out.println()…
thanking you sir…
Thanks, tell your friends also to derive the advantage of the site.
Sir can u plz give me the code for System.out.println() with their classes?
See my site.
sir your site is very useful, with the help of the contents on it i clear my several doubts, sir please provide some contents on advance java & various frameworks also.
thanks sir
sir if i do this
class b
{
public static void main(String… a)
{
PrintStream c=new PrintStream();
c.println(“dfsaf”);
}
}
why this showing error i hav just made object of PrintStream class and tried to access thier method
Correct your code as follows:
import java.io.*;
class b
{
public static void main(String… a)
{
PrintStream c=new PrintStream(System.out);
c.println(“dfsaf”);
}
}
Sir why u have mentioned System.out in the constructor of PrintStream class what is this meaning??
All streams are carriers of data. PrintStream carries to the destination. Which destination, where it is to be mentioned? It is mentioned in the constructor of PrintStream. System.out is connected to the OS stream that carries to the dos prompt.
hlo sir Pls explain
What is difference between String and string in java ? where it’s using this String and string ….
String is class and string means referring a String value but permitted to write notes.
sir if i do this
class b
{
public static void main(String… a)
{
PrintStream c=new PrintStream();
c.println(“dfsaf”);
}
}
why this showing error i hav just made object of PrintStream class and tried to access thier method
Sir could you provide the mystery behaind System.out.println()
It is already given in the web site.
hi sir..,why “+” operator is present is System.out.printl(“sum” + sum);
It is for concatenation.
hi sir,
System class is defined in which package?
java.lang package
java.lang.object
On the same page of html you sent with sendRedirect() method, extra data cannot be displayed. For this, you may use Struts or other frameworks.
Hello Sir…
I didn’t get the actual meaning of System.out.println()….
Please help me…
With Regards..
System.out is internally connected to the output mechanism of the underlying operating system. To println() parameter, we pass data that is to be printed at the command prompt. Remaining things are explained in the site.
hi sir,
can I write a main() method inside an abstract class?
See this link in way2java.com
http://way2java.com/oops-concepts/abstract-class-with-main/
thank you sir,
System class is defined in which package?
Hi sir,
could you please provide some material on Advanced java like core java. And your site is very useful to java learners.
It takes some time.