Variables and Constants

Variables and Constants

Variables and Constants

Variables and Constants

Published by: Anil K. Panta

Variables

Used to store data values in memory.

Types of Variables:

  1. Class Variables (static) – one copy for all objects.

  2. Instance Variables – different for each object.

  3. Local Variables – exist only within a method or block.

Constants

  • Value cannot be changed after declaration.

  • Declared using static final keywords.

Example:

static final double PI = 3.14159;

Data Types in Java

1. Primitive Data Types

  • byte, short, int, long

  • float, double

  • char, boolean

2. Non-Primitive Data Types

  • String – Sequence of characters (immutable).

Array – Fixed-size collection of elements of the same type.

We will get back to you via email or phone call