+ 1
[DUPLICATE] public static void main(String args[]) why we need to write it ? and what does it mean?
5 Answers
+ 1
public: when we write it, we make the whole program and all its datatypes like int etc. and member functions accesible from anywhere
static: static is a keyword and it doesnt have a huge significance but u can look it up on wiki
void: void shows that we are not passing anything like data or something while starting the program.. i.e. initially the program is blank.
main:the most imp. part of any java or c or c++ program is main. main is a method and every program be it of 10 lines or 100000 lines will have to have a main method. The basic info of a program is stored in main method. Sting args represents that we are passing arguments inside the program
+ 1
tqâș
+ 1
I'll answer what is left to answer.
Static : We can access a Class variable by using the name of the Class, and not necessarily using a reference to an individual Object within the Class.Static variables can be accessed even when no Objects of that Class exists. Class variables are declared using the static keyword.
In simple words, you don't need an object to call the main method just a class in which the main method is. Hope I could explain.
And about the arguments of the main method.
We write String[] args to let the computer know that we are writing code in string format or plain English.
0
For simplicity I'll just say every program needs a starting point. Something that has to be run first in order to run the rest. In the case of Java, this is done with the main method. You'll understand the variables as you understand Java more and more
0
is a main method to run the program