Hello guys, welcome to lingarajtechhub.com . Today we are going to discuss about Area of Circle in java.
Code:
package com.Area_Circle.java; public class Area { static int r=5; static double Area_of_circle=3.14*r*r; public static void main(String[] args) { System.out.println("area of circle is:"+Area_of_circle); } }
Line-1:
- package com.Area_Circle.java
It is a java package , this package is created in a java project and it contains classes inside the package.
Line-2:
- public class Area
Here “Area” is the class-name , class is a template used to create objects & class-name first letters must be capital. It is public means we can use this ,outside of this package.
Line-3:
- static int r=5
Static int means Integer value belongs to class.Here int(integer) is a data type. r is the variable name and assigned value 5.
Line-4:
- static double Area_of_circle=3.14*r*r
Static double means double value belongs to class.Here double is a data type. “Area_of_circle” is the variable name and the formula of circle is (PI*r^2).
Line-5:
- public static void main(String[] args)
It is a main method in which we can execute a program.
- public : It is an access modifier. The main() is public because we can access main() outside of the class , if main() can’t be public then JVM(Java Virtual Machine) can’t be called main() & code can’t be executed.
- Static : static is a keyword in which the main method has to be static in which JVM can load the class into memory and call the main method without creating an instance.
- Void : Void is a data type. It means no return type. → main(): Main is a function.
- String [] args : string means collection of characters ,String[] args represents a collection of Strings that are separated by a space and can be typed into the program on the terminal directly.
Line-6:
- System.out.println()
system is a predefined class .Out is a static variable of type printstream present in system class. Println shows the result.