JOOPs Through Java
All lessons

Unit 1 · Starting From Zero · 9 min

Your first Java program

Java source code defines classes. A standard console application can start from a method with the signature public static void main(String[] args).

Why this matters

You will see this entry-point structure in many beginner console programs, so understanding it makes lab exercises easier to follow.

Real-life analogy

A runnable class's main method is like a labelled entrance the Java launcher knows how to use. A project may contain several classes with main methods, but you choose which one to launch.

Syntax

Syntax
class ClassName {
    public static void main(String[] args) {
        // your statements go here
    }
}

Example

Java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, BCA student!");
        System.out.println("Welcome to OOPs Through Java.");
    }
}

Output

Hello, BCA student!
Welcome to OOPs Through Java.

Step by step

  1. 1`public class Hello` — creates a class named Hello. The file must be saved as Hello.java.
  2. 2`public` makes this entry method accessible to the Java launcher.
  3. 3`static` lets the Java launcher call main without creating an object first.
  4. 4`void` means main gives nothing back when it finishes.
  5. 5`main(String[] args)` is the conventional application entry point; args can hold command-line values.
  6. 6`System.out.println(...)` prints a line of text and then moves to the next line.
  7. 7Every statement ends with a semicolon `;`. Every `{` must have a matching `}`.

Key points

  • A standard launched class uses public static void main(String[] args) as its entry point
  • A project can contain more than one class with a main method; the selected class determines where that run starts
  • File name must match the public class name
  • Java is case sensitive
  • println adds a new line, print does not

Common mistakes

  • Saving the file with a different name than the public class
  • Writing `Public` or `Void` with a capital letter — Java is case sensitive
  • Forgetting the semicolon at the end of a statement
  • Using print instead of println and wondering why output is on one line

Try it yourself

  • Print your name, your course and your college on three separate lines.
  • Change println to print and observe the difference.
Open the practice notebook