Java System.out.println()
Now, here we will learn in detail what is System.out.println() in java programming language. What is the need of it? So let's start...
Before learning in detail, I want to tell you in short that System.out.println() is a statement which is used to mostly print messages on console of cmd.
Sometimes System.out.println() is called in short SOP.
public class SOPExample
{
public static void main(String args[])
{
System.out.println("hello java");
}
}
output : hello java
Syntax :
public final class System extends Object
The System class contains several useful class fields and methods. The System class cannot be instantiated.
There are some facilities provided by System class which is standard output, standard input, and standard error output stream.
(1) static PrintStream err
The "standard" error output stream.
(2) static InputStream in
The "standard" input stream.
(3) static PrintStream our
The "standard" output stream.
Above mention all the stream classes available in java.io package.
1) static String clearProperty(String key)
This method removes the system property indicated by the specified key.
2) static console console()
This console() method returns the unique Console object associated with the current Java Virtual Machine if any.
3) static long currentTimeMillis()
This method returns the current time in milliseconds.
4) static void exit(int status)
This method terminates the currently running Java Virtual Machine.
5) static void gc()
This method runs the garbage collector.
The static variable out is written between the System and println() method. The out object is called with System class.
Syntax of SOP :
System.out.println();
public class SOPExample1
{
public static void main(String args[])
{
System.out.println("Hello Java ");//first massage
System.out.prilntln("Learn Java With Smile");//second massage
}
}
output : Hello Java
Learn Java With Smile
public class SOPExample2
{
public static void main(String args[])
{
int a = 40;
System.out.println(a);
}
}
output : 40
Read More:
Explanation of Java main() Method.
What is Static Keyword in Java?.
What is this keyword in Java?.
Sometimes System.out.println() is called in short SOP.
Java System.out.println() Example
This is the simple example of System.out.println(). In this example we will give "hello java" massage in println() method in double quotes. Take a look in below examplepublic class SOPExample
{
public static void main(String args[])
{
System.out.println("hello java");
}
}
output : hello java
System.out.println()
Let's understand what is "System", "out", "println()" in System.out.println() statement.System
System is a class in java which is available in java.lang.* package. System is a final class in java and System class extends only Object class in java programming language.Syntax :
public final class System extends Object
The System class contains several useful class fields and methods. The System class cannot be instantiated.
There are some facilities provided by System class which is standard output, standard input, and standard error output stream.
Fields of System Class
There are some fields of System class which are given below(1) static PrintStream err
The "standard" error output stream.
(2) static InputStream in
The "standard" input stream.
(3) static PrintStream our
The "standard" output stream.
Above mention all the stream classes available in java.io package.
Methods of System Class
There are many methods of System class in java but some methods are given below1) static String clearProperty(String key)
This method removes the system property indicated by the specified key.
2) static console console()
This console() method returns the unique Console object associated with the current Java Virtual Machine if any.
3) static long currentTimeMillis()
This method returns the current time in milliseconds.
4) static void exit(int status)
This method terminates the currently running Java Virtual Machine.
5) static void gc()
This method runs the garbage collector.
Out
In java out is an object reference of PrintStream class. In other word, we can say out is a type of PrintStream class. But out is defined in System class as public, static and final.The static variable out is written between the System and println() method. The out object is called with System class.
Println()
In java println() is method of PrintStream class. In java language println() method used to print massages or values. In java println() method is overloaded method of PrintStream class which can take different-different arguments such println(int), println(char), etc.Syntax of SOP :
System.out.println();
Java System.out.println() Example- With Printing Massages
This is the simple example of sop where we will print some massages which we will pass as an string with the help of double quotes in println method of PrintStream class.public class SOPExample1
{
public static void main(String args[])
{
System.out.println("Hello Java ");//first massage
System.out.prilntln("Learn Java With Smile");//second massage
}
}
output : Hello Java
Learn Java With Smile
Java System.out.println() Example - With Printing Value
In this example, We will print value.public class SOPExample2
{
public static void main(String args[])
{
int a = 40;
System.out.println(a);
}
}
output : 40
Read More:
Explanation of Java main() Method.
What is Static Keyword in Java?.
What is this keyword in Java?.
this is the great post for java System.out.println
ReplyDelete