[java] What does 'public static void' mean in Java?

What does public static void mean in Java?

I'm in the process of learning. In all the examples in the book I'm working from public static void comes before any method that is being used or created. What does this mean?

This question is related to java methods

The answer is


The three words have orthogonal meanings.

public means that the method will be visible from classes in other packages.

static means that the method is not attached to a specific instance, and it has no "this". It is more or less a function.

void is the return type. It means "this method returns nothing".


It means that:

  • public - it can be called from anywhere
  • static - it doesn't have any object state, so you can call it without instantiating an object
  • void - it doesn't return anything

You'd think that the lack of a return means it isn't doing much, but it might be saving things in the database, for example.


Public - means that the class (program) is available for use by any other class.

Static - creates a class. Can also be applied to variables and methods,making them class methods/variables instead of just local to a particular instance of the class.

Void - this means that no product is returned when the class completes processing. Compare this with helper classes that provide a return value to the main class,these operate like functions; these do not have void in the declaration.


Considering the typical top-level class. Only public and no modifier access modifiers may be used at the top level so you'll either see public or you won't see any access modifier at all.

`static`` is used because you may not have a need to create an actual object at the top level (but sometimes you will want to so you may not always see/use static. There are other reasons why you wouldn't include static too but this is the typical one at the top level.)

void is used because usually you're not going to be returning a value from the top level (class). (sometimes you'll want to return a value other than NULL so void may not always be used either especially in the case when you have declared, initialized an object at the top level that you are assigning some value to).

Disclaimer: I'm a newbie myself so if this answer is wrong in any way please don't hang me. By day I'm a tech recruiter not a developer; coding is my hobby. Also, I'm always open to constructive criticism and love to learn so please feel free to point out any errors.


  • public means you can access the class from anywhere in the class/object or outside of the package or class
  • static means constant in which block of statement used only 1 time
  • void means no return type

It means three things.

First public means that any other object can access it.

static means that the class in which it resides doesn't have to be instantiated first before the function can be called.

void means that the function does not return a value.

Since you are just learning, don't worry about the first two too much until you learn about classes, and the third won't matter much until you start writing functions (other than main that is).

Best piece of advice I got when learning to program, and which I pass along to you, is don't worry about the little details you don't understand right away. Get a broad overview of the fundamentals, then go back and worry about the details. The reason is that you have to use some things (like public static void) in your first programs which can't really be explained well without teaching you about a bunch of other stuff first. So, for the moment, just accept that that's the way it's done, and move on. You will understand them shortly.


static means that the method is associated with the class, not a specific instance (object) of that class. This means that you can call a static method without creating an object of the class. Because of use of a static keyword main() is your first method to be invoked.. static doesn't need to any object to instance... so,main( ) is called by the Java interpreter before any objects are made.


The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared. (The opposite of public is private, which prevents a member from being used by code defined outside of its class.)

In this case, main( ) must be declared as public, since it must be called by code outside of its class when the program is started.

The keyword static allows main( ) to be called without having to instantiate a particular instance of the class. This is necessary since main( ) is called by the Java interpreter before any objects are made.

The keyword void simply tells the compiler that main( ) does not return a value. As you will see, methods may also return values.