SlideShare a Scribd company logo
JAVA
"WRITE ONCE, RUN ANYWHERE”
Lec--6
By: Zubair Khalid
Java
£ Arrays and their types
£ Methods
£ The Void keyword
£ Methods Call by value
£ Methods Call by reference
An array is a group of consecutive memory locations with the same
name and datatype.
Used to store multiple values of same data types
Arrays
There are following types of arrays
£ One-dimensional array
£ Multi-dimensional array
Datatype Arrayname[]=new Datatype[Arraylength]
One-dimensional Array
Declaration Syntax:
A type of array in which all elements are arranged in the form of list is
known as one-dimensional array or linear list.
It consists of one column or one row.
One-dimensional Array
E.G :
Int a[]=new Int[10];
A.Datatype A.Name A.Length
One-dimensional Array
Assigning value to array:
a [0]=24;
a [1]=30;
a [2]=13;
.
.
.
Method 1(initialization):
Int a[]={33,44,55,….};
Method 2(definition):
Datatype Arrayname[][]=new Datatype[Arrayrows] [Arraycolumns]
Multi-dimensional Array
Multi-dimensional array can be considered as a table consists of rows and
columns.
Each element in 2-D array is referred with the help of two indexes. One is used to
indicate the row and the second index indicates the column of the element
Declaration Syntax:
Multi-dimensional Array
E.G :
Int a[][]=new Int[2][3];
A.Datatype A.Name A.Rows A.Columns
Multi-dimensional Array
Assigning value to array:
A [0][0]=24;
A [0][1]=30;
A [0][2]=13;
.
.
.
Method 1(initialization):
Int a[][]={33,44,55,….};
Method 2(definition):
Methods
When we call the System.Out.Println() method, the system actually executes several
statements in order to display a message on the console.
A Java method is a collection of statements that are grouped together to
perform an operation.
Example:
Creating Methods
public static int methodName(int a, int b) {
// body
}
Now we will learn how to create our own methods with or without return values, invoke a
method with or without parameters, and apply method abstraction in the program design.
Syntax:
ℑ Public static Modifier
ℑ Int Return Type
ℑ Methodname Name of method
ℑ a,b Parameters
Creating & Calling Methods
Example:
Creating
Calling
Void Keyword
Here, in the previous example we're considering a void method PFTN. This
method is a void method, which does not return any value.
The void keyword allows us to create methods which do not return a value.
Example:
Passing Arguments to Methods
Using Primitive data types  byte, short, int, long, float, double, char & boolean
Using Reference data types  Objects & Arrays etc.
A method can pass arguments in two manners:
A method can pass arguments in two manners:
Call by value  Pass by value
Call by reference  Pass by reference
Call by Value (or) Pass by Value
The call by value copies the values of actual parameter into formal parameters
Changing value of formal parameter not effect the value of actual parameter
The original copy of the argument value remains without changing because
the method creates own copy of argument values and then uses them
Passing Parameters by Value
While working under calling process, arguments is to be passed. These should be in the same
order as their respective parameters in the method specification. Parameters can be passed by
value or by reference.
Passing Parameters by Value means calling a method with a parameter. Through this, the
argument value is passed to the parameter.
Syntax:
add(9,5)
Method Value 1
Value 2
Passing Parameters by Value
Example:
Call by Reference (or) Pass by Reference
• In this approach, a reference to an object is passed as argument into the
method, inside the called method this reference is used to access the actual
object
• Therefore changes made via reference parameter within method (formal
argument) will effect the actual object
Reference types, such as an object is passed into methods by reference.
Passing Parameters by Reference
Example:

More Related Content

PPT
Ap Power Point Chpt9
PDF
Arrays in c_language
PPTX
OOPs with java
PPTX
PPTX
Array Of Pointers
PPTX
Lecture 7
PPTX
ARRAY
Ap Power Point Chpt9
Arrays in c_language
OOPs with java
Array Of Pointers
Lecture 7
ARRAY

What's hot (19)

PPT
Array
PPTX
Lesson 11 one dimensional array
PPTX
Regular Expressions
PPTX
arrays of structures
PPT
One Dimensional Array
PPTX
Data Types - Premetive and Non Premetive
PPTX
Chap6java5th
PPTX
Lecture 3 data structures and algorithms
PDF
Elementary data structure
PPT
Lecture 4 classes ii
PPTX
Python dictionary
PPT
Lecture 2a arrays
ODP
C++ arrays part1
PPTX
arrays in c
PDF
C Sharp: Basic to Intermediate Part 01
PPTX
PPTX
Arrays in c language
Array
Lesson 11 one dimensional array
Regular Expressions
arrays of structures
One Dimensional Array
Data Types - Premetive and Non Premetive
Chap6java5th
Lecture 3 data structures and algorithms
Elementary data structure
Lecture 4 classes ii
Python dictionary
Lecture 2a arrays
C++ arrays part1
arrays in c
C Sharp: Basic to Intermediate Part 01
Arrays in c language
Ad

Similar to Java -lec-6 (20)

