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

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

Regarding class files

Class files:- Regarding class file or dot class file also known as byte code of class, in a java programming language we can use any number of classes in our program. After compilation all classes convert into individual   .class   file. Example:- class A { } class B { } class C { } class Student { public static void main(String[]args) { System.out.println("Well-come to my java blog"); } } We can save above program to any   classname.java   or we can use any other   name.java,   there is no compulsion for java file name. But recommended to save by that class name which having main method. I saved the above file to   Student.java   name .   Before compilation my   C:\JAVATECH   folder contain only one java file. Student.java For  compilation. C:\JAVATECH>javac  Student.java After compilation   my   C:\JAVATECH   folder contains five files, on...

inheritance

INHERITANCE:- Inheritance is the process of code re-usability, using this property software or applications can develop in less time or can develop rapidly. Inheritance increases the readability of code and decrease redundancy or repetition of code or reduces size of code. Use of previously developed code in future any number of times is called inheritance. Through inheritance variables and methods of class can inherited. Types of Inheritance:- 1)         Single or Single level inheritance 2)         Multilevel inheritance 3)         Hierarchical inheritance Java does not support to multiple inheritance. Single or single level inheritance:- In a single inheritance a class is inherited by a single class. In a single or single level inheritance a sub class having only one super class directly or indirectly. Syntax: -        class Subclass ex...