0% found this document useful (0 votes)
17 views19 pages

Day10 Arrays

Uploaded by

mohamedjaaved19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views19 pages

Day10 Arrays

Uploaded by

mohamedjaaved19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Arrays

TNS India Foundation | ‹#›


Partners in Economic Transformation
Recap

• Polymorphism- one thing many forms

TNS India Foundation | ‹#›


Partners in Economic Transformation
Quiz

Q1. What does the word 'Polymorphism' mean in Greek?

A Many Forms

B Single form

C No form

D Final Form

TNS India Foundation | ‹#›


Partners in Economic Transformation
Quiz

Q2. In Java, what concept allows us to implement runtime polymorphism?

A Method overloading

B Method Overriding

C Constructors

D Static methods

TNS India Foundation | ‹#›


Partners in Economic Transformation
Hook
class Test
{
public static void main(String args[])
{
System.out.println(“TNSIF”);
System.out.println(“TNSIF”);
System.out.println(“TNSIF”);
System.out.println(“TNSIF”);
System.out.println(“TNSIF”);
System.out.println(“TNSIF”);
}
}

What will happen if we need to print “TNSIF” for 100 times ??


Is it possible for us to do so ???

TNS India Foundation | ‹#›


Partners in Economic Transformation
Learning Objective

● Understanding the concept of Arrays


● Identifying the Advantage & Disadvantages of Arrays
● Categorizing the various types of Arrays
● a. Single Dimensional Arrays
● b. Multi Dimensional Arrays
● Design Patterns

TNS India Foundation | ‹#›


Partners in Economic Transformation
Arrays

• Java array is an object which contains elements of a similar data type.


• Additionally, The elements of an array are stored in a contiguous memory location.
• It is a data structure where we store similar elements.
• We can store only a fixed set of elements in a Java array.

TNS India Foundation | ‹#›


Partners in Economic Transformation
Advantage / Disadvantage of Arrays

Advantages

○ Code Optimization: It makes the code optimized, we can retrieve or sort the data
efficiently.
○ Random access: We can get any data located at an index position.

Disadvantages

○ Size Limit: We can store only the fixed size of elements in the array. It doesn't grow
its size at runtime.

TNS India Foundation | ‹#›


Partners in Economic Transformation
Types of Arrays

TNS India Foundation | ‹#›


Partners in Economic Transformation
Single Dimensional Array

Syntax to Declare an Array in Java

1. dataType[] arr; (or)


2. dataType []arr; (or)
3. dataType arr[];

Instantiation of an Array in Java

1. arrayRefVar=new datatype[size];

TNS India Foundation | ‹#›


Partners in Economic Transformation
Hands on Coding

TNS India Foundation | ‹#›


Partners in Economic Transformation
Multi Dimensional Array

Syntax to Declare Multidimensional Array in Java

1. dataType[][] arrayRefVar; (or)


2. dataType [][]arrayRefVar; (or)
3. dataType arrayRefVar[][]; (or)
4. dataType []arrayRefVar[];

Example to instantiate Multidimensional Array in Java

1. int[][] arr=new int[3][3];//3 row and 3 column

TNS India Foundation | ‹#›


Partners in Economic Transformation
Hands on Coding

TNS India Foundation | ‹#›


Partners in Economic Transformation
Design Pattern

// outer loop
for (int i = 1; i <= 5; ++i) {
// codes
// inner loop
for(int j = 1; j <=2; ++j) {
// codes
}
..
}

TNS India Foundation | ‹#›


Partners in Economic Transformation
Hands on Coding

TNS India Foundation | ‹#›


Partners in Economic Transformation
Quiz

Q1. How do you declare an array in Java?

A int[] arr;

B int arr[];

C int arr;

D Array<int> arr;

TNS India Foundation | ‹#›


Partners in Economic Transformation
Quiz

Q2. What is the index range for the elements of an array in Java?

A 0 to length - 1

B 1 to length

C -1 to length - 1

D 0 to length

TNS India Foundation | ‹#›


Partners in Economic Transformation
Summary

Arrays: It is a group of like-typed variables referred to by a common name.The variables in


the array are ordered, and each has an index beginning with 0.

Types of Arrays: Single dimensional array and Multidimensional array

TNS India Foundation | ‹#›


Partners in Economic Transformation
Let’s Reflect -

1. What is your major learning from today’s session?


2. How are you going to use this learning in your journey on the job?

TNS India Foundation | ‹#›


Partners in Economic Transformation

You might also like