1. CLASSPATH
CLASSPATH is an environment variable which tells the Java compiler and the JVM where to look for Java class files.
2. Identifier
Identifiers are programmer-designed tokens. They are used for naming:
Classes
Methods
Variables
Objects
Labels
Packages
Interfaces
3. Identifier Rules
- Identifiers can contain alphabets, digits, underscore (
_), and dollar sign ($) characters. - An identifier must not begin with a digit.
- Uppercase and lowercase letters are distinct.
Examples
studentName student_name student1 $amount _count
4. Data Type
A data type specifies the size and type of values that can be stored. It is an attribute that tells the computer something about the kind of data being represented.
5. Primitive Data Types
The source organizes Java primitive data types into integer, real, character and other categories.
| Category | Representation | Bytes | Default Value |
|---|---|---|---|
| Integer | int | 4 | 0 |
| Integer | short | 2 | 0 |
| Integer | long | 8 | 0 |
| Real | float | 4 | 0.0f |
| Real | double | 8 | 0.0d |
| Character | char | 2 | \u0000 |
| Other | byte | 1 | 0 |
| Other | boolean | 1 | false |
| Object reference | Reference | — | null |
6. Variable
An identifier whose value can change during the execution of a program is called a variable.
Example
int age = 20; age = 21;
Here, age is a variable because its value can change during program execution.
7. Constant
An identifier whose value cannot change during the execution of a program is called a constant.
Example
final int MAX = 100;
The value of MAX cannot be reassigned after initialization.
8. How to Declare a Variable
The source gives two basic forms of variable declaration.
Data type var_name; Data type var_name = value;
Examples
int number; int number = 10; String name = "Java";
9. Statement
Statements are roughly equivalent to sentences in natural languages. A statement forms a complete unit of execution.
;).Examples
int a = 10; a = a + 5; System.out.println(a);
10. Block
A block is a group of zero or more statements between balanced braces and can be used anywhere.
{
int a = 10;
int b = 20;
System.out.println(a + b);
}
{ and } and groups statements into a single unit.11. Expression
An expression is a collection of operators and operands.
An operand can be a variable, constant or method invocation.
Example
a + b * c
| Part | Role |
|---|---|
| a, b, c | Operands |
| +, * | Operators |
| a + b * c | Expression |
12. Quick Revision
| Topic | Key Point |
|---|---|
| CLASSPATH | Environment variable that tells the Java compiler and JVM where to find Java class files. |
| Identifier | Programmer-designed name for classes, methods, variables, objects, labels, packages and interfaces. |
| Identifier Rule | Can contain letters, digits, underscore and dollar sign, but cannot start with a digit; case matters. |
| Data Type | Specifies the size and type of values that can be stored. |
| Primitive Data Types | int, short, long, float, double, char, byte and boolean. |
| Variable | An identifier whose value can change during program execution. |
| Constant | An identifier whose value cannot change during program execution. |
| Variable Declaration | Data type var_name; or Data type var_name = value; |
| Statement | A complete unit of execution; statements end with a semicolon. |
| Block | Group of zero or more statements between balanced braces. |
| Expression | Collection of operators and operands. |