B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP Java Main Method Explained | TutorialsApp

Java public static void main Method

What is the main method in Java?

It is the entry point of any Java application. Syntax:

public static void main(String[] args)
Explanation of Each Keyword:
  • public: JVM can access this method from anywhere.
  • static: Method can be called without creating object.
  • void: Method doesn't return anything.
  • main: Standard method name where execution starts.
  • String[] args: Takes input from command line as array of Strings.
Example:
public class Hello {
    public static void main(String[] args) {
        System.out.println("Welcome to Java!");
    }
}
Frequently Asked Questions
  • Why must the method be public? Because JVM must be able to access it from outside the class — otherwise it will give an error.
  • Why is it static? If it were not static, we would need to create an object of the class. But JVM should run the method without needing that.
  • What does void mean again? It means the method does not return anything. It just runs and ends.
  • Can I rename args? Yes, you can change args to any other name:
    public static void main(String[] myInput) { ... }
    But don’t change main, String[], or the order — JVM won’t recognize it.
Summary Table:
WordTypePurpose
publicAccess ModifierMakes method accessible to JVM
staticKeywordNo object creation needed
voidReturn TypeNothing returned
mainMethod NamePredefined name used by JVM
String[]Argument TypeInput arguments in form of String array
argsArgument NameReference name for input data

Java का main method क्या होता है?

यह किसी भी Java प्रोग्राम की शुरुआत करने का पॉइंट होता है। Syntax:

public static void main(String[] args)
हर शब्द का मतलब:
  • public: यह method कहीं से भी accessible है
  • static: object बनाए बिना ही method कॉल किया जा सकता है
  • void: यह कोई value return नहीं करता
  • main: Java execution यहीं से शुरू होता है
  • String[] args: command-line से input के लिए
उदाहरण:
public class Hello {
    public static void main(String[] args) {
        System.out.println("Java में आपका स्वागत है!");
    }
}
अक्सर पूछे जाने वाले सवाल
  • method public क्यों होना चाहिए? क्योंकि JVM इसे बाहर से access करता है।
  • यह static क्यों है? ताकि इसे object बनाए बिना call किया जा सके।
  • void का क्या मतलब है? इसका मतलब method कोई value return नहीं करता।
  • args का नाम बदल सकते हैं? हाँ, इसे कुछ भी रख सकते हैं जैसे:
    public static void main(String[] myInput) { ... }
    लेकिन main, String[] या उनकी order को न बदलें।
सारांश तालिका:
शब्दप्रकारउद्देश्य
publicAccess ModifierJVM कहीं से भी access कर सके
staticकीवर्डobject की जरूरत नहीं
voidReturn Typeकुछ return नहीं करता
mainmethod नामexecution की शुरुआत
String[]argument प्रकारcommand-line से इनपुट
argsargument नामइनपुट का reference