Home>Article>Java> What does void mean in java

What does void mean in java

青灯夜游
青灯夜游 Original
2023-03-01 19:19:35 6234browse

In Java, void means "empty", that is, "returns nothing". When the method is declared, it means that the method has no return value. Void corresponds to a wrapper class "java.lang.Void". The Void class is modified with final and is a non-instantiable placeholder class used to save a reference to a Class object that represents the Java keyword void.

What does void mean in java

The operating environment of this tutorial: windows7 system, java8 version, DELL G3 computer.

1. Overview

void is a keyword in Java. In java learning, void is included in the definition of Java main method. Figure, as follows:

public static void main(String[] args) { .....; }
  • Anyone who has studied Java knows that void means empty. If you ask an expert, the expert will tell you: "void is nothing, you just need to Remember that void is empty. When the method is declared, it means that the method has no return value".
  • Compared with the C language, there are four data types in C, includingempty type, which says "There is a type of function that is not needed after calling it. Returns a function value to the caller. This function can be defined as an "empty type".

Java language is a strongly typed language, and strong type includes two meanings:

  • 1. All variables must be declared first and then used
  • 2. Variables of a specified type can only accept values whose type matches the type.

From the syntax of the method declaration, we can see that the definition of the method must have a return value, and the type of the method return value needs to be determined; when the method is defined with void, it means there is no return value, so it can be seen that void should be regarded as a data type .And there are onlytwo data typesin Java, namelybasic data typesandreference data types.

Basic data types (8 types) : byte, short, int, long,; char; float, double; boolean.

Reference types: classes, interfaces, array types, and a special null class.

2. So what is the type of void in java?

In fact, void also has corresponding packaging classesjava.lang.Void, but we cannot directly operate them . It inherits from Object, as follows:

public final class Void extends Object { /* * The Void class cannot be instantiated. */ private Void() {} }

Searching for online information, there is probably this explanation:

  • Void - Class in java.lang
  • Void class It is a non-instantiableplaceholderclass, used to save a reference to a Class object that represents the Java keyword void.

For more programming-related knowledge, please visit:Programming Teaching!!

The above is the detailed content of What does void mean in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn