Java Variables & Basics — தமிழ்

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 06 / 50 · தமிழ்

Java Variables & Basics

Name a value. Use it with purpose.

Step-by-step explanationsRunnable JavaPractice + answer

முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.

இந்தப் பாடத்தில்…

  • Explain the key idea behind Variables.
  • Read and run a complete example, then predict what changes.
  • Recognize the topic-specific mistake discussed below.
01 / The concept

அடிப்படையைப் புரிந்துகொள்ளுங்கள்

A variable associates a name and type with a value. Start with meaningful names such as lessonsCompleted. Assigning a new value changes what the variable holds; it does not change its declared type. Local variables must be assigned before you read them.

02 / Step by step

விரிவான விளக்கங்கள்

Variables (மாறிலிகள்) என்றால் என்ன?

Variables என்பது தரவுகளை (Data values) சேமித்து வைப்பதற்கான பெட்டிகள் (Containers) போன்றது. Java-வில் ஒரு Variable-ஐ உருவாக்கும்போது, அது எத்தகைய தரவைச் சேமிக்கப் போகிறது (Data Type) என்பதை முன்கூட்டியே குறிப்பிட வேண்டும்.

Variable-ஐ உருவாக்குவது (Declaration) எப்படி?

  • முதலில் ஒரு Type-ஐ தேர்ந்தெடுக்கவும் (உதா: int, String).
  • Variable-க்கு ஒரு பெயரை வழங்கவும் (உதா: age, userName).
  • விருப்பப்பட்டால், = குறியீட்டைப் பயன்படுத்தி ஒரு மதிப்பை (Value) assign செய்யவும்.

Code anatomy / கோடின் விளக்கம்

CodeMeaning
intData type: இது முழு எண்களை (integer) சேமிக்கும் என்பதை Java-விடம் கூறுகிறது.
userAgeVariable Name: தரவை அடையாளம் காணப் பயன்படும் பெயர்.
=Assignment Operator: வலதுபுறம் உள்ள மதிப்பை, இடதுபுறம் உள்ள variable-ல் சேமிக்கிறது.
25Value: Variable-ல் சேமிக்கப்படும் தரவு (தகவல்).
;Statement Terminator: ஒவ்வொரு Java statement-உம் Semicolon-ல் முடிவடைய வேண்டும்.

Variables-க்கு பெயரிடும்போது எப்போதும் camelCase முறையைப் பின்பற்றுங்கள் (உதா: employeeSalary, firstName). மேலும், x அல்லது y போன்ற பெயர்களைத் தவிர்த்து, தரவின் தன்மையைப் பிரதிபலிக்கும் அர்த்தமுள்ள பெயர்களை (Meaningful names) வழங்குவது தலைசிறந்த மென்பொருள் பொறியாளரின் (Good Software Engineer) அடையாளமாகும்.

Java reference fragmentJAVA
// Declare and Initialize
String developerName = "Sathish";
int experienceYears = 8;
double hourlyRate = 45.50;
boolean isAvailable = true;

// Java 10+ Feature: Local Variable Type Inference (var)
var framework = "Spring Boot";  // Java தானாகவே இதை String என உணர்ந்து கொள்ளும்

System.out.println(developerName + " uses " + framework);

Interview Question: ஒரு Variable-க்கு வழங்கப்பட்ட மதிப்பை, ப்ரோக்ராம் முழுவதும் மாற்ற முடியாதபடி (Constant-ஆக) பாதுகாக்க எந்த Keyword பயன்படுத்தப்படுகிறது?

  1. static
  2. const
  3. final
  4. immutable
Reveal answer / விடை

final

சரியான விடை! `final` keyword-ஐ பயன்படுத்தினால் அந்த variable-க்கான மதிப்பை பின்பு மாற்ற முடியாது. (உதா: `final double PI = 3.14;`). Java-வில் `const` என்ற வார்த்தை பயன்பாட்டில் இல்லை.

03 / Read and predict

முழுமையான உதாரணம்

This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.

Main.java · complete runnable exampleJAVA
public class Main {
    public static void main(String[] args) throws Exception {
        String learner = "Kavi";
        int lessonsCompleted = 2;
        lessonsCompleted = lessonsCompleted + 1;
        System.out.println(learner + " completed " + lessonsCompleted + " lessons.");
    }
}
Predict first. Then reveal the expected output / வெளியீடு
Kavi completed 3 lessons.

The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.

04 / Learn by changing

Change it. Run it. Understand it.

Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.

05 / Your turn

நீங்களே முயற்சி செய்யுங்கள்

Practice challenge

Start the count at 5 and increase it by 2.

Reveal the answer and reasoning / விடை

The final count becomes 7. Change the initialization and the value added in the assignment.

தவிர்க்க வேண்டிய தவறு: The = symbol assigns a value. It does not ask whether two values are equal.

பாடத்தின் சுருக்கம்

  • Explain the example without reading the output first.
  • Make the change requested in the practice task.
  • Describe why the result changed—or why compilation failed.

Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.

Coding Tamilan · Understand the idea. Try the code. Build the habit.