Java Variables: Types, Data Types, and Naming Rules

#javaForAutomationDays _Day 4, 🔹What Are Variables in Java? Variables are memory locations used to store values that can change during the execution of a program. Every variable in Java has a type, a name, and a value. 🔹 Types of Variables in Java 1- Local Variables Declared inside methods or blocks and only accessible within that specific scope. They must be initialized before use. 2- Instance Variables Declared inside a class but outside any method. Each object has its own copy, and they receive default values if not initialized. 3- Static Variables (Class Variables) Declared using the keyword static and shared across all objects of the class, meaning there is only one shared copy. 🔹 Data Types in Java Java provides primitive data types such as: int, long, byte, short for whole numbers float, double for decimal numbers char for characters boolean for true/false values The most commonly used non-primitive type is String. 🔹 Quick Examples int age = 20; double salary = 4500.75; char grade = ‘A’; boolean active = true; String language = “Java”; 🔹 Variable Naming Rules A variable name must start with a letter, $, or _, and cannot start with a number. Names are case-sensitive, and it’s recommended to use camelCase with meaningful names. 🔹 Why Are Variables Important? They allow programs to store and manage data dynamically, making the code flexible, reusable, readable, and easier to maintain. #java #softwaretesting #programming #Techlearnin

  • text

To view or add a comment, sign in

Explore content categories