This content originally appeared on DEV Community and was authored by Arun
**Rules for identifiers in java
✓ In Java, an identifier is the name you give to classes, methods, variables, interfaces, etc.
Rules for Identifiers in Java:
- Allowed characters
Letters (A-Z, a-z)
Digits (0-9)
Underscore (_)
Dollar sign ($)
Example: myVar, student_name, $_count
Must not begin with a digit
Invalid – 1number
Valid – number1No special characters or spaces (except _ and $)
Invalid – my-name, first name
Valid – myName, first_nameCannot be a reserved keyword (like int, class, static, if)
Invalid: class
Valid: classNameCase-sensitive
Student and student are different identifiersNo length limit:
✓ You can make identifiers very long, but short and meaningful names are recommended.Convention rules (not enforced by compiler but recommended):
✓ Variables & methods → start with a lowercase letter (studentAge, calculateSum())
✓ Classes & interfaces → start with an uppercase letter (Student, CarDetails)
✓ Constants → written in UPPERCASE with underscores (MAX_VALUE, PI)
**Example Program
class StudentDetails {
int studentAge;
String studentName;
void displayInfo()
{
System.out.println(studentName + " is " + studentAge + " years old.");
}
}
- Declaration (Declarisation) ✓✓ Declaration is the process of introducing a variable in a program by specifying its data type and name. At this point, memory is reserved for the variable, but it does not yet have a value (unless given a default).
Syntax:
datatype variableName;
Example:
int age; // declaration
String name; // declaration
Here, age is declared as an integer, name as a string.
- Initialization ✓✓ Initialization means assigning an initial value to a declared variable. ✓✓ It can happen at the time of declaration or later in the code.
Syntax:
datatype variableName = value;
Example:
int age = 20; // declaration + initialization
String name = “Arun”; // initialized with value
Here, age is initialized with 20, name with “Arun”.
- Compiler and Interpreter
Compiler
Translates the entire program (source code) into machine code at once.
Execution is faster.
Example: C, C++ use compilers.
Interpreter
Translates the program line by line and executes it immediately.
Execution is slower.
Example: Python, Java (partly) use interpreters.
Java uses both:
Java code is compiled by javac (compiler) into bytecode.
Then the JVM (Java Virtual Machine) interprets/executes the bytecode.
- Class and Object
Class → A blueprint/template that defines properties and behaviors.
Object → A real-world entity created from the class.
Example:
class Car {
String color;
void drive() {
System.out.println(“Car is driving”);
}
}
public class Main {
public static void main(String[] args) {
Car myCar = new Car(); // Object creation
myCar.color = “Red”;
myCar.drive();
}
}
- ASCII and Unicode
ASCII (American Standard Code for Information Interchange)
7-bit code (128 characters).
Covers English letters, digits, symbols.
Example: ‘A’ = 65, ‘a’ = 97.
Unicode
16-bit or more (65,536+ characters).
Supports all languages (English, Tamil, Hindi, Chinese, etc.).
Java uses Unicode for characters.
**
This content originally appeared on DEV Community and was authored by Arun