Java Syntax & Output

Classes, main method, statements and println.

✍️ 2 exercises in this lesson

Every Java program has at least one class, and execution starts in the main method:

public static void main(String[] args)

  • Statements end with a semicolon ;.
  • Code blocks use curly braces { }.
  • Java is case-sensitive: Main and main are different.
  • System.out.println() prints a line; System.out.print() prints without a new line.

Java Comments

// single line and /* multi-line */

Key Takeaways: Java Syntax & Output

Mastering Java Syntax & Output helps you write clean and reliable Java code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Java Syntax & Output Code Example

Java
public class Main {
    public static void main(String[] args) {
        // Print some text
        System.out.println("Line one");
        System.out.print("Same ");
        System.out.print("line");
        System.out.println();
        System.out.println(3 + 4);
    }
}
Output
Line one
Same line
7
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

Java Syntax & Output Practice Exercises

Check what you learned in “Java Syntax & Output”.

/ 2 solved
Fill in the blank

Complete the main method signature.

public static  main(String[] args)
✓ Correct! Not quite. Try again.
Multiple choice

Which prints text without a new line?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services