PPTX
IntroductionJava Programming - Math Class
PPT
ch06.ppt
PPT
PPT
ch06.ppt
PPT
array Details
PPTX
ch 7 single dimension array in oop .pptx
PPTX
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
PPT
Cso gaddis java_chapter5
PPT
Lecture 9
PDF
PASS BY VALUE .pdf
PPT
Java căn bản - Chapter10
PPTX
Chap1 array
PDF
Arrays Java
PDF
Xamarin: C# Methods
PDF
Java session 3
PPTX
Identifiers, keywords and types
PPT
Chap07
PPTX
Chap2 class,objects contd
PPT
Java_Identifiers_keywords_data_types.ppt
PPT
17-Arrays en java presentación documento
IntroductionJava Programming - Math Class
ch06.ppt
ch06.ppt
array Details
ch 7 single dimension array in oop .pptx
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
Cso gaddis java_chapter5
Lecture 9
PASS BY VALUE .pdf
Java căn bản - Chapter10
Chap1 array
Arrays Java
Xamarin: C# Methods
Java session 3
Identifiers, keywords and types
Chap07
Chap2 class,objects contd
Java_Identifiers_keywords_data_types.ppt
17-Arrays en java presentación documento
Ad

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPT
Teaching material agriculture food technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Review of recent advances in non-invasive hemoglobin estimation
sap open course for s4hana steps from ECC to s4
Assigned Numbers - 2025 - Bluetooth® Document
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Java -lec-6

  • 1. JAVA "WRITE ONCE, RUN ANYWHERE” Lec--6 By: Zubair Khalid
  • 2. Java £ Arrays and their types £ Methods £ The Void keyword £ Methods Call by value £ Methods Call by reference
  • 3. An array is a group of consecutive memory locations with the same name and datatype. Used to store multiple values of same data types Arrays There are following types of arrays £ One-dimensional array £ Multi-dimensional array
  • 4. Datatype Arrayname[]=new Datatype[Arraylength] One-dimensional Array Declaration Syntax: A type of array in which all elements are arranged in the form of list is known as one-dimensional array or linear list. It consists of one column or one row.
  • 5. One-dimensional Array E.G : Int a[]=new Int[10]; A.Datatype A.Name A.Length
  • 6. One-dimensional Array Assigning value to array: a [0]=24; a [1]=30; a [2]=13; . . . Method 1(initialization): Int a[]={33,44,55,….}; Method 2(definition):
  • 7. Datatype Arrayname[][]=new Datatype[Arrayrows] [Arraycolumns] Multi-dimensional Array Multi-dimensional array can be considered as a table consists of rows and columns. Each element in 2-D array is referred with the help of two indexes. One is used to indicate the row and the second index indicates the column of the element Declaration Syntax:
  • 8. Multi-dimensional Array E.G : Int a[][]=new Int[2][3]; A.Datatype A.Name A.Rows A.Columns
  • 9. Multi-dimensional Array Assigning value to array: A [0][0]=24; A [0][1]=30; A [0][2]=13; . . . Method 1(initialization): Int a[][]={33,44,55,….}; Method 2(definition):
  • 10. Methods When we call the System.Out.Println() method, the system actually executes several statements in order to display a message on the console. A Java method is a collection of statements that are grouped together to perform an operation. Example:
  • 11. Creating Methods public static int methodName(int a, int b) { // body } Now we will learn how to create our own methods with or without return values, invoke a method with or without parameters, and apply method abstraction in the program design. Syntax: ℑ Public static Modifier ℑ Int Return Type ℑ Methodname Name of method ℑ a,b Parameters
  • 12. Creating & Calling Methods Example: Creating Calling
  • 13. Void Keyword Here, in the previous example we're considering a void method PFTN. This method is a void method, which does not return any value. The void keyword allows us to create methods which do not return a value. Example:
  • 14. Passing Arguments to Methods Using Primitive data types  byte, short, int, long, float, double, char & boolean Using Reference data types  Objects & Arrays etc. A method can pass arguments in two manners: A method can pass arguments in two manners: Call by value  Pass by value Call by reference  Pass by reference
  • 15. Call by Value (or) Pass by Value The call by value copies the values of actual parameter into formal parameters Changing value of formal parameter not effect the value of actual parameter The original copy of the argument value remains without changing because the method creates own copy of argument values and then uses them
  • 16. Passing Parameters by Value While working under calling process, arguments is to be passed. These should be in the same order as their respective parameters in the method specification. Parameters can be passed by value or by reference. Passing Parameters by Value means calling a method with a parameter. Through this, the argument value is passed to the parameter. Syntax: add(9,5) Method Value 1 Value 2
  • 17. Passing Parameters by Value Example:
  • 18. Call by Reference (or) Pass by Reference • In this approach, a reference to an object is passed as argument into the method, inside the called method this reference is used to access the actual object • Therefore changes made via reference parameter within method (formal argument) will effect the actual object Reference types, such as an object is passed into methods by reference.
  • 19. Passing Parameters by Reference Example: