Java4teachus

Thursday, January 03, 2019

System.out.println( ) & System.out.print() in Java

What is System.out.println() & System.out.print() in java. Basically in java these statements are used for print the values in the output . Here we discuss about the 2 statements and about their explanation.

In Java interview point of view this is very useful for fresher learner and beginner who want to know about the meaning of "System.out.println();"

➧ System.out.println( ); ------> 1 statement
➧ System .out.print( );    ------> 2 statement
  1. Statement 1 is used to displaying result of Java program on this console in form of "line/line".
  2. Statement 2 is used for displaying result of Java program in the "same line".

Explanation

  • print( ) & println( ) are the two predefined instance methods present in predefined class called "PrintStream".
  • To access print() & println() methods we need an object of  "PrintStream" class.
  • An object of  PrintStream class called "Out" is created as a static data member in an another predefined class called "System".
  • Hence access print()& println() are two methods then we need to write as follows:
               System.out.println( ) ;
              System.out.print( );


Consider the following old segment which makes understand Technical coding of statements.

Program:-


     class PrintStream
     {
       void print(....)
       {
        ..........
       }
       void println(.....)
       {
        .......
        .......
        }
    class System
      {
       ...........
      Static final PrintStream out = new PrintStream( );
       ...........
      }
   }

Example:- 

Hello Java World

System.out.println( "Hello Java World");

Example:-1 

int a = 10;

System.out.println( a);                                 // 10
System.out.println( "value of a="+a);         // value of a=10
System.out.println(a+"is the value of  a");  // a is the value of 10.

Example:-2 

int a = 10,int b= 20,int c = a+b;

System.out.println( "Sum ="+c);                                 // sum =30
System.out.println(c+' is the sum ");                           // 30 is the sum
System.out.println( " sum of "+a+"&"+ b+ "=" +c);   // sum of 10 and 20 = 30

Example:-3

( Java. 'J' James Gosling )

System.out.println ("Java"+ " ' " + "J" + " ' " + "James Gosling");

No comments:

Post a Comment

Thanks for visiting my site..