Categories: Keyword in Java

The return keyword in Java programming language

The return keyword in Java programming language

In this tutorial, we will discuss The return keyword in Java programming language

The return keyword is typically used to end of the code or stop the execution of a method when its execution is completed and return value to the caller.

In Java programming language, the return keyword is used to return certain value to the calling method of the particular type.

return can be used with methods in two ways

Methods returning a value: the method that defined as the return type, method return value(statements) must be immediately followed by the return value

Methods not returning a value: the method that defined not  return type, method no return value(statements) and skips execution

When we declare a method as void it does not return value, otherwise always a method returns value

Declaration

The syntax of return

return value;  //return variable

Example

return myAge;

Example  1

int roomArea (int length, int width){
//this method declare as int
//it can return value 
return length*width

}

Program 1

public class Find_Area{
static int roomArea(int length, int width){
//it return value
return length*width;
}

public static void main(String args[]){
int area=roomArea(12,24);
System.out.println("Class room area is :"+area);

}
}

When the above code is compiled and executed, it will produce the following results

Class room area is :288

 

There are other Java language keywords that are similar to this keyword

public keyword in Java

private keyword in Java

protected keyword in Java

 

Suggested for you

Keywords in Java language

Keywords in C++ language

Keywords in C language

Keywords in Python language

 

The new keyword in Java programming language
The volatile keyword in java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Share
Published by
Karmehavannan

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

3 weeks ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

3 weeks ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

1 month ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

4 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

9 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

9 months ago