Posts

Showing posts from September, 2025

OBJECT ORIENTED PROGRAMMING THROUGH JAVA : Unit - 3 : Topic - 1 : Arrays

Image
1. Introduction to Arrays Definition An array in Java is a collection of variables of the same data type stored at contiguous memory locations . It allows us to store multiple values in a single variable, instead of declaring separate variables for each value. Arrays are fixed-size (the size must be defined at the time of creation). Each element in an array is accessed using an index . Array indexing in Java starts from 0 . Why Arrays? To handle large amounts of data efficiently. Easy traversal using loops. Better performance as elements are stored in continuous memory. Key features of Arrays Store Primitives and Objects: Java arrays can hold both primitive types (like int, char, boolean, etc.) and objects (like String, Integer, etc.) Contiguous Memory Allocation When we use arrays of primitive types, the elements are stored in contiguous locations. For non primitive types, references of items are stored at contiguous locations. Zero-based Indexing: The first e...