Keyword in Java

The void keyword in Java programming language

The void keyword in Java programming language

In this tutorial, we will discuss The void keyword in java programming language

The void keyword is a Java keyword. This keyword allows us to create methods which do not return a value. Which means void is a special type of keyword in Java as a void keyword does not return value unlike int, double, float etc at method declaration.

Declaration

Syntax of the void keyword

return _type method_name(){
    //statement(s)
}

Example

Example of a void method

void add(){
   //statement(s)
}

Above method is a void method as it  does not return any value to the main method.

Example void method within the class
public class Example _void{  // this is a class in java
public static void main(String args[]){
}
public void add(){  // this is a void method. It does not produce return value;
}
}

Program 1

public class voidEx{
    public static void main (String args[]){
        my_age(50);
    }
     static void my_age(int age){
        System.out.println("My age is :"+age);
//No return
}
}

 

When the above code is executed, it produces the following results

The age is :50

In the above example, The method my_age is a void method passed as a parameter age(int) which does not return any value

 

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

 byte  in Java Language

 int  in Java Language

long  in Java Language

 float  in Java Language

char  in Java Language

 void  in Java Language

try  in Java Language

Catch in Java Language

implements  in java Language

public  in Java Language

static  in Java language

Volatile  in Java Language

Package  in Java Language

class  in Java Language

boolean  in Java Language

break in Java Language

do  in Java Language

double  in Java Language

This  in Java Language

final  in Java Language

switch  in Java Language

interface  in Java Language

extends  in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Finally  in Java language

 

 

 

 

The protected keyword in Java programming language
The int 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.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago