DMCA.com Protection Status Java Programming Lesson 2 | Variables & Data Types Explained - ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer

Header Ads

Java Programming Lesson 2 | Variables & Data Types Explained

LESSON - 2 VERIABLES AND DATA TYPES


Welcome to Lesson-2: Variables & Data Types 👨‍💻✨


📘 Lesson 2 — Variables & Data Types

✅ What is a Variable?

A variable is a container that stores data.

Example:
int age = 20; → age stores number 20

📌 Format:

dataType variableName = value;

✅ Java Data Types

Java has 2 categories:

CategoryTypesExamples
Primitive      8 types        int, float, char, boolean, long, double, byte, short
Non-Primitive    String, Array, Class        "Hello", {1,2,3}

✅ Primitive Data Types (Most Used)

TypeSize           ExampleUse
int   4 bytes              10        Whole numbers
float   4 bytes             5.5f        Decimal (less accurate)
double   8 bytes             8.99        Decimal (high accuracy)
char   2 bytes              'A'        Single character
boolean   1 bit          true/false        Conditions
long   8 bytes         99999999L        Big whole numbers

📌 Always remember:
float → add f
long → add L


✅ Practical Example

public class VariablesExample { public static void main(String[] args) { int age = 21; float height = 5.7f; char grade = 'A'; boolean isStudent = true; String name = "Jitu Hasan"; System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Height: " + height); System.out.println("Grade: " + grade); System.out.println("Is Student: " + isStudent); } }

✅ Output:

Name: Jitu Hasan Age: 21 Height: 5.7 Grade: A Is Student: true

✅ Naming Rules (Important Interview Question)

✔ Allowed: letters, numbers, _, $
✔ Must NOT start with a number
✔ Case-sensitive (age ≠ Age)
✔ No spaces

✅ Good:

studentName, totalMarks, age2

❌ Bad:

2amount, student name, class

✅ Mini Exercise (Do it Now ✅)

Write a program using variables to print:

📌 Your Name
📌 Your Age
📌 Your Country
📌 Your Favorite Programming Language

Example Output:

My Name: _____ Age: _____ Country: _____ Favorite Language: _____

👉 Reply here with your code & output
I will check and improve it ✅


🎯 Quick Quiz

1️⃣ Which is a non-primitive data type?
A) int
B) String
C) boolean

2️⃣ Which is correct?
A) float x = 5.5;
B) float x = 5.5f;

Reply like: 1 → ?, 2 → ?


✅ Lesson-2 Completed!

Tell me when you're ready for:

Lesson-3: Operators (Arithmetic, Logical, Relational)

Waiting for your answers + exercise 👇😊


NEXT PARTLesson-3: Operators

No comments

Thank You For Visit My Website.
I Will Contact As Soon As Possible.

Theme images by 5ugarless. Powered by Blogger.