Comment styles
Description
Java supports single-line and block comments.
Explanation
Use comments sparingly and keep them accurate.
Example
// A learner's final score
/* This can span lines */← Chapter 2 — Core Syntax & Data
mixed
Comments explain intent to people reading code. The compiler ignores them, so they should clarify why a choice exists rather than repeat an obvious statement.
Names should describe their purpose. Java convention uses camelCase for variables and methods, PascalCase for classes, and uppercase for constants.
Java supports single-line and block comments.
Use comments sparingly and keep them accurate.
// A learner's final score
/* This can span lines */Names begin with a letter, underscore, or dollar sign.
Spaces, keywords, and most punctuation cannot appear in identifiers.
int finalScore = 88;A good name reduces the need for comments. For example, passingScore is easier to understand than x, especially when a program grows.
public class NamingDemo {
public static void main(String[] args) {
// Store Rohan's result.
int finalScore = 88;
System.out.println(finalScore);
}
}