Question: Why do you have to have a main method in a class MyClass to run a Java program via java MyClass ? What's going on

Why do you have to have a main method in a class MyClass to run a Java program via "java MyClass" ? What's going on here when the program runs?


GUI components have an "addActionListener" method which takes as an argument an object that implements the ActionListener interface. However, we don't actually have to build a class that implements the ActionListener interface, instantiate it as an object, and pass it to addActionListener.


 Instead we can just pass in a lambda function. Why is this allowed and how does it know to call that lambda method?

Step by Step Solution

3.31 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

In Java the main method is the entry point for a Java program When you run a Java program via the command java MyClass the Java Virtual Machine JVM lo... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!