Java Basics: Variables, Data Types, and Operators

Java is a powerful and versatile programming language used in web development, mobile applications, and enterprise systems. To begin your journey in Java, it’s essential to understand the basic building blocks: variables, data types, and operators.

🔹 Variables in Java

Variables are containers that store data values. In Java, each variable must be declared with a data type before it is used.

Syntax:

int age = 25;

String name = "John";

Here, int is the data type, age is the variable name, and 25 is the value. Java is a statically-typed language, meaning the data type must be specified at the time of declaration.

🔹 Data Types in Java

Java supports two categories of data types:

1. Primitive Data Types

These are the most basic data types and are predefined by Java:

int – integer numbers (e.g., 10, -5)

double – decimal numbers (e.g., 3.14, -0.5)

char – single character (e.g., 'A', 'z')

boolean – true or false

byte, short, long, float – used for memory optimization in specific cases

2. Non-Primitive (Reference) Data Types

These are objects and include:

String

Arrays

Classes

Interfaces

Example:

String city = "Hyderabad";

🔹 Operators in Java

Operators are used to perform operations on variables and values. Java has several types:

1. Arithmetic Operators

Used for mathematical operations:

+ (addition)

- (subtraction)

* (multiplication)

/ (division)

% (modulus)

2. Relational (Comparison) Operators

Used to compare values:

== (equal to)

!= (not equal to)

> , <, >=, <=

3. Logical Operators

Used for boolean logic:

&& (AND)

|| (OR)

! (NOT)

4. Assignment Operators

Used to assign values:

= , +=, -=, *=, /=

Example:

int a = 10;

int b = 5;

System.out.println(a + b); // Output: 15

Conclusion

Understanding variables, data types, and operators is essential for writing basic Java programs. These elements form the foundation of Java logic and structure. Once you're comfortable with these, you can move on to control statements, loops, and object-oriented programming concepts.

Start practicing now—Java gets easier the more you code!

Learn  Full Stack Java Training

Introduction to Java and Full Stack Development

Setting Up Java Development Environment (JDK, IntelliJ, Eclipse)

Visit Our Quality Thought Training Institute 


Comments

Popular posts from this blog

Understanding the useEffect Hook

What Is Tosca? A Beginner’s Guide

Exception Handling in Java