Java learning: Hello World program with java

Recently, I begin to use java in my work. I used to c++ for more than 10 years.

Programmer start every thing begin with Hello World

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

Java main function, must be in a public class

 public static void main(String[] args) {} 

Compile HelloWorld

javac HelloWorld.java

Execute HelloWorld

java HelloWorld
remember, not java HelloWorld.class
otherwise, you will got below error
Error: Could not find or load main class HelloWorld.class

No comments:

Post a Comment

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...