Java Arrays — தமிழ்

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

Java Arrays

Store related values in a fixed-size sequence.

Step-by-step explanationsRunnable JavaPractice + answer

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

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

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

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

An array has a fixed length after creation. Elements use zero-based indexes, so valid indexes range from 0 through length – 1. Changing one element is different from resizing the array.

02 / Step by step

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

Java Arrays: ஓர் அறிமுகம்

Array என்பது ஒரே type-ஓட multiple values-ஐ ஒரே variable-ல store பண்றதுக்கு use ஆகுது.

Array declare பண்றதுக்கு square brackets use பண்றோம்:

Array Elements Access பண்றது

Index number use பண்ணி element access பண்ணலாம் — index 0-ல ஆரம்பிக்கும்:

Array Length

Array-ல எத்தனை elements இருக்குன்னு தெரிஞ்சுக்க length property use பண்றோம்:

Array Loop

Array-ல உள்ள எல்லா elements-ஐயும் loop-ல access பண்ணலாம்:

Array index 0-ல ஆரம்பிக்கும் — 5 elements இருந்தா index 0 முதல் 4 வரை இருக்கும். 5-ல try பண்ணா ArrayIndexOutOfBoundsException வரும்!

Java reference fragmentJAVA
int[] nums = {10, 20, 30, 40, 50};
System.out.println(nums.length);      // 5
System.out.println(nums[2]);          // 30
nums[2] = 99;

for (int n : nums) System.out.print(n + " ");  // 10 20 99 40 50

java.util.Arrays.sort(nums);
System.out.println(java.util.Arrays.toString(nums));  // [10, 20, 40, 50, 99]

int[][] grid = {{1,2,3},{4,5,6},{7,8,9}};
System.out.println(grid[1][2]);  // 6

Java-வில் array-ன் default value என்ன (int array-க்கு)?

  1. null
  2. 0
  3. undefined
  4. -1
Reveal answer / விடை

0

Java-வில் int array declare செய்தால் எல்லா elements-உம் automatically `0`-ஆக initialize ஆகும். boolean arrays `false`, object arrays `null`-ஆக initialize ஆகும்.

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 {
        int[] scores = {10, 20, 30};
        scores[1] = 25;
        System.out.println(scores.length);
        for (int score : scores) {
            System.out.println(score);
        }
    }
}
Predict first. Then reveal the expected output / வெளியீடு
3
10
25
30

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

Add a fourth value to the initializer and run the same loop.

Reveal the answer and reasoning / விடை

The length becomes 4 and the for-each loop visits all four values.

தவிர்க்க வேண்டிய தவறு: The last valid index is length – 1. Accessing scores[scores.length] throws an exception.

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

  • 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.