Skip to main content

Posts

Showing posts from September, 2025

Java Variables

   Java Variables A  variable  in Java is a container that holds data during program execution. Each variable has a  name, data type, and value . 1.  Declaration and Initialization Before a variable can be used, it must be declared, which involves specifying its data type and a unique name. int age = 25;       // declaration + initialization String name = "Test"; double salary;      // only declaration salary = 500.50;  // initialization later 2.  Types of Variables Local Variable  → Variables declared inside a method/block/constructor. Instance Variable  → Variables declared inside a class but outside methods (object-specific). Static Variable  → Variables declared with  static , shared across all objects. class Employee {     String name;          // instance variable     static String company = "XYZ Ltd"; // static variable     voi...