Check out example codes for "java method". It will help you in understanding the concepts better.

Code Example 1

public class Main {
  public static void main(String args[]) {
    int sum = AddNums(5, 6);
  public static void SayHi() { //This method has no return value
  public static int AddNums(int a, int b) { //This method has a return value
    return a + b;

Code Example 2

public class MyClass {
  private int value = 10;
  // getter method
  public int getValue() {
    return value;
  // setter method
  public void setValue(int value) {
    this.value = value;

Code Example 3

public static void main(String[] args)
	int length=getLength();
  	System.out.println("Your length is: "+length);
//methods are outside of main method
public static int getLength()
	int length=5;
  	return length;

Learn ReactJs, React Native from