Your First Application: Blank File to Output

Your First Application: Blank File to Output in Java: Now you have a JDK and an IDE. This topic connects them: you will go from an empty folder to text printed…

Concept Explanation

Now you have a JDK and an IDE. This topic connects them: you will go from an empty folder to text printed on screen, and understand every piece you typed.

Every Java program needs exactly one entry point — the main method. When you press Run, the JVM looks for main, and starts there. No main, no program.


Step by Step

In IntelliJ, right-click the src folder, choose New → Java Class, and name it Welcome. Then type:

public class Welcome {
    public static void main(String[] args) {
        System.out.println("My first Java application");
        System.out.println("Compiled and running");
    }
}

Press Shift + F10. The console prints both lines.

What Each Keyword Does

  • public — visible from anywhere; the JVM must be able to reach main.
  • class Welcome — the container. The file must be named Welcome.java.
  • static — callable without creating a Welcome object first.
  • void — returns nothing.
  • main — the exact name the JVM searches for.
  • String[] args — values passed in from the command line.

What Happens When You Press Run

  1. javac compiles Welcome.java into Welcome.class (bytecode).
  2. The java launcher starts a JVM.
  3. The JVM loads Welcome.class and calls main.
  4. Your text reaches the console.

The same thing by hand:

javac Welcome.java
java Welcome

Note you run java Welcome — the class name, not Welcome.class.


Common Mistakes

  1. Filename mismatch: public class Welcome must live in Welcome.java. Java is strict about this.
  2. Misspelling main: Main, mian, or main() without String[] args all produce "main method not found".
  3. Running the file, not the class: java Welcome.class fails. Drop the extension.

Best Practices

  • PascalCase class names: Welcome, OrderProcessor — never welcome.
  • Keep main thin: As programs grow, main should call other methods rather than hold all the logic.
  • Run early and often: Compile after every few lines so errors stay small and findable.

Practice Exercises

  1. The Introduction: Write a class AboutMe that prints your name, your city, and why you are learning Java on three lines.
  2. The Manual Route: Compile and run the same class from the terminal with javac and java instead of the IDE button.
  3. The Break-It Drill: Rename the class to Welcome2 but leave the file as Welcome.java. Read the error, then fix it.