Java Fundamentals

Classpath, Identifiers, Data Types, Variables, Constants, Statements, Blocks & Expressions

Prepared By Krishna Srikanth

1. CLASSPATH

CLASSPATH is an environment variable which tells the Java compiler and the JVM where to look for Java class files.

Key idea: CLASSPATH helps Java locate compiled class files and other required classes during compilation and execution.

2. Identifier

Identifiers are programmer-designed tokens. They are used for naming:

Classes

Methods

Variables

Objects

Labels

Packages

Interfaces

3. Identifier Rules

  1. Identifiers can contain alphabets, digits, underscore (_), and dollar sign ($) characters.
  2. An identifier must not begin with a digit.
  3. 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.

Remember: A data type determines what kind of value a variable can store and the amount of memory associated with that value.

5. Primitive Data Types

The source organizes Java primitive data types into integer, real, character and other categories.

CategoryRepresentationBytesDefault Value
Integerint40
Integershort20
Integerlong80
Realfloat40.0f
Realdouble80.0d
Characterchar2\u0000
Otherbyte10
Otherboolean1false
Object referenceReferencenull
Note: The table preserves the representation, byte sizes and default values as presented in the source PDF.

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.

Important: Every statement must end with a semicolon (;).

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);
}
Key idea: A block is enclosed between { 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
PartRole
a, b, cOperands
+, *Operators
a + b * cExpression

12. Quick Revision

TopicKey Point
CLASSPATHEnvironment variable that tells the Java compiler and JVM where to find Java class files.
IdentifierProgrammer-designed name for classes, methods, variables, objects, labels, packages and interfaces.
Identifier RuleCan contain letters, digits, underscore and dollar sign, but cannot start with a digit; case matters.
Data TypeSpecifies the size and type of values that can be stored.
Primitive Data Typesint, short, long, float, double, char, byte and boolean.
VariableAn identifier whose value can change during program execution.
ConstantAn identifier whose value cannot change during program execution.
Variable DeclarationData type var_name; or Data type var_name = value;
StatementA complete unit of execution; statements end with a semicolon.
BlockGroup of zero or more statements between balanced braces.
ExpressionCollection of operators and operands.