In Java (a programming language) a main method is a location where a Java starts. By start I mean that everything that occurs during the program is in some way started due to the content (code) of your main method. I will refer to the main as a method but it is also called "main function." functions are equivalent to methods when talking about computer science.
The main method looks complicated, but really shouldn't be:
class YourClass{
public static void main(string[] args){
/*where the start of your code belongs*/
}
}
If you exclude a main method from your Java program, it will not run what-so-ever. This is because your computer is looking for a start location, which by means of the Java programming environment was assigned to be the static method main.
Broken Apart For Better Understanding
Basic Dissection of the main method code
1. public = open to everyone
2. static = non moving (I'll explain)
3. void = nothing
4. main = base
5. String[] = A series of values
6. args = arguments
Taking this dissection an inch deeper
1. public = accessible to any programmer
2. static = content (code) inside will be instantaneous and still.
3. void = return nothing
4. main = the name of the base level method
5. String = Any text like "hello" or "I should favorite this site" or "haha 2+2 doesn't equal 4"
6. String[] = A series of text elements (really called Strings) such as "wow","thats it?" or "hey","merry","christmas"
7. args = A name that points at the data, String[]
Finally: Packed into A Box
public static void main(String[] args){ /*content or code*/ }
=
An open-to-all non-movable basic method that returns nothing and is passed (it receives) a series of Text that is where every Java program start.
For more information about the main method in java programs:
No comments:
Post a Comment