Java Variables and Data Types – Learn the Basics with Simple Examples
Java Programming

Java Variables and Data Types – Learn the Basics with Simple Examples

19 Aug, 2026 CCI Admin Java Programming
Back to All Blogs

Java Variables and Data Types – Learn the Basics with Simple Examples

Published: 19 Aug, 2026 | Author: CCI Admin | Category: Java

Variables and data types are some of the most important concepts for beginners learning Java. They help us store and work with different types of information in a program.

What is a Variable in Java?

A variable is a named memory location used to store data. Every variable in Java must have a specific data type.

int age = 20;
String name = "CCI Student";

Here, age stores a number and name stores text.

Types of Variables in Java

Java mainly has three types of variables:

  • Local Variables
  • Instance Variables
  • Static Variables

What are Data Types?

A data type tells Java what kind of value a variable can store. Java data types are mainly divided into two categories.

  • Primitive Data Types
  • Non-Primitive Data Types

Primitive Data Types

Primitive data types are used to store simple values such as numbers, characters, and true or false values.

  • byte – Small whole numbers
  • short – Whole numbers
  • int – Commonly used for whole numbers
  • long – Large whole numbers
  • float – Decimal numbers
  • double – More precise decimal numbers
  • char – A single character
  • boolean – true or false

Non-Primitive Data Types

Non-primitive data types are used to store objects and more complex data.

  • String
  • Array
  • Class
  • Interface

Simple Java Example

public class VariablesExample {
    public static void main(String[] args) {

        int age = 20;
        double price = 499.99;
        char grade = 'A';
        boolean isStudent = true;
        String name = "CCI Student";

        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Grade: " + grade);
        System.out.println("Price: " + price);
        System.out.println("Student: " + isStudent);
    }
}

Why are Variables and Data Types Important?

Understanding variables and data types helps beginners write better Java programs. Choosing the correct data type also helps programs handle data properly.

Tips for Beginners

  • Always declare variables before using them.
  • Use meaningful variable names.
  • Choose the correct data type.
  • Practice with simple Java programs.
  • Try changing values and observe the output.

Learn Java at CCI Computer Education, Pudukkottai

At CCI Computer Education, Pudukkottai, students can learn Java programming through simple explanations, coding exercises, and practical projects.

Start with the fundamentals, practice regularly, and gradually move toward object-oriented programming and real-world Java projects.

Conclusion

Variables and data types are the foundation of Java programming. Once you understand how to declare variables and store different types of values, you can start building more useful Java programs.

Keep practicing with simple examples and continue learning step by step. Strong fundamentals can help you build confidence in Java programming and prepare for future IT opportunities.

What's Next?

In our next Java tutorial, we will learn about Java Operators and how to perform calculations and comparisons in Java programs.


Call: 98427 97945  |  Website: ccipudukkottai.com  |  WhatsApp Channel: Join Now

Share: Facebook | WhatsApp | Twitter