Public static void | SoloLearn: Learn to code for FREE!

0

Public static void

Can someone please explain why public static void always is there?

12/2/2019 9:11:48 AM

Walt Rothschild

7 Answers

New Answer

+2

main method: Every JAVA application contains one main method. The main method contains many keywords, let’s break it down to understand it: public: This makes the main method public so that JVM can call it from anywhere. It should be public. static: JVM doesn’t need to create an object to call the main method. Because the static method is accessible through the class. void: void is the return type of this method, the main method doesn’t return anything. main: Its entry point of JVM to run java application. It is the main method. String[] args: It is a command-line argument we can provide those values from the command prompt. Example: class HelloJavaProgram { public static void main(String args[]) { System.out.println("Hello Java Program"); } } For more details? https://javagoal.com/first-java-program/

+1

Walt Rothschild This the main method. You need it to execute your code. But as HonFu mentioned it is better to take it as a fact. You will learn about it if you get introduced into classes/methods.

+1

public static void main(String[] args) public --> access modifier static --> non-access modifier void --> return type This line is a must to run your java code. If you didn't understand any of these kindly complete the java course and you will come to know.

0

The explanation of this, if the context is still missing (because you're just starting), tends to only lead to more confusion. In my opinion, it's best to just take it as a given and go on with your study of the basics. This will naturally become clear after you studied the tutorial. If not, then at least you'll have the context to understand the explanation.

0

does either one of the characters have to be in the code?

0

Yes, it's necessary in this case.

0

Could you give an example?