Output Statement in java:-
In java, we use [Link]() is the output statement to display a message, string or data on
the screen. It displays the argument that we pass to it.
Let’s understand each part of this statement:
1. System: It is a final class defined in the [Link] package.
2. out: It is an instance of PrintStream type and its access specifiers are public and final
3. println(): It is a method of PrintStream class.
As we know that we need to create the object of a class to invoke its method. Here instead of creating the
object of the PrintStream class we use [Link], it internally creates the object of PrintStream class so
we can use the statement [Link]() to invoke println() method.
/*First Program in java language.
Save the file with name [Link]*/
class First
{
public static void main(String args[])
{
[Link]("HELLO WELCOME TO JAVA WORLD");
}
}
NOTE:- To Compile the above program we must set path and class path.
To set the path follow the command
D:\second Bsc\set path=C:\Program Files\Java\jdk1.8.0_162\bin;
To set the class path follow the command
D:\Second Bsc\set classpath=C:\Program Files\Java\jdk1.8.0_162\jre\lib\[Link];
Compilation:-javac [Link] (press enter)
If there are no compilation errors in your program then java compiler creates one file i.e
[Link] file(byte code) otherwise compiler displays compilation errors.
Execution:- java First
Explanation of above program
//Addition of Two numbers.([Link])
class Add
{
public static void main(String args[])
{
int x,y,z;
x=11;
y=22;
z=x+y;//Assignment Expression.-single value produced
[Link](x);
[Link](y);
[Link](z);
}
}
Compilation:- D:\Second [Link]\javac [Link]
Execution:- D:\Second [Link]\java Add
-------------------------------------------------------------
//Basic Program in java
class Sample
{
public static void main(String args[])
{
[Link]("JAVA IS OBJECT ORIENTED");
[Link]("JAVA IS PLATFORM INDEPENDENT & PORTABLE");
[Link]("JAVA IS SECURE");
[Link]("JAVA IS ROBUST");
[Link]("JAVA IS DISTRIBUTED");
[Link]("JAVA IS MULTITHREADING");
[Link]("JAVA IS DYNAMIC");
}
}//OUTPUT STATMENT IN JAVA [Link]();
OUTPUT:-
//3)Arthimetical operations
class Arth
{
public static void main(String[] args)
{
int x=60;
int y=30;
[Link]("Additon:"+(x+y));
//++ is a concatenation operator.
//printf("Addition:%d",(x+y));
[Link]("Subtraction:"+(x-y));
[Link]("Multiply:"+(x*y));
[Link]("DIVISION"+(x/y));
}
}
OUTPUT: