<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">On 5/7/2024 3:06 PM, Olexandr Rotan
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAL5bRt_Y+sO5yBBzf1Tu=546ob+VLkNAvxapBVb-Lm4iUmA75w@mail.gmail.com">
<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>
</blockquote>
<br>
This direction ("just let me mix statements and variables at the top
level, and let the compiler figure it out") was extensively explored
during the design process, for the obvious reasons, but it turned
out that this falls afoul of the project goals in a pretty big way,
so it was rejected. <br>
<br>
<blockquote type="cite" cite="mid:CAL5bRt_Y+sO5yBBzf1Tu=546ob+VLkNAvxapBVb-Lm4iUmA75w@mail.gmail.com">
<div dir="ltr">
<div>I see this accomplishable without any changes to Java
language in a following way:</div>
</div>
</blockquote>
<br>
I think you may be confused on what "Java Language" means. You talk
about "compiler transformations" as if they are outside the
language, but the compiler *implements* the language, as specified
in the specification. The compiler has no latitude to accept
programs that are not given meaning by the specification. (To think
otherwise is a fatal type error.)<br>
<br>
<blockquote type="cite" cite="mid:CAL5bRt_Y+sO5yBBzf1Tu=546ob+VLkNAvxapBVb-Lm4iUmA75w@mail.gmail.com">
<div dir="ltr">
<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" moz-do-not-send="true" class="moz-txt-link-freetext">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" moz-do-not-send="true" class="moz-txt-link-freetext">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>
</blockquote>
<br>
</body>
</html>