Java Hello World program
KW.java
class KW 
{
    public static void main(String[] args) 
    {
        System.out.println("Hello, World!");
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Hello, World! kodingwindow@kw:~$
Java program without using main function (only compilation)
KW.java
class KW
{
    static 
    {
        System.out.println("Hello World");
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Error: Main method not found in class KW, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application kodingwindow@kw:~$
Advertisement