Does all the java code have to be within public static void main(String[ ] args) { ) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Does all the java code have to be within public static void main(String[ ] args) { )

I was wondering if all the code in a java program has to be within ///public static void main(String[ ] args) { } similar like how it is in html and the body tag

12th Jun 2019, 9:45 PM
Shaurya Sen
Shaurya Sen - avatar
2 Answers
+ 4
No...but if you are writing POJO means Plain Old Java Object Class then you need to use it. Because without main method you can't compile it and it will throw exception "main" method not found in the class. If you are writing in back-end for web based website then no need to use.
12th Jun 2019, 9:50 PM
A͢J
A͢J - avatar
+ 2
The main method is inside of a class. You can code outside of this class yes but it still has to be inside of some other class.. The main method is were your program begins executing.
12th Jun 2019, 11:51 PM
D_Stark
D_Stark - avatar