beginner 8 views
Writing Your First Java Program
Create, compile, and run a simple HelloWorld program while learning the structure of a Java application.
Writing Your First Java Program
The traditional first program prints a message to the console. In Java every executable program needs a public static void main(String[] args) method.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Welcome to the Java Platform!");
}
}
Explanation:
public class HelloWorld– defines a class named HelloWorld accessible from anywhere.public static void main(String[] args)– the entry point the JVM calls when launching the program.System.out.println(...)– writes the supplied text followed by a newline to the standard output stream.
Remember: The class name must match the filename (HelloWorld.java) and the main method must be exactly as shown for the JVM to recognise it.
HelloWorld.java
HelloWorld.javaJAVA
Sign in to ask a question or join the discussion.
Practice what you just read
Take a test on introduction