Java Syntax

JK JK 2026 
Created at
Updated at  
7,472 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() Facebook X
Comments 0
Similar posts
  1. The Print() Method
    7,177
  2. Java Getting Started
    7,426
  3. Java Comments
    8,064
  4. Java Variables
    7,493
  5. Java Math
    7,455
  6. Java If ... Else
    7,421
  7. Java Short Hand If...Else (Ternary Operator)
    7,602
  8. Java Switch Statements
    7,427
  9. Java While Loop/Do While Loop/For Loop/For-Each Loop/Break/Continue
    7,920
  10. Java Methods
    7,110
  11. Java Scope
    7,124
  12. Java Recursion
    7,211
  13. Java Classes and Objects
    7,115
  14. What is Java?
    7,112
  15. Java Packages
    7,191
  16. Java Inheritance (Subclass and Superclass)
    7,195
  17. Java Polymorphism
    7,071
  18. Java Inner Classes
    7,083
  19. Machine Learning Types and Programming Languages
    7,268
  20. Java Tutorials associated with AP Computer Science A
    7,668
  21. Creating a simple Java Servlet (Web Server Page) with Apache Maven on Microsoft Windows
    7,193
  22. Java Servlet Example
    7,139
  23. Difference between Java and Javascript
    7,661
  24. Challenge: One Code Problem Per Day
    1,153
  1. How do I replace content that based on the HTML UI Template
    7,170
  2. Dataset of California Foodbanks
    7,192
  3. Java Abstract Classes and Methods
    7,775
  4. Java Arrays
    8,783
Recently updated
  1. Why You Can't Stop Watching Jack Bryan's Beatbox Gaming Shorts
    129
  2. Song So-hee: The Soulful Voice Touching Hearts Through Korean Music
    132
  3. Watch This Dazzling Dancer’s Mind-Blowing Moves
    162
  4. Michael Jackson's Billie Jean
    229
  5. Bootstrap vs. Tailwind CSS: Origins, Features, Pros & Cons, and How to Choose the Right Framework
    210
  6. The Complete Guide to Golang: History, Features, Real-World Uses, and Code Examples
    657
  7. Telemetry vs. Analytics: Understanding the Difference and Why It Matters
    326
  8. The Evolution and Production Reality of Agentic AI
    284
  9. How to Activate or Waive Your UIUC Student Health Insurance
    367
  10. Complete Guide to Building a Machine Learning Model
    398
  11. My life cuts at Las Vegas during Thanksgiving day holiday
    7,489
  12. The Cybercab Transformation: From Autonomous Taxi to Mobile Base Station
    420
  13. Harness vs. OpenClaw: Two Very Different "Agents"
    1,078
  14. Clean Python Environments: The Power of venv vs. Docker
    915
  15. What is Docker? Why is Docker also useful in a development environment?
    680
  16. UIUC 2026-2027 Academic Calendar
    1,718
  17. How to Build Llama 3 AI Apps with Python: Setup & User Prompts
    883
  18. Open-Source LLMs: The AI Revolution
    833
  19. Resume 2.0: Leveling Up for My First Software Gig
    2,428
  20. Not everyone will understand what this man just did
    2,030
  21. UIUC Dorm Guide: Find Your Perfect Fit !!
    1,669
  22. Unpacking IU's Shopper
    838
  23. Jackie Chan's Police Story: The Action Masterpiece
    720
  24. The IVE Story: Identity, 'I AM' Charts, and Influence
    1,024
  25. Tech Visionaries who graduated at UIUC - You are the Next Turn
    1,248
  26. Open Databases for Sex Crime Occurrences in the U.S.
    778
  27. Automatically copy text to the clipboard when dragging the mouse in the Cursor
    2,841
  28. My First Day at University of Illinois-Urvana Champaign
    1,259
  29. Sand, Sea, and a Splash of Fun at Newport Beach: A Family Adventure
    8,223
  30. Sun, Rocks, and Adventure: A Day at Joshua Tree National Park
    8,309
  31. Sipping the Stars: My Starbucks Adventure
    9,784
  32. Exciting explore at Sequoia National Park
    7,738
  33. My Life Shot at Death Valley
    1,797
  34. Ip Man fights with Muay Thai Master
    1,003
  35. Mad Clown - Don't Die
    1,100
  36. How to get Student Enrollment and Degree Verification at UIUC
    5,119
  37. LAX Thanksgiving Rush: A Joyful Reunion
    970
  38. ZO ZAZZ(조째즈) - Don`t you know (모르시나요) (PROD.ROCOBERRY)
    1,197
  39. FISHINGIRLS Unleashes Energetic EP 'Funiverse' Featuring Signature Track 'Fishing King'
    1,040
  40. 10CM - To Reach You (너에게 닿기를)
    1,212
  41. Feeling weak? Transform yourself at the UIUC ARC!
    1,626
  42. BOYNEXTDOOR - If I Say I Love You
    1,243
  43. The Future of Software Engineer - AI Engineering
    978
  44. G Dragon x Taeyang (Eyes Nose Lips, Power, Home Sweet Home, GOOD BOY) - LE GALA PIÈCES JAUNES 2025
    973
  45. Lie - Legend song by BIGBANG
    7,884
  46. Why ROLLBACK is useful when you work with Google Gemini CLI?
    914
  47. Reimbursement after Vaccination at McKinley Health Center
    1,077
  48. Gemini CLI makes a Magic! Time to speed up your app development with Google Gemini CLI!
    1,019
  49. Common Questions from UIUC school life in terms of CS Program
    1,190
  50. UIUC Immunization Compliance
    1,274