1
\$\begingroup\$

Can someone tell me why sometimes people are including class C{public static void main(String[]a){...}} and sometimes that seems to be not necessary?(https://codegolf.stackexchange.com/a/62373/46569)

\$\endgroup\$
11
\$\begingroup\$

Whenever submissions are required to be full programs, Java's standard boilerplate code (i.e. class and main, etc.) is required. When submissions are allowed to be functions, this boilerplate is not required.

\$\endgroup\$
  • \$\begingroup\$ Unless the OP specifies otherwise, I think @AlexA. means. \$\endgroup\$ – Addison Crump Nov 18 '15 at 19:56
  • 2
    \$\begingroup\$ @VoteToClose I can't imagine a situation where the OP would require boilerplate for a function (thereby making it a full program) or not require boilerplate for a full program (thereby making it a snippet, which aren't allowed by default). \$\endgroup\$ – Alex A. Nov 18 '15 at 20:01
  • \$\begingroup\$ You could have a fickle OP :P \$\endgroup\$ – Conor O'Brien Nov 18 '15 at 20:01
  • \$\begingroup\$ I meant "Unless the OP specifies otherwise, submissions are required to be full programs..." c: \$\endgroup\$ – Addison Crump Nov 18 '15 at 20:10
  • \$\begingroup\$ When it's a function, that doesn't mean just a function body though. So you still need the function header and whatnot, even though you don't need the rest of the boilerplate. \$\endgroup\$ – SuperJedi224 Nov 18 '15 at 20:16
  • \$\begingroup\$ Thanks for your answers, I actually completely missed the "write a program or function" \$\endgroup\$ – Joba Nov 18 '15 at 21:02
  • \$\begingroup\$ @VoteToClose Except that the default is the other way around. If not specified, functions are fine: meta.codegolf.stackexchange.com/q/2419/14215 \$\endgroup\$ – Geobits Nov 19 '15 at 14:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .