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

Introduction of Java

Java is a high level programming language which is used for creating various types of software's or applications. Types of java applications:- 1)     Stand alone application 2)     Desktop based application          3)     Web based application 4)     Enterprise application etc. Stand alone application:- Stand alone application run on single machine without user interface and every stand alone application having main method. Desktop based application:- Desktop based application also run on single machine with user interface and every Desktop based application having main method. Web based application:- Web based application run on web, web based application not required main method but for such types of application need server. Enterprise application:- Enterprise application is category of web application where doing some business or involve some money related issues. Java Editions: - There are four Java platforms. ·       

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 language cl

java print

Syntax of main method in java is    public static void main(String[]args)  before understanding about main method we have to understand that who is responsible for main method.if we write a simple program or write a simple java class without main method like      Test.java           class Test      {      } above program will compile successfully.for compilation of  java file use  javac tool  or  javac.exe  file. javac Test.java it means compiler checks only syntax of class that means compiler does not check the main method in the file or program,so that compiler is not responsible for main method in java. After successfully compilation of above program we have to run the generated byte code. java Test Error: Main method not found in class Test, please define the main method as:    public static void main(String[] args) So JVM (java virtual machine) or java interpreter is responsible for main method,first jvm check that the main method is pres