Basic Rules to Write a Java Program
1. Every Java program must be inside a class.
2. The filename must match the public class name (e.g., [Link] for class First).
3. The entry point of every Java program is the main method: public static void main(String[] args)
4. Java is case-sensitive (e.g., Main and main are different).
5. Curly braces { } are used to define blocks of code for classes, methods, loops, etc.
6. Each statement must end with a semicolon (;).
7. Comments can be written using: - // for single line - /* ... */ for multi-line - /** ... */ for
documentation
8. Variables must be declared with a type (e.g., int, String, double).
9. String values must be enclosed in double quotes (" ").
10. Character values must be enclosed in single quotes (' ').
11. Class names should start with uppercase letters by convention (e.g., Student, HelloWorld).
12. Method names should start with lowercase letters (e.g., display(), calculateSum()).
13. Indentation and spacing improve readability but are not enforced by the compiler.
14. Access modifiers (public, private, protected, default) control visibility of classes and members.
15. A Java program can have multiple classes, but only one public class per file.
16. The public class must have the same name as the filename.
17. Use 'new' keyword to create objects (e.g., Student s = new Student();).
18. The main method must be static because it is called without creating an object.
19. Compile the program using: javac [Link]
20. Run the program using: java ClassName (without .class extension).