Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Java Interview Question – Explain public static void main(String[] args)

Posted on 02/08/2025 By admin

This is an important interview question in Java and mainly asked to Freshers. I will try to explain my best it here.

A Java program has a starting point of execution with a predefined signature of main method in a class. Method signature of main method is given below:-

public static void main(String[] args){}

This could be also written as:-

public static void main(String... args)
public static void main(String args[])

Let me break above method signature in to pieces so that you will understand it better.

“public“: It is a Java keyword first so written in small case. It is an access specifiers or modifiers. Access modifiers are keywords in Java that set the accessibility of classes, methods, and other members. A public method can be accessed globally. Java Runtime Environment needs to call this main method outside of the class which is only possible if main method is made public. Declaring main method with any other access specifiers will not allow JVM to run it. If you do so, that main method will be considered as a normal java method and JVM will look for the main method with expected signature and throw error “Main method not found in class”.

“static“: It is a Java keyword first so written in small case. Members declared as static in a Java class belong to class not its instance or object. When a Java class is loaded into memory, all its static members are also loaded in to memory unlike non-static members. You can access any static members without creating an object of class.

JVM can not create an object of class at run time to access main method. So only way is to declare main method as static so that JVM can load the class in to memory and can access static main method and start execution of program.

“void“:- It is a Java keyword first so written in small case. When a method does not return any value, we need to specify void in method signature. A Java program starts with main method and ends as soon as execution of main method finishes. So if you make main method to return something, you can not use returned value.

“main“:- It is method name which is fixed. JVM searches for the method with name “main”.

“String[] args“:- Java “main” method accepts an argument of type String[]. “args” is just a name of arguments and you can change it to anything. But you can not change type of args. It must be String[]. We can pass args value from command line or run configuration. When we do not pass any argument, its size is zero.

Hope, I am able to explain in details. If you have any doubt, concerns or feedback, do let me know.

#ThanksForReading

Uncategorized

Post navigation

Previous Post: Git Tutorial 25 – Important Pattern Formats For the .gitignore file
Next Post: browser

Related Posts

Git Tutorial 11 – Git Pull – Download And Merge Changes From Remote Repository Uncategorized
InnerClassTestNg – Make Selenium Easy Uncategorized
ConsoleStarted – Make Selenium Easy Uncategorized
Locators in Selenium Uncategorized
How To Locate Web Element Which Has Multiple Class Names Uncategorized
Git Tutorial 2 – What is GIT and Its Advantages? Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark