Skip to main content

system out println

System.out.println():- System.out.println(“javaindore.blogspot.in”);   , will display message written in double quotes on the standard output device that is system screen or monitor.

Here System is a java class, declared in lang package like java.lang.System, here java is main package and lang is a sub package.

In java System class is declared as a public and final, due to public declaration everybody can happily access these class members but due to final declaration nobody can inherit this class or nobody can override System class methods.
All the methods of System class are public and static so everyone can access all the methods using class name like classname.method.

For example: public static void exit (int) is a method of System class then using
 System. exit (0) anyone can use.

System class not provided public constructor so directly we cannot create object of System class.

System class in java:-

                                    Public final class java.lang.System
                                   {
                                    Variables, methods and static block
                                   }

out:-out is a public static and final variable of type PrintStream class, declared in System class. So we cannot initialize or change the value of out because of final access modifier.

                                       public final class java.lang.System
                                      {
                                      public static final java.io.PrintStream out;
                                       }

out is a static so using System. out we can access out.

println:-println is a method of PrintStream class so using out object of PrintStream class we can access println method.
So for access println method we have to write out.println (), but for accessing out we have to write System.out  , so completely we have to write.

                                                                System.out.println ()

PrintStream class:-

public class java.io.PrintStream extends java.io.FilterOutputStream implements java.lang.Appendable,java.io.Closeable
 {
public void print(boolean);
 public void print(char);
 public void print(int);
 public void print(long);
 public void print(float);
 public void print(double);
 public void print(char[]);
 public void print(java.lang.String);
 public void print(java.lang.Object);
 public void println();
 public void println(boolean);
 public void println(char);
 public void println(int);
 public void println(long);
 public void println(float);
 public void println(double);
 public void println(char[]);
 public void println(java.lang.String);
 public void println(java.lang.Object);
……………………………………………..
……………………………………………..
………………………………………………
}

println method is overloaded into PrintStream class.
PrintStream class also contains print method, it is also overloaded.

println method print message on monitor after printing message throw control to the next line where print method does not throw control to the next line


System class:- public final class java.lang.System

Example1:-TS.java

class TS
{
public static void main(String[]args)
{       
System.out.println(System.out);
System.out.println(System.in);
System.out.println(System.err);
}
}
Output:-
C:\JAVATECH>javac TS.java
C:\JAVATECH>java TS
java.io.PrintStream@52e922
java.io.BufferedInputStream@25154f
java.io.PrintStream@10dea4e

Example2:-TS.java

class TS
{
public static void main(String[]args)
{
System.out=null;
System.out.println(System.out);
}
}
Output:-
C:\JAVATECH>javac TS.java
TS.java:5: error: cannot assign a value to final variable out
System.out=null;
      ^
1 error
Example3:-TS.java

class TS
{
public static void main(String[]args)
{

System.out.println(System.out.println("Well-Come to Javaindore"));
}
}
Output:-
C:\JAVATECH>javac TS.java
TS.java:6: error: 'void' type not allowed here
System.out.println(System.out.println("Well-Come to Javaindore"));
                                     ^
1 error

Example4:-TS.java

class TS
{
public static void main(String[]args)
{
System.out.println("Well-Come to Javaindore");
System.exit(1000);
System.out.println("Well-Come to Javaindore");
}
}
Output:-
C:\JAVATECH>javac TS.java
C:\JAVATECH>java TS
Well-Come to Javaindore

Example5:-TS.java
class TS
{
public static void main(String[]args)
{
System.out.println(System.nanoTime());
System.out.println(System.currentTimeMillis());
}
}
Output:-
C:\JAVATECH>javac TS.java
C:\JAVATECH>java TS
2420403428713
1491200407038

Example6:-TS.java
class TS
{
public static void main(String[]args)
{
System.out.println("Well-come to ");
System.out.println(System.lineSeparator());
System.out.println("javaindore");
}
}
Output:-
C:\JAVATECH>javac TS.java
C:\JAVATECH>java TS
Well-come to


Javaindore

Example7:-TS.java

class TS
{
public static void main(String[]args)
{
System.out.println(System.getProperties());
}
}
Output:-
C:\JAVATECH>javac TS.java

C:\JAVATECH>java TS
{java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=C:\Jav
a\jre8\bin, java.vm.version=25.0-b70, java.vm.vendor=Oracle Corporation, java.ve
ndor.url=http://java.oracle.com/, path.separator=;, java.vm.name=Java HotSpot(TM
) Client VM, file.encoding.pkg=sun.io, user.country=US, user.script=, sun.java.l
auncher=SUN_STANDARD, sun.os.patch.level=, java.vm.specification.name=Java Virtu
al Machine Specification, user.dir=C:\JAVATECH, java.runtime.version=1.8.0-b132,
 java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Ja
