It seems like you want to continue discussing the previous chapter where we created a Java file named Main.java
and used the code to print "Hello World" to the screen. Here's a recap of the code snippet we used:
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Example explained
-
Every line of code in Java must be inside a class:
- In Java, code is organized into classes, which serve as blueprints for objects. All code must be contained within a class, even if it's just a simple program.
-
Class names should start with an uppercase letter:
- By convention, class names in Java start with an uppercase letter. This makes it easier to distinguish classes from other identifiers like variables and methods.
-
Java is case-sensitive:
- Java treats uppercase and lowercase letters as distinct. For example, "MyClass" and "myclass" would be considered different identifiers in Java.
-
File name must match the class name:
- When saving a Java file, the filename must match the name of the class declared in the file. Additionally, the file should have a ".java" extension to indicate that it contains Java source code.
Hello World
Practice Excercise Practice now