Fundamentals of Java
Identifiers, Keywords, Data Types,
Variables, Reserved Words, and
Operators
Identifiers in Java
• Definition: Names given to variables, methods, classes, objects, etc.
• Rules:
• • Must begin with a letter, underscore (_), or dollar sign ($)
• • Can contain letters, digits, underscores, dollar signs
• • Cannot use keywords as identifiers
• • Case-sensitive (Name and name are different)
• Examples: age, studentName, _value, $salary
• Invalid: 2name, class, my name
Keywords in Java
• Definition: Predefined reserved words in Java with special meaning
• Cannot be used as identifiers
• Examples: class, public, static, void, int, if, else, switch, while, for, return
• Code Example:
• public class Example {
• int number;
• void display() { System.out.println("Hello Java"); }
• }
Data Types in Java
• Definition: Data types specify the type and size of data a variable can hold
• Primitive Data Types (8): byte, short, int, long, float, double, char, boolean
• Non-Primitive Data Types: String, Arrays, Classes, Objects
• Examples:
• int age = 21;
• float price = 99.5f;
• char grade = 'A';
• boolean isPass = true;
• String name = "Pradnya";
Variables in Java
• Definition: A container for storing data values
• Declared with a data type, value can change during execution
• Syntax: dataType variableName = value;
• Example: int number = 10; String city = "Kolhapur";
• Types of Variables:
• • Local variable: Declared inside methods
• • Instance variable: Inside class but outside methods
• • Static variable: Declared with static keyword, shared across objects
Reserved Words in Java
• Definition: Words reserved by Java for its syntax
• Includes: Keywords + Literals + Special Identifiers
• Examples:
• • Keywords: class, if, else, static
• • Literals: true, false, null
• • Special identifiers: this, super
• Code Example: boolean flag = true; String name = null;
Operators in Java
• Definition: Symbols used to perform operations on variables and values
• Types:
• • Arithmetic Operators (+, -, *, /, %)
• • Relational Operators (==, !=, >, <, >=, <=)
• • Logical Operators (&&, ||, !)
• • Assignment Operators (=, +=, -=, *=, /=)
• • Unary Operators (++ --)
• • Ternary Operator (?:)
• Code Example:
• int a = 10, b = 5;
• System.out.println(a + b); // 15
• System.out.println(a > b); // true
• System.out.println(a == 10 && b == 5); // true
• a += 5; // 15