The following code shows A Java Program to Compute and Display Area of a Circle.

Since, we have a public class with the name Main, we need to save the file with name Main.java. In order to compute area of circle, here we create a static function computeArea() that accepts radius as input and returns the area. For the purpose of taking input from the user, the class Scanner is used. It is available in java.util package. Also, the nextDouble() function returns the double value read from the user.

// Using a Java Function to find area of a triangle
import java.util.*;
public class Main{
    public static void main(String[] args) {
        double radius, circleArea;
        System.out.println("Enter the value of radius: ");
        Scanner mydata=new Scanner(System.in);
        radius=mydata.nextDouble();
        circleArea=computeArea(radius);
        System.out.println("Area of Circle with Radius "+radius+" is "+circleArea);
    }
    public static double computeArea(double circle_radius)
    {
        return 3.14*circle_radius*circle_radius;
    }
}

Output

Computing Area of Circle Using a Function in Java
Computing Area of Circle Using a Function in Java

Further Reading

Understanding Enterprise Java Beans

Java Practice Exercise