va\jre8\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\Users\user\AppData\Local\Te
mp\, line.separator=
, java.vm.specification.vendor=Oracle Corporation, user.variant=, os.name=Window
s 7, sun.jnu.encoding=Cp1252, java.library.path=C:\Windows\system32;C:\Windows\S
un\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Win
dows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\
Intel\OpenCL SDK\2.0\bin\x86;E:\Java\jdk1.8.0\bin;C:\Java\jdk1.8.0\bin;;., java.
specification.name=Java Platform API Specification, java.class.version=52.0, sun
.management.compiler=HotSpot Client Compiler, os.version=6.1, user.home=C:\Users
\user, user.timezone=Asia/Calcutta, java.awt.printerjob=sun.awt.windows.WPrinter
Job, file.encoding=Cp1252, java.specification.version=1.8, java.class.path=c:\mj
ava\mysql-connector-java-5.0.7-bin;.;, user.name=user, java.vm.specification.ver
sion=1.8, sun.java.command=TS, java.home=C:\Java\jre8, sun.arch.data.model=32, u
ser.language=en, java.specification.vendor=Oracle Corporation, awt.toolkit=sun.a
wt.windows.WToolkit, java.vm.info=mixed mode, java.version=1.8.0, java.ext.dirs=
C:\Java\jre8\lib\ext;C:\Windows\Sun\Java\lib\ext, sun.boot.class.path=C:\Java\jr
e8\lib\resources.jar;C:\Java\jre8\lib\rt.jar;C:\Java\jre8\lib\sunrsasign.jar;C:\
Java\jre8\lib\jsse.jar;C:\Java\jre8\lib\jce.jar;C:\Java\jre8\lib\charsets.jar;C:
\Java\jre8\lib\jfr.jar;C:\Java\jre8\classes, java.vendor=Oracle Corporation, sun
.stderr.encoding=cp437, file.separator=\, java.vendor.url.bug=http://bugreport.s
un.com/bugreport/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little,
 sun.stdout.encoding=cp437, sun.desktop=windows, sun.cpu.isalist=pentium_pro+mmx
 pentium_pro pentium+mmx pentium i486 i386 i86}



Comments

Popular posts from this blog

Inner classes

Inner Classes:- class inside class or interface called inner class or nested class. Advantage of inner classes is grouping multiple classes and interfaces into a single class. Another big advantage of inner class is that inner class can happily access all the data or variables of outer class directly. Types of Nested classes:- There are two types of nested classes static and non-static nested classes. (A)Non –static inner classes:- 1)     Member inner class 2)     Anonymous inner class 3)     Local inner class (B)Static nested class Example1:-Outer.java class Outer { class Inner { void disp() { System.out.println("Hello This is Inner class Method"); } } public static void main(String[]args) { Inner in=new Inner(); in.disp(); } } Output:- C:\JAVATECH>javac Outer.java Outer.java:12: error: non-static variable this cannot be referenced from a static context Inner in=new Inner(); ...

Inheritance-4

Example10:- class Student { Student() { System.out.println("This is super class Zero argument constructor"); } Student(String s) { System.out.println("This is super class One argument constructor"); } } class Test extends Student { Test() { super(null); System.out.println("This is sub class Zero argument constructor"); } public static void main(String[]args) { Test t=new Test(); } } Output:- C:\JAVATECH>javac Test.java C:\JAVATECH>java Test This is super class One argument constructor This is sub class Zero argument constructor Example11:- class Student { Student() { System.out.println("This is super class Zero argument constructor"); } Student(String s) { System.out.println("This is super class One argument constructor"); } } class Test extends Student { Test() { super(); super(null); System.out.println("This is su...

Small concept about OOPs

Some small concept about OOPs:- In many books and website write about OOPs concepts as hundred percent object oriented, pure object oriented and partial object oriented language. Hundred percent object oriented:- In the hundred percent object oriented movie hero is object, without object program is incomplete that means can not execute program without object. Without class and object programming or application development is not possible. Example of hundred percent object oriented language is  Smalltalk . Pure object oriented:- In the object oriented cinema obviously object is the hero. In pure object oriented language object having same importance but in this having some relax that is without creating object we can successfully execute our application. So in the object oriented programming without class we cannot create or run our application, class is must. Example of pure object oriented language is  Java . Partial object oriented:- In this type of la...