Definition:
Example
Addition,Subtraction and multiplication in JAVA
import java.lang.*;
public class mathematics
{
public static void main(String args[])
{
int a,b,c;
a=10;
b=5;
System.out.println("Add:"+(a + b));
System.out.println("Sub:"+(a - b));
System.out.println("Multiply:"+(a * b));
}
}
o/p
15
5
50
Java is a computer programming language. It enables programmers to write computer instructions using English based commands, instead of having to write in numeric codes. It’s known as a “high-level” language because it can be read and written easily by humans. Like English, Java has a set of rules that determine how the instructions are written. These rules are known as its “syntax”. Once a program has been written, the high-level instructions are translated into numeric codes that computers can understand and execute.
Example
Addition,Subtraction and multiplication in JAVA
import java.lang.*;
public class mathematics
{
public static void main(String args[])
{
int a,b,c;
a=10;
b=5;
System.out.println("Add:"+(a + b));
System.out.println("Sub:"+(a - b));
System.out.println("Multiply:"+(a * b));
}
}
o/p
15
5
50
Why public static void main(String args[]) is used.
The Main method is the method in which execution to any
java program begins. A main method declaration looks as follows: public static void main(String args[])
{
} The method is public because it be accessible to the JVM to begin execution of the program. It is Static because it be available for execution without an object instance. you may know that you need an object instance to invoke any method. So you cannot begin execution of a class without its object if the main method was not static. It returns only a void because, once the main method execution s over, the program terminates. So there can be no data that can be returned by the Main method The last parameter is String args[]. This is used to signify that the user may opt to enter parameters to the java program at command line. We can use both String[] args or String args[]. The Java compiler would accept both forms. |
No comments:
Post a Comment