Java Variables and Data Types, Variable Scope and Lifetime

0.0(0)
studied byStudied by 1 person
0.0(0)
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/21

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:01 AM on 1/31/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

22 Terms

1
New cards

Variables

Act as containers to store data that can be referenced and manipulated in a program. Each has a specific type, determining the kind of data it can hold.

2
New cards

Declaring a variable

int age;
double salary;
String name;
char middleName;

It specify the data type, followed by the variable name.

3
New cards

Variable Initialization

int age = 19;
double salary = 20000.9876;
String name = "Grrrr";
char middleName = 'G';

Variables are declared or later in the code

4
New cards

Statically-typed Language

Java is a _____________, meaning each variable must have a type defined at compile time.

5
New cards

Primitive Data Types
Reference Data Types

Two primary data types of Java.

6
New cards

byte
short
int
long
float
double
char
boolean

Primitive Data Types

7
New cards

byte

1 byte which are used for small numbers that ranges from -128 to 127.

8
New cards

short

2 bytes which is suitable for slightly larger numbers that ranges from -32,768 to 32,767.

9
New cards

int

4 bytes which commonly used integer type that ranges from -231 to 231-1.

10
New cards

long

long bigNumber = 12345678L;

8 bytes which uses for a larger integer type that uses L suffix for literals.

11
New cards

float

float pi=3.14F;

4 bytes which is a single-precision floating point that uses F suffix.

12
New cards

double

8 bytes which is a double-precision floating point and default for decimal values.

13
New cards

char

2 bytes which stores a single Unicode character.

14
New cards

boolean

1 byte which holds true or false.

15
New cards

Reference Data Types

These include classes, interfaces, and arrays, such as String, arrays (int[]), and custom classes. Unlike primitives, they store references to objects rather than the object itself.

16
New cards

Scope

The section of the code where a variable can be accessed.

17
New cards

Local Variables

Declared within a method and accessible only within that method.

18
New cards

Instance Variables (Fields)

Declared within a class but outside any method. They belong to the instance of the class.

19
New cards

Class Variables (Static Fields)

Declared with the static keyword and shared across all instances of the class.

20
New cards

Lifetime

The period during which a variable occupies memory. Local variables are deleted after method execution, while instance and class variables persist as long as the object or class exists

21
New cards

Deleted

Lifetime is when a variable occupies memory. Local variables are ______ after method execution, while instance and class variables persist as long as the object or class exists

22
New cards

Persist

Lifetime is when a variable occupies memory. Local variables are deleted after method execution, while instance and class variables _______ as long as the object or class exists.