Java Syntax and Basic Structure

Chapter 3: Java Syntax and Basic Structure 3.1 Structure of a Java Program A basic Java program follows a specific structure that includes: Class definition main() method (entry point) Statements inside curly braces Example: Public class MyProgram { public static void main(String[] args) { System.out.println("Java is powerful!"); } } 3.2 Components of a Java Program 3.3 Java Syntax Rules Java is case-sensitive: Main ≠ main File name must match the class name (for public class) The main() method must be exactly: public static void main(String[] args) 3.4 Java Comments Comments are used to make code easier to understand. Single-line comment: // This is a single-line comment Multi-line comment: /* This is a multi-line comment */ Documentation comment (for APIs): /** * This class prints Hello World. */ 3.5 Printing Output in Java We use System.out.println() or System.out.print() to show output. ➤ Example: System.out.println("Welcome!"); System.out.print("Hello ...