Core Java with OCJP/SCJP: Language Fundamentals Part-6 || Arrays Part-1

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Arrays

1) introduction
2) Array Declaration
3) Array Creation
4) Array Initialization
5) Array declaration, Creation & initialization in a single line
6) lenght vs lenght()
7) Anonymous Array
8) array elements assignment
9) Array Variable assignment

Introduction

an array is an indexed collection of a fixed number of homogeneous data elements
the main advantage of arrays is we can represent a huge number of values by using a single variable so that the readability of the code will be improved but the main disadvantage of arrays are
fixed in size that is once we create an array there is no chance of increasing or decreasing the size based on our requirement hence to use the arrays concept compulsory we should
know the size in advance, which may not possible always.

Array Declaration

one-dimensional array declaration

int[] x; valid best practice recommended because the name is clearly separated from the type
int []x; valid
int x[]; valid

at the time of declaration, we can't specify the size otherwise we will get a compile-time error
int[6] x; invalid
int[] x; valid

two-dimensional array declaration

int[][] x; valid
int [][]x; valid
int x[][]; valid
int[] []x; valid
int[] x[]; valid
int []x[]; valid

which of the following is valid

int[] a, b; valid a= 1 b= 1 dimensional
int[] a[], b; valid a=2 b=1 dimensional
int[] a[], b[]; valid a=2 b=2 dimensional
int[] []a, b; valid a=2, b=2 dimensional
int[] []a, b[]; valid a=2, b=3 dimensional
int[] []a, []b; invalid if we want to specify dimensional before the variable that facility is applicable only for 1st variable in a declaration

if we are trying to apply for the remaining variables we will get a compile-time error

int[] []a, []b, []c; a is valid b is invalid c is invalid

3-dimensional array declaration

int[][][] a;
int [][][]a;
int a[][][];
int[] [][]a;
int[] a[][];
int[] []a[];
int[][] []a;
int[][] a[];
int [][]a[];
int []a[][]; these all are valid

Array creation

every array in java is an object only hence we can create arrays by using a new operator

int[] a=new int[3];

for every array type corresponding classes are available and these classes are part of the java language and not available to the program level

example

class Test{
public static void main(String[] args){
int[] x= new int[3];
//[I
}
}


array, corresponding class name

int[] [I
int[][] [[I
double[] [D
short[] [S
byte[] [B
boolean[] [Z

loopholes for creating arrays

1) at the time of array creation compulsory we should specify the size otherwise we will get compile time error

int[] x=new int[]; invalid
int[] x=new int[6]; valid


2) it is legal to have an array with size zero in java

int[] x=new int[0]; valid

3) if we are trying to specify array size with some -ve int value then we will get a run time exception saying negative array size exception

int[] x=new int[-3]; valid RE: negative arror size exception

4) to specify array size the allowed data types are byte, short, char, and int if we are trying to specify any other type then we will get CE:

int[] x=new int[10]; valid
int[] x=new int['a']; valid

byte b=20;
int[] x=new int[b]; valid

short s=30;
int[] x=new int[s]; valid

int[] x=new int[10l]; incalid CE; p l p found long required int

the maximum allowed array size in java is 2147483647 which is the maximum value of the int data type

int[] x=new int [2147483647]; valid RE: even in the case we may get a run time exception if sufficient heap memory is not available
int[] x=new int[2147483648]; invalid CE ; integer number is too large

comedyhits
Автор

Sir I am a instrumentation engg PG. and served as an assistant professor for 7 years. But now i want to enter an IT industry. In this pandemic lockdown your videos are giving me strong confidence to learn Java. The way you teach and you cover every minute details is incredible Sir. Thank you so much

snehalwankhade
Автор

He is inevitable like thanos in programming language Great salute to this maestro durga sir the JAVA legend

obetheanest
Автор

He is covering very minute and basic concepts. Thanks for these videos.

gyandhungana
Автор

0:14 - Eras
0:19 - Agenda: Introduction, Array Declaration, Array Creation, Array Initialization
1:05 - Declaration, Creation, and Initialization in a Single Line
1:38 - Length vs length (Java length variable vs length method)
1:51 - Anonymous Arrays
2:05 - Array Element Assignments
2:19 - Array Variable Assignments
2:37 - Introduction to Arrays: Need, Purpose, Advantages, Disadvantages
3:05 - Example: int x = 10
4:17 - Representing 10, 000 Values with an Array
5:04 - Advantages of Arrays
5:51 - Limitations of Arrays: Fixed Size
6:09 - Example: Classroom Scenario (Fixed Size Limitation)
7:12 - Array Limitations: Homogeneous Data Types Only
8:02 - Collections as a Solution to Array Limitations
8:30 - Definition of an Array
9:08 - Main Advantage of Arrays
10:05 - Readability Improvement with Arrays
10:49 - Main Disadvantage: Fixed Size
12:16 - Summary and Conclusion

Abhi-rknp
Автор

i can't believe, teacher is like that 8 years before. i am glad to see you sir.

unboxingadda
Автор

Five years ago you taught about Java but still students watched your videos
Great thing Great thing Great thing

Maaa
Автор

In 2024, I'm still finding your videos helpful. They're a great resource for learning about Java.

justtt.prerna
Автор

Best tutorials ever words to describe it....

bibekdhungana
Автор

When i decided to Do Selenium WebDriver (Test Automation), my 1 friend suggested me to watch your Java Tutorial. Than my fully life is changed. ThanQ Sir, One Day i will come to Hyderabad to Touch your feet Only.

hrusikeshbisoyi
Автор

2018 and you are still saving lives. Thank you so much!

somerandomsheat
Автор

Durga sir . . i just want to touch your feet.. Keep blessing :)

HUNTER-sjfu
Автор

Only teacher I have seen in my life which doesn’t leave a single doubt in my mind.

sanjaychhikara
Автор

he clears those doubts which we don't know we had🙌🏻

tanishajaiswal
Автор

I'm addicted to your videos. I will share this playlist everywhere, awesome teaching style and in-depth information.

farazmobin
Автор

First impression is best impression.So always Durga sir is first impression when came to JAVA.

nagarajm
Автор

Sir, I am from Bihar.There is no teacher like you in my college .I learn and enjoy most your every session.
Thankyou so much sir🙏🙏

VARSHAKumariDECE
Автор

Excellent Sir.. You are God of Java.. Salute you sir..👍👏👏

piyushhibare
Автор

Thank you so much every minute you are clearing my each and every doubts....India needs more teachers like you....

ishitakundu
Автор

I am from Noida .No Coaching is better than you/Yours.One day when i will visit hyderabad will surely meet and Touch your feet and have your blessings Sir.Jai Hind

deveshsingh