Coding/Learn/java/first program
Java Foundational Course
01.Introduction to Java
02.Your First Java Program
03.Syntax & Code Structure
04.Comments in Java
05.Variables & Declaration
06.Primitive Data Types
07.Numbers & Arithmetic Operators
08.Strings in Java
09.Booleans & Relational Operators
10.Type Casting & Conversion
11.Scanner & Interactive Input
12.Logical Operators (&&, ||, !)
13.If Statements
14.If-Else Statements
15.If-Else-If Ladders
16.Switch Statements
17.While Loops
18.Do-While Loops
19.Standard For Loops
20.Break & Continue Statements
21.Arrays in Java
22.Array Indexing & Traversal
23.Enhanced For-Each Loop
24.Essential String Methods
25.Methods in Java
26.Method Parameters & Arguments
27.Method Overloading
28.Classes & Objects in Java
29.Constructors in Java
30.Exception Handling (try-catch-finally)
31.Capstone Mini Projects
Course Certificate0%

Complete all lessons to earn

LearnYour First Java Program
2 / 31 0%
Lesson 02 of 31
6 mins read

Your First Java Program

PreviousNext Lesson
In Plain English

Every Java program begins with a structured blueprint. The main method is the ignition switch: when you run your program, the JVM seeks out this exact signature to start executing instructions step by step.

The Mental Model

"Think of the class as a factory building and the main method as the factory's main front entrance. When the JVM arrives to work, it looks specifically for the door labeled "public static void main"."

Deep Dive: How It Works

public: An access modifier meaning this method can be called from anywhere outside the class.

static: Tells Java that this method belongs to the class itself, so the JVM can run it without creating an object instance first.

void: Indicates that the method performs actions but does not return a value back.

String[] args: An array of strings representing command-line arguments passed into the program.

System.out.println vs System.out.print: println adds a line break at the end, while print keeps subsequent output on the exact same line.

Syntax Blueprint

System.out.print("Text on same line ");
System.out.println("and next line!");

Use print() to stay on the current line and println() to advance to a fresh line.

PointCore Rules to Remember

Point star
The Main Signature: public static void main(String[] args) is required for execution.
Point star
Semicolons are Mandatory: Every single statement in Java must end with a semicolon (;).
Point star
Case Sensitivity: Java is strictly case-sensitive: "System" is valid, "system" will fail to compile.

Common Beginner Traps & How to Fix Them

Mistake:Missing semicolon at end of statement

Why it happens: Forgetting ; causes a compile error: ';' expected.

How to fix: Ensure every executable line ends with a semicolon.

Pro Tip: You can concatenate text and numbers directly using the + operator inside System.out.println().

Live Interactive Example

Hit Run Code to see it live
Comparing print and println
Java 13
1
2
3
4
5
6
7
8
9
Output Console
Click "Run Code" to view the rendered output.
How it works: The first three print() calls remain on line 1 until println() triggers a line break.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Print a two-line status report

  • PointPrint "System: ONLINE" on line 1.
  • PointPrint "Status: READY" on line 2.
1
2
3
4
5
6
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates