Java Syntax

JK1982 
Created at
Updated at  

  7,280   0   0  

In the vast landscape of programming languages, Java stands as a titan – revered for its versatility, reliability, and widespread usage. At the heart of Java lies its syntax, the rules and conventions that govern the structure and behavior of code. Let us embark on a journey to unravel the intricacies of Java syntax, starting with the fundamental building blocks of a Java program.

“The essence of programming is to control complexity, not to create it.” - Kernighan

Let us understand the basic structure of Java based on below code

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

Every line of code that runs in Java must be inside a class. In our example, we named the class Main. A class should always start with an uppercase first letter.

Note: Java is case-sensitive: "MyClass" and "myclass" has different meaning.

The name of the java file must match the class name. When saving the file, save it using the class name and add ".java" to the end of the filename. The output for above code should be:

Hello World

The main Method

The main() method is required and you will see it in every Java program:

public static void main(String[] args)

Any code inside the main() method will be executed. Don't worry about the keywords before and after main. You will get to know them bit by bit while reading this tutorial.

For now, just remember that every Java program has a class name which must match the filename, and that every program must contain the main() method.


System.out.println()

Inside the main() method, we can use the println() method to print a line of text to the screen:

public static void main(String[] args) {
  System.out.println("Hello World");
}

 

Java syntax serves as the bedrock upon which robust and reliable software solutions are built. By adhering to established conventions and mastering the intricacies of syntax, developers unlock the full potential of the Java programming language, empowering them to craft elegant, efficient, and maintainable code.



Tags: Java Java Class Java Syntax Kernighan main() println() Share on Facebook Share on X

◀ PREVIOUS
Java Getting Started

▶ NEXT
The Print() Method

  Comments 0
SIMILAR POSTS

The Print() Method

(updated at )

Java Getting Started

(updated at )

Java Comments

(updated at )

Java Variables

(updated at )

Java Math

(updated at )

Java If ... Else

(updated at )

Java Short Hand If...Else (Ternary Operator)

(updated at )

Java Switch Statements

(updated at )

Java While Loop/Do While Loop/For Loop/For-Each Loop/Break/Continue

(updated at )

Java Methods

(updated at )

Java Scope

(updated at )

Java Recursion

(updated at )

Java Classes and Objects

(updated at )

What is Java?

(created at )

Java Packages

(updated at )

Java Inheritance (Subclass and Superclass)

(updated at )

Java Polymorphism

(created at )

Java Inner Classes

(updated at )

Machine Learning Types and Programming Languages

(updated at )

Java Tutorials associated with AP Computer Science A

(updated at )

Creating a simple Java Servlet (Web Server Page) with Apache Maven on Microsoft Windows

(created at )

Java Servlet Example

(created at )

Difference between Java and Javascript

(updated at )

Challenge: One Code Problem Per Day

(created at )

OTHER POSTS IN THE SAME CATEGORY

Java Packages

(updated at )

Java Abstract Classes and Methods

(updated at )

Java Classes and Objects

(updated at )

Java Recursion

(updated at )

Java Scope

(updated at )

Java Methods

(updated at )

Java Arrays

(updated at )

Java While Loop/Do While Loop/For Loop/For-Each Loop/Break/Continue

(updated at )

Java Switch Statements

(updated at )

Java Short Hand If...Else (Ternary Operator)

(updated at )

Java If ... Else

(updated at )

Java Math

(updated at )

Java Variables

(updated at )

Java Comments

(updated at )

The Print() Method

(updated at )

Java Getting Started

(updated at )

What is Java?

(created at )

UPDATES

Harness vs. OpenClaw: Two Very Different "Agents"

(updated at )

Clean Python Environments: The Power of venv vs. Docker

(updated at )

What is Docker? Why is Docker also useful in a development environment?

(created at )

UIUC 2026-2027 Academic Calendar

(updated at )

How to Build Llama 3 AI Apps with Python: Setup & User Prompts

(updated at )

Open-Source LLMs: The AI Revolution

(updated at )

Resume 2.0: Leveling Up for My First Software Gig

(created at )

Not everyone will understand what this man just did

(created at )

UIUC Dorm Guide: Find Your Perfect Fit !!

(updated at )

Unpacking IU's Shopper

(created at )

Jackie Chan's Police Story: The Action Masterpiece

(updated at )

The IVE Story: Identity, 'I AM' Charts, and Influence

(updated at )

Tech Visionaries who graduated at UIUC - You are the Next Turn

(updated at )

Open Databases for Sex Crime Occurrences in the U.S.

(updated at )

Automatically copy text to the clipboard when dragging the mouse in the Cursor

(updated at )

My First Day at University of Illinois-Urvana Champaign

(updated at )

Sand, Sea, and a Splash of Fun at Newport Beach: A Family Adventure

(updated at )

Sun, Rocks, and Adventure: A Day at Joshua Tree National Park

(updated at )

Sipping the Stars: My Starbucks Adventure

(updated at )

Exciting explore at Sequoia National Park

(updated at )

My Life Shot at Death Valley

(updated at )

Ip Man fights with Muay Thai Master

(created at )

Mad Clown - Don't Die

(created at )

How to get Student Enrollment and Degree Verification at UIUC

(updated at )

LAX Thanksgiving Rush: A Joyful Reunion

(updated at )

ZO ZAZZ(조째즈) - Don`t you know (모르시나요) (PROD.ROCOBERRY)

(updated at )

FISHINGIRLS Unleashes Energetic EP 'Funiverse' Featuring Signature Track 'Fishing King'

(updated at )

10CM - To Reach You (너에게 닿기를)

(updated at )

Feeling weak? Transform yourself at the UIUC ARC!

(updated at )

BOYNEXTDOOR - If I Say I Love You

(updated at )

The Future of Software Engineer - AI Engineering

(updated at )

G Dragon x Taeyang (Eyes Nose Lips, Power, Home Sweet Home, GOOD BOY) - LE GALA PIÈCES JAUNES 2025

(updated at )

Lie - Legend song by BIGBANG

(updated at )

Why ROLLBACK is useful when you work with Google Gemini CLI?

(created at )

Reimbursement after Vaccination at McKinley Health Center

(created at )

Gemini CLI makes a Magic! Time to speed up your app development with Google Gemini CLI!

(created at )

Common Questions from UIUC school life in terms of CS Program

(created at )

UIUC Immunization Compliance

(created at )

LEE CHANHYUK's songs really resonate with my soul - Time Stop! Vivid LaLa Love, Eve, Endangered Love ...

(created at )

LEE CHANHYUK - Endangered Love (멸종위기사랑)

(created at )

Cupid (OT4/Twin Ver.) - LIVE IN STUDIO | FIFTY FIFTY (피프티피프티)

(created at )

Common methods to improve coding skills

(created at )

US National Holiday in 2026

(created at )

BABYMONSTER “WE GO UP” Band LIVE [it's Live] K-POP live music show

(created at )

BLACKPINK - ‘Shut Down’ Live at Coachella 2023

(created at )

JENNIE - like JENNIE - One of Hot K-POP in 2025

(created at )

BABYMONSTER(베이비몬스터) - DRIP + HOT SOURCE + SHEESH

(created at )

Common Naming Format in Software Development

(created at )

In a life where I don't want to spill even a single sip of champagne - LEE CHANHYUK - Panorama(파노라마)

(created at )

Countries with more males and females - what about UIUC?

(created at )