Preskočiť na hlavný obsah

What is the minimum app in Java (21)?

Who doesn't know "Hello, World!"? When you start writing a code in a new language, you usually write this simple program. What does it look like in Java code?

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

But, explain to a beginner what "public static void" and strange args are. What would you say if the program could be simplified.

class App { 
    void main() { 
        System.out.println("Hello, World!");
    }
}

Let's make it even simpler, without class declaration.

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

Yes, this is simplest Java code in Java 21 release. Try it yourself. In a Java 21 preview feature (JEP 445) it needs to be enabled by with the --enable-preview flag. Just compile your application by command javac --release 21 --enable-preview App.java and run it as simple as java --enable-preview App

This simplification increases the flexibility and ease of use of Java, especially for beginners who are still learning basic programming concepts. The feature "Implicit Classes and Extended Main Methods" (still preview), proposes to develop the Java language so that students can write their first programs without having to understand language more complex features designed for larger programs.

Obľúbené príspevky z tohto blogu

mysql 5.0 upgrade to 5.1

The 5.1 series of MySQLwas unmasked for the gentoo portage. When upgrading from an older major version (including 5.0), you will be required to rebuild everything linked to the libmysqlclient.so.15 and libmysqlclient_r.so.15. You can do this by installing app-portage/gentoolkit and running: # revdep-rebuild --library libmysqlclient.so.15 # revdep-rebuild --library libmysqlclient_r.so.15 If you use the Portage 2.2 series, you may also use: # emerge @preserved-rebuild The official upgrade documentation is available here: http://dev.mysql.com/doc/refman/5.1/en/upgrading.html Note that existing databases may need converting as well, again including those upgrading from 5.0 to 5.1.