Java
Beginner
1 min read
What Is Java and Setting Up the JDK
Example
// File: HelloWorld.java
// Compile: javac HelloWorld.java
// Run: java HelloWorld
public class HelloWorld {
/**
* The main method is the entry point for every Java application.
* The JVM looks for this exact signature when starting execution.
*
* @param args command-line arguments passed to the program
*/
public static void main(String[] args) {
// Print a greeting to standard output
System.out.println("Hello, World!");
// Print the current Java version at runtime
String version = System.getProperty("java.version");
System.out.println("Running on Java " + version);
// Demonstrate System.out.printf for formatted output
String name = "Java Developer";
System.out.printf("Welcome, %s!%n", name);
// Show that args can be iterated
if (args.length > 0) {
System.out.println("Command-line arguments received:");
for (String arg : args) {
System.out.println(" " + arg);
}
} else {
System.out.println("No command-line arguments were provided.");
}
}
}