Basics - what does 'public class YourName { public static void main(String[] args) {' mean? the course offers no explanation at the introduction



<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>


Replace this line with your code.

<do not remove the three backticks above>


Let’s break it down:
public class YourName{} simply defines a class called YourName
This class contains the public static void main(String[] args){} defines the main function in a java program. It serves as the entry point to the program, and when you compile and run the java app, main is the first thing that runs.
String[] args is a parameter that accepts inputs from the command line, if you were to run it there.

public This allows the function to be accessed from outside of the class it is currently in. This is necessary, because the method is being called by the Java Runtime Environment.
static This allows the Java Virtual Machine to allow invocation of the method from within the YourName class
void Since the main function is what defines the program itself, there is no point in having it return a value. Void simply says “This function will not return anything”

The first lesson almost never fully explains what these things mean because you’ll learn them as time passes, and because it can be overwhelming at first. Just stick with it, and it’ll start to make sense after a while.


Thank you kindly, I expect familiarity will come with practice and thinking but your reply is very clear and direct. I appreciate that.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.