Welcome to one of the most exciting parts of your Java journey — understanding the syntax! At GoNimbus, we believe learning Java should be both logical and enjoyable. Let’s break down the essential rules that make your Java programs run smoothly.


📂 Java File Structure

Every Java program begins with a class. Let’s take another look at a simple example:

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello, Java from GoNimbus!");
  }
}

🔍 Dissecting the Code

ElementWhat It Means
public class MainDeclares a class named Main. Class names in Java must start with a capital letter and match the filename (i.e., Main.java).
{ }Curly braces define the scope of your class or method.
public static void main(String[] args)This is the main method — the entry point where Java starts executing your program.
System.out.println(...)A command that prints output to the screen.

🧠 Important Java Rules

  • Case Sensitivity: Java is case-sensitive. Main, main, and MAIN are treated as different identifiers.
  • Filename = Class Name: The filename must exactly match the public class name. Example: MyApp.java must contain public class MyApp.
  • Every Statement Ends with ; (semicolon): Forgetting this causes compilation errors.

🛠 The main() Method – Your Program’s Launch Pad

public static void main(String[] args) {
  // your code goes here
}

You’ll see this method in every Java application. While it may look confusing now, here’s a simplified breakdown:

KeywordMeaning
publicMakes this method accessible to the Java runtime.
staticAllows this method to run without creating an object.
voidMeans the method doesn’t return any value.
String[] argsAccepts command-line arguments (you’ll learn about this later).

📌 Tip: You don’t need to memorize it all right now — just know that your program must have this method to run.


📤 Print Output with System.out.println()

System.out.println("Java is awesome!");
  • System – A built-in class in the java.lang package.
  • out – A static object (an instance of PrintStream) inside the System class.
  • println() – A method that prints a line of text and moves to the next line.

💬 Want to print without a new line? Use System.out.print() instead.


🧩 Syntax Summary

ConceptExample
Class Declarationpublic class HelloWorld { }
Main Methodpublic static void main(String[] args) { }
OutputSystem.out.println("Hello Java!");
Block of CodeEnclosed between { }
Statement EndEach line ends with ;

🌟 GoNimbus Bonus Tips

✅ Use indentation to improve code readability
✅ Start class names with uppercase (e.g., Student, Employee)
✅ Use meaningful names — avoid names like abc, xyz
✅ Write comments to explain your code logic


📘 Up Next: Java Variables and Data Types

Now that you understand how Java syntax works, it’s time to explore how to store and manipulate data using variables and data types.


Scroll to Top