CS 2nd Lec #04
CS 2nd Lec #04
Java naming convention is a rule to follow as you decide what to name your
identifiers such as class, package, variable, constant, method, etc.
But, it is not forced to follow. So, it is known as convention not rule. These
conventions are suggested by several Java communities.
All the classes, interfaces, packages, methods and fields of Java programming
language are given according to the Java naming convention. If you fail to
follow these conventions, it may generate confusion or erroneous code.
Class It should start with the uppercase letter. public class Employee
It should be a noun such as Color, Button, System, {
Thread, etc. //code snippet
Use appropriate words, instead of acronyms. }
Variable It should start with a lowercase letter such as id, class Employee
name. {
It should not start with the special characters like & // variable
(ampersand), $ (dollar), _ (underscore). int id;
If the name contains multiple words, start it with the //code snippet
lowercase letter followed by an uppercase letter such }
as firstName, lastName.
Avoid using one-character variables such as x, y, z.
Arithmetic (+, -, *, /, %)
Comparison (==, !=, <, >, <=, >=)
Increment (++, ++x) and Decrement (--, --x) (explained later)
Numeric Literals:
Numeric literals are the actual numbers you write in your code.
They can be integers (e.g., 10, -25) or floating-point numbers (e.g.,
3.14, -12.5e2 which represents -12.5 * 10^2).
Choose the appropriate data type based on the range and precision
required for your values.
Evaluating Expressions and Operator Precedence:
Expressions combine variables, literals, and operators to compute a
result.
Operator precedence determines the order in which operations
within an expression are evaluated. (e.g., multiplication and division
happen before addition and subtraction)
Use parentheses to override default precedence or clarify complex
expressions.
import java.util.Date;
Assignment:
What is a method in Java?
Method Declaration
Naming a Method
Types of Method
Predefined Method
User-defined Method