Java 21 will no longer have public static void main!

The previous Java was like this:

47ba522a84e3d63bc4cf97e99e3adc38.png

Java 21 will be like this:

0704b9d002294d2d954a7051612280ee.png

Seeing this news, my biggest feeling is: 

Fuck, why is it Java 21? ! I'm still using Java 8!

In fact, from Java 8 to Java 21, the middle is Java 11, Java 17 is the long-term support version, and the others are "minor" versions with little change. 

The proposal to remove "public static void main" this time comes from JEP 445: Unnamed Classes and Instance Main Methods.

For a long time, the complaints about Java are "too verbose", "too much ritual", and Java imposes this sense of ritual on everyone who learns it for the first time.

For class declaration and public static void main, every novice finds it incomprehensible incantations, and they become a huge obstacle on the way of learning. 

A lovely American teacher actually created a RAP to help novices memorize "public static void main"!

public class HelloWorld { 
    public static void main(String[] args) { 
        System.out.println("Hello World");
    }
}

For the uninitiated, this simple five lines of code say, seriously overloaded with information:

(1) public on the class   

It only makes sense when accessing across packages, why does a simple Hello World have to write it?

(2) class 

Novices just want to write hello world, do they still have to understand what a class is?

(3) public on the method 

What the hell is this? Why add a public

(4) static 

Novices can't understand what static methods are, why static methods are needed.

(5)  String[] args

The definition of this parameter is also confusing for novices

(6) System.out.println(...)

System is a class, out is a static field, and println is an instance method. The only thing students care about is println.

On the first day of class, a lot of things need to be explained, and the get out of class is about to end, and the students can't write any programs, so the teacher has to say: remember first, you will understand later.

So Brian Goetz believes that all this must be simplified.

The first step uses a more permissive "startup protocol", which can be changed to this:

class HelloWorld { 
    void main() { 
        System.out.println("Hello World");
    }
}

The second step is changed to this by introducing "unnamed class":

void main() { 
    System.out.println("Hello World");
}

The third step, "Automatically import static methods", is changed to this:

void main() {
    println("Hello World");
}

It looks clearer and clearer, and it will be very friendly to Java beginners. 

But when it comes to JEP, System.out.println is still reserved, I don't know why.

For this change, netizens are frying pan, some people say: Hey, you forgot one thing: Script

d8d2d2c24a98b79a5808638795a677a2.png

Others said that the Java logo should become like this in the future:

e4513d085d9c98931a1d13ddb2335aef.png

What I need to remind everyone is that this is a preview function, which is disabled by default in the JDK, mainly to reduce the cognitive burden when teaching Java.

After more than 20 years of development, a huge ecology has been established around Java, and all kinds of software are available. While Java is extremely successful, it also puts a heavy burden on Java. If you want to simplify it into Python and JS It is almost impossible to use scripting language, and it is commendable to be able to take a small step this time.

References: https://openjdk.org/projects/amber/design-notes/on-ramp

https://openjdk.org/jeps/445

(over)

Finally, let’s promote the planet "ChatGPT base" established by Shanke and I, which is dedicated to exploring the position of programmers in the ChatGPT era and how to use ChatGPT to improve work efficiency.

In the field of programmers, our planet may be the most deeply engaged in ChatGPT . It has gone far beyond the ChatGPT chat stage. Many people have entered API development and even privatized model training.

ChatGPT chat -> use ChatGPT API to develop applications -> train privatization and deploy large models

Many friends here have evolved from Xiaobai to skilled players in the field of ChatGPT. Planet’s column has many valuable topics:

60df698201c5e8e8b22abe24660dcc95.png

Come to this planet, brush your heart for a few days, and you will surpass 99% of people in this field without knowing it.

The planet now has these events:

Join the planet to get a ChatGPT account (only for the top 100 who entered the planet today, contact information: add WeChat onlyliuxin97, password: ChatGPT planet )

Export high-quality content and send a 100 yuan red envelope

Now the planet is in the trial operation period, the original price is 199 yuan, now there is a coupon of 100 yuan , which is equivalent to 99 yuan , you can join, embrace ChatGPT early, become the first batch of people who can use ChatGPT and use ChatGPT well, and take the lead , get bonus.

a548e6e793da9b887664d9e528b09286.png

Guess you like

Origin blog.csdn.net/coderising/article/details/131078827