0% found this document useful (0 votes)
3 views1 page

Java Basic Rules

This document outlines the basic rules for writing a Java program, emphasizing that every program must be inside a class and the filename must match the public class name. It details the structure of a Java program, including the main method, case sensitivity, and the use of curly braces and semicolons. Additionally, it covers naming conventions, variable declarations, comments, access modifiers, and the process for compiling and running a Java program.

Uploaded by

Aswin Gouda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java Basic Rules

This document outlines the basic rules for writing a Java program, emphasizing that every program must be inside a class and the filename must match the public class name. It details the structure of a Java program, including the main method, case sensitivity, and the use of curly braces and semicolons. Additionally, it covers naming conventions, variable declarations, comments, access modifiers, and the process for compiling and running a Java program.

Uploaded by

Aswin Gouda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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).

You might also like