SlideShare a Scribd company logo
Noida Institute of Engineering and
Technology, Greater Noida
JAVA TRAINING
Mr. Sumit Kumar
Subject code-BMCA0253
OOT using JAVA
DATE - 10/04/2024 TIME – 9:00 TO 05:00
2
Java Array
 Java array is an object the contains elements of similar data
type. It is a data structure where we store similar elements.
 Array holds a fixed number of elements.
 Length of an array is specified when an array is created. Once
length of an array is specified it remains fixed.
 Array in Java is index based and the index starts from 0. So
the first element is stored in the array at index 0.
 Elements in Java array are always numbered from 0 to (n –
1) where n is the individual elements in the array.
 They are dynamic, created on the heap memory.
 Array objects implement Cloneable and Serializable
interfaces.
 To declare an array, define the variable type with square
brackets:[]
3
4
• An array is a container object that holds a fixed number of values of a single
type.
• The length of an array is established when the array is created. After creation,
its length is fixed.
• As we know Array is a data structure where we store similar elements and
Array a starts from index 0.
• Each item in an array is called an element, and each element is accessed by its
numerical index.
• Since arrays are objects in Java, we can find their length using member length.
• A Java array variable can also be declared like other variables with [] after the
data type.
• The variables in the array are ordered and each has an index beginning from
0.
• Java array can be also be used as a static field, a local variable or a method
parameter.
• The size of an array must be specified by an int value and not long or short
5
6
Advantage of Java Array
Code Optimization: It makes the code optimized, we can retrieve or
sort the data easily.
Random access: We can get any data located at any index position.
Disadvantage of Java Array
Size Limit: We can store the only fixed size of elements in the array. It
doesn't grow its size at runtime. To solve this problem,
collection framework is used in java.
7
8
9
Types of Array in java
Single Dimensional Array
Multidimensional Array
10
11
Declaring a Variable to Refer to an Array
// this form is discouraged
float anArrayOfFloats[];
int[] anArray;
1.An array's type is written as type[], where type is the data type of
the contained elements; the brackets are special symbols
indicating that this variable holds an array. The size of the array is
not part of its type (which is why the brackets are empty).
Creating an Array
Int[] anArray = new int[10];
String[] anArrayOfStrings = new String[10];
Object[] anArrayOfObjects = new Object[10];
12
13
• Multidimensional array in java
 In such case, data is stored in row and column based index (also known
as matrix form).
Syntax to Declare Multidimensional Array in java
dataType[][] arrayRefVar;
(or)
dataType arrayRefVar[][];
(or)
dataType []arrayRefVar[];
14
 Example to instantiate Multidimensional Array in java
int[][] arr=new int[3][3]; //3 row and 3 column
 Example to initialize Multidimensional Array in java
arr[0][0]=1;
arr[0][1]=2;
arr[0][2]=3;
arr[1][0]=4;
arr[1][1]=5;
arr[1][2]=6;
arr[2][0]=7;
arr[2][1]=8;
arr[2][2]=9;
15
 Example of Multidimensional java array
class Testarray3{
public static void main(String args[]){
//declaring and initializing 2D array
int arr[][]={{1,2,3},{2,4,5},{4,4,5}};
//printing 2D array
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
}
Output :-
1 2 3
2 4 5
4 4 5
16
OOPs (Object-Oriented Programming System)
• OOPs (Object-Oriented Programming System)Object
means a real-world entity such as a pen, chair, table,
computer, watch, etc. Object-Oriented Programming is a
methodology or paradigm to design a program using
classes and objects. It simplifies software development
and maintenance by providing some concepts:
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
17
Object
• The Object is the real-time entity having some state and behavior. In
Java, Object is an instance of the class having the instance variables
as the state of the object and the methods as the behavior of the
object. The object of a class can be created by using the new keyword
in Java Programming language.
• 1. An object is a real-world entity.
• 2. An object is a runtime entity.
• 3. The object is an entity which has state and behavior.
• 4. The object is an instance of a class.
• object in Java is the physical entity
• Real-world examples
• Dogs have state (name, color, breed, hungry) and behavior (barking,
fetching, wagging tail). Chair, Bike, Marker, Pen, Table, Car, Book,
Apple, Bag etc. It can be physical or logical (tangible and intangible).
18
• Apart from these concepts, there are some other
terms which are used in Object-Oriented design:
• - Coupling
• - Cohesion
• - Association
• - Aggregation
• - Composition
19
20
class
A class is a group of objects which have common properties.
It is a template or blueprint from which objects are created.
In short, a class is the specification or template of an object.
• class in Java is a logical entity only.
• A class is a template or blueprint from which objects are
created. So, an object is the instance(result) of a class.
• A class in Java can contain:
• Fields
• Methods
• Constructors
• Blocks
• Nested class and interface
21
22
1.class <class_name>{
2. method;
3. field;
4.}
23
24
//Java Program to illustrate how to define a class and fields
//Defining a Student class.
class Student{
//defining fields
int id;//field or data member or instance variable
String name;
//creating main method inside the Student class
public static void main(String args[]){
//Creating an object or instance
Student s1=new Student();//creating an object of Student
//Printing values of the object
System.out.println(s1.id);//
accessing member through reference variable
System.out.println(s1.name);
}
}
25
//Java Program to demonstrate having the main method in
//another class
//Creating Student class.
class Student{
int id;
String name;
}
//
Creating another class TestStudent1 which contains the main method
class TestStudent1{
public static void main(String args[]){
Student s1=new Student();
System.out.println(s1.id);
System.out.println(s1.name);
}
}
26
class Student{
int id;
String name;
}
class TestStudent2{
public static void main(String args[]){
Student s1=new Student();
s1.id=101;
s1.name="Sonoo";
System.out.println(s1.id+" "+s1.name);//
printing members with a white space
}
}
27
class Student{
int rollno;
String name;
void insertRecord(int r, String n){
rollno=r;
name=n;
}
void displayInformation(){System.out.println(rollno+" "+name);}
}
class TestStudent4{
public static void main(String args[]){
Student s1=new Student();
Student s2=new Student();
s1.insertRecord(111,"Karan");
s2.insertRecord(222,"Aryan");
s1.displayInformation();
s2.displayInformation();
}
}
28
public static void main(String args[]){
Student2 s1=new Student2();
Student2 s2=new Student2();
s1.insertRecord(111,"Karan");
s2.insertRecord(222,"Aryan");
s1.displayInformation();
s2.displayInformation();
}
}
111 Karan
222 Aryan
OUTPUT

More Related Content

PPTX
Array.pptx
PPTX
Arrays in java.pptx
PPTX
How to create a two-dimensional array in java
PPTX
the array, which stores a fixed-size sequential collection of elements of the...
PDF
Arrays in java
PPTX
CAP615-Unit1.pptx
PPTX
Data types ^J variables and arrays in Java.pptx
PPTX
Array.pptx
Arrays in java.pptx
How to create a two-dimensional array in java
the array, which stores a fixed-size sequential collection of elements of the...
Arrays in java
CAP615-Unit1.pptx
Data types ^J variables and arrays in Java.pptx

Similar to JAVA WORKSHOP(DAY 3) 1234567889999999.pptx (20)

PPTX
OOPs with java
PDF
Arrays in Java
PDF
JAVA Class Presentation.pdf Vsjsjsnheheh
PPTX
Introduction to java
PPTX
arraylist in java a comparison of the array and arraylist
PPTX
Basic_Understanding_of_Arrays_in_Java_Quipoin.pptx
PPTX
Array lecture
PPTX
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
PDF
Class notes(week 4) on arrays and strings
PPTX
ppt_on_java.pptx
PPT
PPTX
ARRAYS.pptx
DOCX
Class notes(week 4) on arrays and strings
PPTX
Presentation2.ppt java basic core ppt .
PPTX
Learning core java
PPTX
Object oriented programming2 Week 2.pptx
PPTX
PCSTt11 overview of java
PPTX
Java Array String
PPT
packages and interfaces
PPTX
intro_java (1).pptx
OOPs with java
Arrays in Java
JAVA Class Presentation.pdf Vsjsjsnheheh
Introduction to java
arraylist in java a comparison of the array and arraylist
Basic_Understanding_of_Arrays_in_Java_Quipoin.pptx
Array lecture
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Class notes(week 4) on arrays and strings
ppt_on_java.pptx
ARRAYS.pptx
Class notes(week 4) on arrays and strings
Presentation2.ppt java basic core ppt .
Learning core java
Object oriented programming2 Week 2.pptx
PCSTt11 overview of java
Java Array String
packages and interfaces
intro_java (1).pptx
Ad

Recently uploaded (20)

PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PPTX
Introduction to Knowledge Engineering Part 1
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
Business Acumen Training GuidePresentation.pptx
PPTX
Understanding Prototyping in Design and Development
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
1intro to AI.pptx AI components & composition
PPTX
Global journeys: estimating international migration
PPTX
Azure Data management Engineer project.pptx
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PDF
Master Databricks SQL with AccentFuture – The Future of Data Warehousing
PPT
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
Challenges and opportunities in feeding a growing population
PPTX
Measurement of Afordability for Water Supply and Sanitation in Bangladesh .pptx
PPT
Quality review (1)_presentation of this 21
PDF
Taxes Foundatisdcsdcsdon Certificate.pdf
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
Introduction-to-Cloud-ComputingFinal.pptx
Introduction to Knowledge Engineering Part 1
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Business Acumen Training GuidePresentation.pptx
Understanding Prototyping in Design and Development
climate analysis of Dhaka ,Banglades.pptx
1intro to AI.pptx AI components & composition
Global journeys: estimating international migration
Azure Data management Engineer project.pptx
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Master Databricks SQL with AccentFuture – The Future of Data Warehousing
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
Business Ppt On Nestle.pptx huunnnhhgfvu
Challenges and opportunities in feeding a growing population
Measurement of Afordability for Water Supply and Sanitation in Bangladesh .pptx
Quality review (1)_presentation of this 21
Taxes Foundatisdcsdcsdon Certificate.pdf
Ad

JAVA WORKSHOP(DAY 3) 1234567889999999.pptx

  • 1. Noida Institute of Engineering and Technology, Greater Noida JAVA TRAINING Mr. Sumit Kumar Subject code-BMCA0253 OOT using JAVA DATE - 10/04/2024 TIME – 9:00 TO 05:00
  • 2. 2 Java Array  Java array is an object the contains elements of similar data type. It is a data structure where we store similar elements.  Array holds a fixed number of elements.  Length of an array is specified when an array is created. Once length of an array is specified it remains fixed.  Array in Java is index based and the index starts from 0. So the first element is stored in the array at index 0.  Elements in Java array are always numbered from 0 to (n – 1) where n is the individual elements in the array.  They are dynamic, created on the heap memory.  Array objects implement Cloneable and Serializable interfaces.  To declare an array, define the variable type with square brackets:[]
  • 3. 3
  • 4. 4 • An array is a container object that holds a fixed number of values of a single type. • The length of an array is established when the array is created. After creation, its length is fixed. • As we know Array is a data structure where we store similar elements and Array a starts from index 0. • Each item in an array is called an element, and each element is accessed by its numerical index. • Since arrays are objects in Java, we can find their length using member length. • A Java array variable can also be declared like other variables with [] after the data type. • The variables in the array are ordered and each has an index beginning from 0. • Java array can be also be used as a static field, a local variable or a method parameter. • The size of an array must be specified by an int value and not long or short
  • 5. 5
  • 6. 6 Advantage of Java Array Code Optimization: It makes the code optimized, we can retrieve or sort the data easily. Random access: We can get any data located at any index position. Disadvantage of Java Array Size Limit: We can store the only fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem, collection framework is used in java.
  • 7. 7
  • 8. 8
  • 9. 9 Types of Array in java Single Dimensional Array Multidimensional Array
  • 10. 10
  • 11. 11 Declaring a Variable to Refer to an Array // this form is discouraged float anArrayOfFloats[]; int[] anArray; 1.An array's type is written as type[], where type is the data type of the contained elements; the brackets are special symbols indicating that this variable holds an array. The size of the array is not part of its type (which is why the brackets are empty). Creating an Array Int[] anArray = new int[10]; String[] anArrayOfStrings = new String[10]; Object[] anArrayOfObjects = new Object[10];
  • 12. 12
  • 13. 13 • Multidimensional array in java  In such case, data is stored in row and column based index (also known as matrix form). Syntax to Declare Multidimensional Array in java dataType[][] arrayRefVar; (or) dataType arrayRefVar[][]; (or) dataType []arrayRefVar[];
  • 14. 14  Example to instantiate Multidimensional Array in java int[][] arr=new int[3][3]; //3 row and 3 column  Example to initialize Multidimensional Array in java arr[0][0]=1; arr[0][1]=2; arr[0][2]=3; arr[1][0]=4; arr[1][1]=5; arr[1][2]=6; arr[2][0]=7; arr[2][1]=8; arr[2][2]=9;
  • 15. 15  Example of Multidimensional java array class Testarray3{ public static void main(String args[]){ //declaring and initializing 2D array int arr[][]={{1,2,3},{2,4,5},{4,4,5}}; //printing 2D array for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ System.out.print(arr[i][j]+" "); } System.out.println(); } } } Output :- 1 2 3 2 4 5 4 4 5
  • 16. 16 OOPs (Object-Oriented Programming System) • OOPs (Object-Oriented Programming System)Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies software development and maintenance by providing some concepts: • Object • Class • Inheritance • Polymorphism • Abstraction • Encapsulation
  • 17. 17 Object • The Object is the real-time entity having some state and behavior. In Java, Object is an instance of the class having the instance variables as the state of the object and the methods as the behavior of the object. The object of a class can be created by using the new keyword in Java Programming language. • 1. An object is a real-world entity. • 2. An object is a runtime entity. • 3. The object is an entity which has state and behavior. • 4. The object is an instance of a class. • object in Java is the physical entity • Real-world examples • Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Chair, Bike, Marker, Pen, Table, Car, Book, Apple, Bag etc. It can be physical or logical (tangible and intangible).
  • 18. 18 • Apart from these concepts, there are some other terms which are used in Object-Oriented design: • - Coupling • - Cohesion • - Association • - Aggregation • - Composition
  • 19. 19
  • 20. 20 class A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. In short, a class is the specification or template of an object. • class in Java is a logical entity only. • A class is a template or blueprint from which objects are created. So, an object is the instance(result) of a class. • A class in Java can contain: • Fields • Methods • Constructors • Blocks • Nested class and interface
  • 21. 21
  • 23. 23
  • 24. 24 //Java Program to illustrate how to define a class and fields //Defining a Student class. class Student{ //defining fields int id;//field or data member or instance variable String name; //creating main method inside the Student class public static void main(String args[]){ //Creating an object or instance Student s1=new Student();//creating an object of Student //Printing values of the object System.out.println(s1.id);// accessing member through reference variable System.out.println(s1.name); } }
  • 25. 25 //Java Program to demonstrate having the main method in //another class //Creating Student class. class Student{ int id; String name; } // Creating another class TestStudent1 which contains the main method class TestStudent1{ public static void main(String args[]){ Student s1=new Student(); System.out.println(s1.id); System.out.println(s1.name); } }
  • 26. 26 class Student{ int id; String name; } class TestStudent2{ public static void main(String args[]){ Student s1=new Student(); s1.id=101; s1.name="Sonoo"; System.out.println(s1.id+" "+s1.name);// printing members with a white space } }
  • 27. 27 class Student{ int rollno; String name; void insertRecord(int r, String n){ rollno=r; name=n; } void displayInformation(){System.out.println(rollno+" "+name);} } class TestStudent4{ public static void main(String args[]){ Student s1=new Student(); Student s2=new Student(); s1.insertRecord(111,"Karan"); s2.insertRecord(222,"Aryan"); s1.displayInformation(); s2.displayInformation(); } }
  • 28. 28 public static void main(String args[]){ Student2 s1=new Student2(); Student2 s2=new Student2(); s1.insertRecord(111,"Karan"); s2.insertRecord(222,"Aryan"); s1.displayInformation(); s2.displayInformation(); } } 111 Karan 222 Aryan OUTPUT