Premium Only Content

#5 Variables in JAVA | Skyhighes | Lecture 5
Here's a description of variables in Java, incorporating images for clarity:
What are Variables?
Think of variables as named containers that store data values during program execution.
They're like labeled boxes in your program's memory, holding information that can be used and manipulated later.
Image of labeled boxes representing variables in memoryOpens in a new window
w3.cs.jmu.edu
labeled boxes representing variables in memory
Declaring Variables:
You must declare a variable before using it. This involves:
Specifying its data type: This tells Java what kind of value the variable can hold (e.g., number, text, true/false).
Giving it a name: Choose a meaningful name that reflects its purpose.
Example:
Java
int age = 25; // Declares a variable named "age" of type "int" and assigns the value 25
String name = "Alice"; // Declares a variable named "name" of type "String" and assigns the value "Alice"
Use code with caution. Learn more
Data Types:
Java has two main types of data types:
Primitive data types: Hold simple values directly in memory.
Examples: int, double, char, boolean, float, byte, short, long
Reference data types: Hold references to objects in memory.
Examples: String, Array, Class
Assigning Values:
You can assign values to variables using the = operator.
Example: int score = 95;
Using Variables:
Once declared and assigned, you can use variables in your code to perform calculations, create output, make decisions, and more.
Example: System.out.println("Your age is: " + age);
Key Points:
Case sensitivity: Variable names are case-sensitive (age is different from Age).
Naming conventions: Use descriptive names to make your code readable (e.g., firstName instead of x).
Scope: Variables have a scope, which determines where they can be accessed within your code.
Types cannot change: Once declared, a variable's data type cannot be changed.
Image of common primitive data types in Java
Remember, variables are essential building blocks for storing and managing data in your Java programs. Choose appropriate data types, meaningful names, and consider variable scope to write clear and effective code.
-
LIVE
LFA TV
2 hours agoLFA TV ALL DAY STREAM - TUESDAY 9/16/25
18,627 watching -
LIVE
JULIE GREEN MINISTRIES
1 hour agoLIVE WITH JULIE
18,909 watching -
LIVE
Game On!
21 hours ago $2.15 earnedJoe Burrow And The Bengals Season IS OVER Despite Being 2-0!
3,146 watching -
6:32
WhaddoYouMeme
16 hours ago $1.77 earnedChristians, These Reactions Should Disturb You
11.3K24 -
9:59
Clownfish TV
14 hours agoWarner Bros and Paramount are MERGING?! | Clownfish TV
2.35K2 -
19:19
World2Briggs
1 day ago $0.59 earnedTop 10 Amazing States With The Lowest Taxes.
12K1 -
LIVE
BEK TV
23 hours agoTrent Loos in the Morning - 9/16/2025
297 watching -
LIVE
The Bubba Army
22 hours agoDid Charlie Kirk's Killer, Confess On Discord? - Bubba the Love Sponge® Show | 9/16/25
2,262 watching -
8:41
Zoufry
1 day agoInside The Cartels Training Camps for Assassins
16.2K1 -
12:37
itsSeanDaniel
1 day agoFake Republican REFUSES to Stand Up for Charlie Kirk
12.1K35