Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Q.A Academy
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Java

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 
View Categories
  • Home
  • Tutorials
  • Java
  • Java
  • What is Java Variable?

What is Java Variable?

What is Java Variable?

In Java, a variable is a container that holds data which can be changed during the execution of a program. Each variable in Java has a specific data type that determines the type and size of data it can hold. Variables are essential for storing data, manipulating it, and passing it within the program.

Declaration and Initialization #

To use a variable in Java, you must first declare it and then optionally initialize it with a value. The general syntax for declaring a variable is:

dataType variableName;

And for initializing a variable:

dataType variableName = value;

Example #

Let’s look at an example to understand variables in Java better:

public class Main {
    public static void main(String[] args) {
        // Declaration of variables
        int age;
        double salary;
        String name;

        // Initialization of variables
        age = 25;
        salary = 50000.50;
        name = "John Doe";

        // Output the values of the variables
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Salary: " + salary);
    }
}

Explanation #

  1. int age;
  • This declares an integer variable named age.

2. double salary;

  • This declares a double variable named salary, which can hold decimal values.

3. String name;

  • This declares a String variable named name, which can hold a sequence of characters.

After declaring the variables, they are initialized with values:

  1. age = 25;
  • This assigns the integer value 25 to the variable age.

2. salary = 50000.50;

  • This assigns the double value 50000.50 to the variable salary.

3. name = “John Doe”;

  • This assigns the string value “John Doe” to the variable name.

Finally, the values of the variables are printed to the console using System.out.println.

Java
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
What is Java Comments ?Variable Naming convention
Table of Contents
  • Declaration and Initialization
  • Example
  • Explanation
© Copyright [2018-2025]. All Rights Reserved.