[go: up one dir, main page]

0% found this document useful (0 votes)
14 views2 pages

5.5 Java Main

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

5.5 Java Main

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

java main() method

The main() is the starting point for JVM to start execution of a Java program. Without
the main() method, JVM will not execute the program. The syntax of the main() method
is:

public: It is an access specifier. We should use a public keyword before the main()
method so that JVM can identify the execution point of the program. If we use private,
protected, and default before the main() method, it will not be visible to JVM.

static: You can make a method static by using the keyword static. We should call the
main() method without creating an object. Static methods are the method which invokes
without creating the objects, so we do not need any object to call the main() method.

void: In Java, every method has the return type. Void keyword acknowledges the
compiler that main() method does not return any value.

main(): It is a default signature which is predefined in the JVM. It is called by JVM to


execute a program line by line and end the execution after completion of this method.
We can also overload the main() method.

String args[]: The main() method also accepts some data from the user. It accepts a
group of strings, which is called a string array. It is used to hold the command line
arguments in the form of string values.

.
Example

1. class Demo
2. {
3. static //static block
4. {
5. System.out.println("Static block");
6. }
7. public static void main(String args[]) //static method
8. {
9. System.out.println("Static method");
10. }
11. }

Output:

Static block
Static method

You might also like