Ever wondered why the line public static void main(String[] args) looks like secret code? It’s actually the entry door to every Java program.

In simple words: a Java program is a set of instructions wrapped inside a class. The main method is the first thing the computer runs, like pressing the start button on a video game.

What makes up a Java program?

Think of a Java program as a tiny house. The class is the house’s frame, the main method is the front door, and the statements inside the method are the furniture you arrange.

Class declaration

The class line starts with the keyword class followed by a name that begins with a capital letter. It tells Java, “Hey, I’m building a new object called …”.

Main method signature

The exact phrase public static void main(String[] args) is non‑negotiable for a program that runs from the command line. Breaking it down:

  • public: anyone (the JVM) can call it.
  • static: it belongs to the class itself, not to an object.
  • void: it returns nothing.
  • String[] args: an array (list) of text values you can pass when you start the program.

Statements and braces

Everything you want the computer to do goes inside the curly braces { } that follow the main line. Each line that ends with a semicolon ; is a statement, like a command in a recipe.

Comments

Anything after // on a line, or between /* and */, is ignored by Java. Use them to leave notes for yourself or your future self.

Full example of the very first program

public class HelloWorld {
    public static void main(String[] args) {
        // Print a friendly greeting
        System.out.println("Hello, world!");
    }
}

When you run this, the screen shows Hello, world!. That single line inside println is a statement that tells Java to send text to the console.

Quick reference table

PartDescription
classDefines the blueprint; must match the file name (HelloWorld.java).
public static void main(String[] args)The entry point; Java looks for this exact signature to start execution.
System.out.println()Prints text followed by a new line on the console.
{ }Curly braces group code blocks; they mark the start and end of the class and method.
// commentSingle‑line note ignored by the compiler.

How to go from code to running program

graph TD A[Write code in a .java file] --> B[Save file with same name as class] B --> C[Compile with javac] C --> D{Compilation error?} D -- Yes --> E[Fix errors and re‑compile] D -- No --> F[Run with java] F --> G[See output on console]

In everyday terms, it’s like writing a recipe, checking it for mistakes, then cooking the dish and finally tasting it.

Common pitfalls for ICSE students

  • File name must match the class name exactly (case‑sensitive).
  • Missing the public static void main line means the program won’t start.
  • Forgetting a semicolon at the end of a statement causes a compile‑time error.
  • Using double quotes inside the printed text without escaping them (e.g., "Hello") breaks the code.

📝 Likely Exam Questions

  1. Write the complete structure of a Java program that prints “Welcome”.
    Answer: Provide the code with class, main method, and System.out.println("Welcome"); inside.
  2. Explain the role of each keyword in the main method signature.
    Answer: public – accessible to JVM; static – belongs to class; void – returns nothing; String[] args – holds command‑line arguments.
  3. What will happen if the file name does not match the class name?
    Answer: The compiler will throw an error like “class HelloWorld is public, should be declared in a file named HelloWorld.java”.
  4. Identify the error in the following snippet and correct it:
    public class Test {
        public static void main(String args) {
            System.out.println("Hi);
        }
    }
    
    Answer: Change String args to String[] args and close the quote in println – System.out.println("Hi");.
  5. List three parts of a Java program and give a one‑line description for each.
    Answer: Class – defines the program’s blueprint; Main method – entry point where execution starts; Statements – commands that perform actions.
#ICSE#Class 10#Java#Programming#Computer Applications