Basic Java Syntax
Basic Java Syntax
It is particularly important to follow the appropriate syntax while writing java code, as we might get errors for the slightest mistake in our code.
The class name should be the same as that of the name of the java file. And each line of code must be written inside a class.
Example: program where file name and class name is different.
Output:
Example: program where file name and class name is same.
Output:
As we can see from both the examples that even a slightest change in the name of file and class name still gives us an error.
Each block of code is indented within the curly brackets{}.
Example: see how each block is indented inside the parent block
Each java file must contain a main method that is needed to execute a java file.
Example: java code without a main method gives an error
Output: