Reading — step 1 of 5
Learn
Hello, World
Every Java program lives inside a class, and every runnable program has one method the JVM hunts for at startup: public static void main(String[] args). That exact signature is the contract. Match it and your program runs. Deviate — wrong capitalization, missing static, a different parameter type — and the JVM refuses to launch.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Read it from the outside in:
public class Main— all Java code lives inside classes. There are no free-floating functions like in Python or JavaScript. The grader on this platform compiles your file as classMain, so keep that name exactly as the starter has it.public static void main(String[] args)— the entry point.publicso the JVM can reach it from outside the class,staticso it can run before any object exists,voidbecause it returns nothing, andString[] argscarries command-line arguments (unused here, but required in the signature).System.out.println(...)— writes its argument to standard output, then moves to the next line.Systemlives injava.lang, which is imported automatically, so this works with zero setup.
Why all the ceremony?
Compared to Python's print("hi"), this looks heavy. The trade is deliberate: Java makes structure explicit from line one. Every program has an unambiguous entry point, every piece of code has a home, and the compiler checks all of it before anything runs. Small scripts pay a tax; large codebases collect the refund — you always know where execution starts and what type everything is.
The idiom and the trap
The working statement:
System.out.println("Hello, World!"); // capital S, double quotes, semicolon
The classic beginner breakages, and what the compiler says about each:
system.out.println("hi"); // error: cannot find symbol — Java is case-sensitive; it's System
System.out.println("hi") // error: ';' expected — every statement ends with a semicolon
System.out.println('hi'); // error — single quotes are for ONE char; text needs double quotes
And the sneakiest one: declaring public static void Main(...) with a capital M. That compiles — it is a perfectly legal method — but the JVM reports that no main method was found when you run it, because Main is not main.
println vs print
System.out.println("A"); // prints A, then a newline
System.out.print("B"); // prints B, the cursor stays on the same line
The grader compares your output character-for-character, including the newline at the end of the line — println produces exactly one complete line, which is what nearly every exercise on this platform expects.
Your exercise
Write a program that prints exactly:
Hello, Java!
One statement inside the provided main:
System.out.println("Hello, Java!");
The grader checks stdout byte-for-byte. The mistake it will catch: copying the lesson example and printing Hello, World! instead of Hello, Java! — or dropping the comma, lower-casing the J, or forgetting the exclamation mark. Exact text, println, done.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…