Showing posts with label System class in java. Show all posts
Showing posts with label System class in java. Show all posts

Tuesday, 4 December 2018

System class in java | System class in java with example - Online Help

System class:

                The System class provides facilitates such as the standard input, output and error streams. It also provides mean to access the properties associated with the Java runtime system and various environment properties such as a version, path, vendor and so on. Fields of this class are in, out, err which represent the standard input, output, and error respectively.
Output statement:
                Java supports three output method to send the result to the screen.
1. print() method
2. println() method
3.  printf() method


      The print(), println(), printf() methods of that object display their string arguments on the standard output.

-          Print():

                    This method displays the string that is supplied as its argument and the output is only one line(Does not terminates the line)

program:
class printdemo
{
Public static void main(String args[])
{
System.out.print(“java ”);
System.out.print(“programming ”);
}
}

The output is:

Javaprogramming


-        Println() method:

                   This method displays the output of the string that is supplied to its argument and then outputs a newline character(terminates the line).

Program:
class println()
{
public static void main(String args[])
{
System.out.println(“java”);
System.out.println(“programming”);
}
}

The output is:
java
programming

-          printf():

           This method outputs the string that is supplied as its argument and then outputs a line. The general format is:
                                 printf(format-string,parameter_list)

        The conversion character that ends a format specifiers indicates the type of the value to be formatted. Each format specifier that starts with a % character is replaced with the corresponding arguments. The version conversion character is as follows:

Conversion character
Type
%d
Decimal integer
%x
Hexadecimal integer
%o
Octal integer
%f
Fixed point floating point
%e
Exponential floating point
%a
Hexadecimal floating point
%s
String
%c
Characters
%b
boolean

Program:
class printfdemo
{
public static void main(String args[])
{
char ch=’A’;
string str=”java”
System.out.printf(“%d\n”,8);
System.out.printf(“%d\n”,-8);
System.out.printf(“%o\n”,10);
System.out.printf(“%x\n”,14);
System.out.printf(“%e\n”,12345678.9);
System.out.printf(“%f\n”,12345678.9);
System.out.printf(“%c\n”,ch);
System.out.printf(“%s\n”,str);
}
}

The output is:
8
-8
12
e
12345678.e+07
12345678.900000
A

java