<div dir="ltr">Could it be possible to not oblige users to create a void main() method? It would be great if a person that sees java for the first time has the option to write code in plain document without any additional method declarations (even method concept is kind of hard for a complete newbie).<div><br></div><div>I see this accomplishable without any changes to Java language in a following way:</div><div><br></div><div>1. Every variable declaration is elevated to the top-level scope of implicitly declared class without initialization. Initialization will be performed later. There could possibly be a problem with var keyword, but if desugaring is performed after attribution, type idents could be explicitly added in the "trans" phase.</div><div>2. Every other top-level statement that is not a method or class declaration in a document is wrapped in the anonymous code block of an implicitly declared class. In this scope any "this" refs should be forbidden as well as return statements.</div><div>3. Every top-level class and method declaration is elevated to a top-level declaration inside an implicitly declared class. If a class is not static, any instance creation of such classes after desugaring should be created as this.new X(). Constructor declarations for implicitly declared class must be forbidden.</div><div>4. Main method is implicitly generated. It creates a new instance of implicitly declared class. This will trigger run of code in anonymous code blocks.</div><div><br></div><div>I understand that these changes could dramatically change current flow in the implementation, but this way I think this feature could be more friendly towards new users by allowing them to write their first hello world program without having to learn concepts of methods and possibly confusing concepts of void type.</div><div><br></div><div>Best regards.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 7, 2024 at 8:55 PM Mark Reinhold <<a href="mailto:mark.reinhold@oracle.com">mark.reinhold@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><a href="https://openjdk.org/jeps/477" rel="noreferrer" target="_blank">https://openjdk.org/jeps/477</a><br>
<br>
  Summary: Evolve the Java programming language so that beginners can<br>
  write their first programs without needing to understand language<br>
  features designed for large programs. Far from using a separate<br>
  dialect of the language, beginners can write streamlined declarations<br>
  for single-class programs and then seamlessly expand their programs to<br>
  use more advanced features as their skills grow. Experienced developers<br>
  can likewise enjoy writing small programs succinctly, without the need<br>
  for constructs intended for programming in the large. This is a preview<br>
  language feature.<br>
<br>
- Mark</blockquote></div>