Table of content

What does void mean in Java?

In Java, the keyword void is used with the method declaration to specify that the method does not return any value after completing the execution. The return type of void method is not assigned to any variable because void is not a data type.

The void method is mostly used when the user wants to change the internal state of the object but does not require the updated state.

In Java, the main() method does not return anything because the main() method's return type is void. When the main() method terminates, the java program also terminates.

public class Example {
  static int getData(int x) {
    return 5 + x; // return integer value since the return type of the method is int
  static void printData() {
    System.out.println("I am a void method");
  public static void main(String[] args) {
    // calling method with return type
    System.out.println("I am a integer method: " + getData(3)); 
    printData(); // calling method with no return type

The output is

I am a integer method: 8
I am a void method
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions