Java Syntax

JK 2010 
Created at
Updated at  
7,406 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,133
  2. Java Getting Started
    7,376
  3. Java Comments
    7,957
  4. Java Variables
    7,421
  5. Java Math
    7,405
  6. Java If ... Else
    7,360
  7. Java Short Hand If...Else (Ternary Operator)
    7,540
  8. Java Switch Statements
    7,374
  9. Java While Loop/Do While Loop/For Loop/For-Each Loop/Break/Continue
    7,804
  10. Java Methods
    7,062
  11. Java Scope
    7,071
  12. Java Recursion
    7,181
  13. Java Classes and Objects
    7,060
  14. What is Java?
    7,072
  15. Java Packages
    7,154
  16. Java Inheritance (Subclass and Superclass)
    7,159
  17. Java Polymorphism
    7,036
  18. Java Inner Classes
    7,026
  19. Machine Learning Types and Programming Languages
    7,209
  20. Java Tutorials associated with AP Computer Science A
    7,557
  21. Creating a simple Java Servlet (Web Server Page) with Apache Maven on Microsoft Windows
    7,146
  22. Java Servlet Example
    7,101
  23. Difference between Java and Javascript
    7,567
  24. Challenge: One Code Problem Per Day
    1,041
  1. Java Packages
    7,154
  2. Java Abstract Classes and Methods
    7,672
  3. Java Classes and Objects
    7,060
  4. Java Recursion
    7,181
  5. Java Scope
    7,071
  6. Java Methods
    7,062
  7. Java Arrays
    8,611
  8. Java While Loop/Do While Loop/For Loop/For-Each Loop/Break/Continue
    7,804
  9. Java Switch Statements
    7,374
  10. Java Short Hand If...Else (Ternary Operator)
    7,540
  11. Java If ... Else
    7,360
  12. Java Math
    7,405
  13. Java Variables
    7,421
  14. Java Comments
    7,957
  15. The Print() Method
    7,133
  16. Java Getting Started
    7,376
  17. What is Java?
    7,072
Recently updated
  1. Bootstrap vs. Tailwind CSS: Origins, Features, Pros & Cons, and How to Choose the Right Framework
    62
  2. The Complete Guide to Golang: History, Features, Real-World Uses, and Code Examples
    140
  3. Telemetry vs. Analytics: Understanding the Difference and Why It Matters
    172
  4. The Evolution and Production Reality of Agentic AI
    166
  5. How to Activate or Waive Your UIUC Student Health Insurance
    240
  6. Complete Guide to Building a Machine Learning Model
    290
  7. My life cuts at Las Vegas during Thanksgiving day holiday
    7,369
  8. The Cybercab Transformation: From Autonomous Taxi to Mobile Base Station
    313
  9. Harness vs. OpenClaw: Two Very Different "Agents"
    903
  10. Clean Python Environments: The Power of venv vs. Docker
    771
  11. What is Docker? Why is Docker also useful in a development environment?
    584
  12. UIUC 2026-2027 Academic Calendar
    1,466
  13. How to Build Llama 3 AI Apps with Python: Setup & User Prompts
    762
  14. Open-Source LLMs: The AI Revolution
    709
  15. Resume 2.0: Leveling Up for My First Software Gig
    2,084
  16. Not everyone will understand what this man just did
    1,729
  17. UIUC Dorm Guide: Find Your Perfect Fit !!
    1,545
  18. Unpacking IU's Shopper
    709
  19. Jackie Chan's Police Story: The Action Masterpiece
    608
  20. The IVE Story: Identity, 'I AM' Charts, and Influence
    910
  21. Tech Visionaries who graduated at UIUC - You are the Next Turn
    1,147
  22. Open Databases for Sex Crime Occurrences in the U.S.
    675
  23. Automatically copy text to the clipboard when dragging the mouse in the Cursor
    2,521
  24. My First Day at University of Illinois-Urvana Champaign
    1,155
  25. Sand, Sea, and a Splash of Fun at Newport Beach: A Family Adventure
    8,084
  26. Sun, Rocks, and Adventure: A Day at Joshua Tree National Park
    8,157
  27. Sipping the Stars: My Starbucks Adventure
    9,576
  28. Exciting explore at Sequoia National Park
    7,616
  29. My Life Shot at Death Valley
    1,629
  30. Ip Man fights with Muay Thai Master
    900
  31. Mad Clown - Don't Die
    974
  32. How to get Student Enrollment and Degree Verification at UIUC
    4,656
  33. LAX Thanksgiving Rush: A Joyful Reunion
    896
  34. ZO ZAZZ(조째즈) - Don`t you know (모르시나요) (PROD.ROCOBERRY)
    1,079
  35. FISHINGIRLS Unleashes Energetic EP 'Funiverse' Featuring Signature Track 'Fishing King'
    943
  36. 10CM - To Reach You (너에게 닿기를)
    1,127
  37. Feeling weak? Transform yourself at the UIUC ARC!
    1,547
  38. BOYNEXTDOOR - If I Say I Love You
    1,154
  39. The Future of Software Engineer - AI Engineering
    913
  40. G Dragon x Taeyang (Eyes Nose Lips, Power, Home Sweet Home, GOOD BOY) - LE GALA PIÈCES JAUNES 2025
    881
  41. Lie - Legend song by BIGBANG
    7,788
  42. Why ROLLBACK is useful when you work with Google Gemini CLI?
    806
  43. Reimbursement after Vaccination at McKinley Health Center
    974
  44. Gemini CLI makes a Magic! Time to speed up your app development with Google Gemini CLI!
    936
  45. Common Questions from UIUC school life in terms of CS Program
    1,074
  46. UIUC Immunization Compliance
    1,165
  47. LEE CHANHYUK's songs really resonate with my soul - Time Stop! Vivid LaLa Love, Eve, Endangered Love ...
    1,064
  48. LEE CHANHYUK - Endangered Love (멸종위기사랑)
    1,068
  49. Cupid (OT4/Twin Ver.) - LIVE IN STUDIO | FIFTY FIFTY (피프티피프티)
    844
  50. Common methods to improve coding skills
    958