SlideShare a Scribd company logo
Java/J2EE Programming Training
Data Handling and Functions
Page 2Classification: Restricted
Agenda
• Implement Single and Multi dimensional array
• Declare and Define Functions
• Call Functions by value and by reference
• Implement Method Overloading
• Use String data-type and String-buffer
Page 3Classification: Restricted
Introduction to Arrays
Page 4Classification: Restricted
Meet John Again
Page 5Classification: Restricted
One day in office
Page 6Classification: Restricted
One day in office
6
Page 7Classification: Restricted
John’s Project – Question Statement
Page 8Classification: Restricted
Daisy was Confused!
Page 9Classification: Restricted
John already had a plan
Page 10Classification: Restricted
John Came up with a solution
Page 11Classification: Restricted
John’s Solution
Page 12Classification: Restricted
John Presented the Solution
Page 13Classification: Restricted
John gets a Promotion
Page 14Classification: Restricted
Why do we use Arrays?
• Arrays are an important structure to hold data.
• Java allows us to hold many objects of the same type using arrays and it can
be used with the help of a loop to access the elements by their index.
Page 15Classification: Restricted
Arrays
Page 16Classification: Restricted
Declaring Arrays
Page 17Classification: Restricted
Declaring Arrays
Page 18Classification: Restricted
Declaring Arrays
• Arrays can be declared for primitive and non-primitive data types.
• Instead of declaring int a1, a2, a3, a4....a100, we can declare int
a[100].
• It is fast and efficient to access an element in an array using the
corresponding index without actually traversing through the entire
array.
• The size of the array is fixed once it is created.
• For Example: A character array of 10 characters can be declared as
Page 19Classification: Restricted
Types of Arrays
Page 20Classification: Restricted
How Single Dimensional Arrays are used?
Page 21Classification: Restricted
Multidimentional Array
• Multi dimensional arrays can be 2 dimensional as rows and columns similar
to a matrix or it could be 3 dimensional with depth, height and breadth or it
could be 'n' dimensional array as per the requirement.
• Multi-dimensional arrays can be declared as
• Usually 2 dimensional arrays are used to perform matrix operations.
• Like single dimensional arrays, multi dimensional arrays can be of primitive
and nonprimitive data type.
Page 22Classification: Restricted
Question
How many bytes are allocated for the array x?
int x[][] = new int[5][5];
Page 23Classification: Restricted
Answer
An int element takes 4 bytes and array x can store 25
int elements.
Hence total number of bytes taken by x is 25*4 = 100
Page 24Classification: Restricted
Question
Can we do multi dimensional array operations in
single dimensional array?
If yes, then why do we require multi dimensional
array?
Page 25Classification: Restricted
Answer
We can perform all the operations of multi
dimensional array in single dimensional array but
when the data has more than one dimension, it will
be easier to perform operations in multi
dimensional array.
Page 26Classification: Restricted
LAB
Page 27Classification: Restricted
Function
Page 28Classification: Restricted
Daisy Seek’s Help
Page 29Classification: Restricted
John helps Daisy
Page 30Classification: Restricted
John helps Daisy
Page 31Classification: Restricted
John explain Functions
Page 32Classification: Restricted
John helps Daisy
Page 33Classification: Restricted
Functions
• Scope specifier modifier return type function name (arguments)
• A function/method has group of statements to be executed.
• A function has a task to perform.
• A function is declared as public static void say Hello(int a, int b)
Page 34Classification: Restricted
Why do we use functions?
• We use functions to provide different kinds of functionality.
• For example:
• absolute()
• To find the absolute value of a number.
• square()
• To find the square of a number.
• sqrt()
• To find the square root of a number.
Page 35Classification: Restricted
Features of Functions
• Scope specifier
• This option specifies the visibility of the function. It could be public,
private, protected or default (package).
• Modifier
• This is optional.
• This will change the meaning of the function. Some of the options could
be final, static, native,synchronized etc.
• Return type
• This option specifies the data that will be returned by the function.
• It could be primitive data type or objects.
• Function name
• It is the name given to the function. Using function name, functions can
be invoked.
• Arguments
• This is optional but can be used. Using this, one can pass values to the
function for computation.
Page 36Classification: Restricted
What happens when a Function is Invoked?
• When a function is called from the main method, main method() address is
stored on top of the stack.
• Control jumps to execute the function.
• After executing the function, main method address is popped from the
stack and main
method execution resumes.
Page 37Classification: Restricted
What happens when a function is invoked?
Page 38Classification: Restricted
What happens when a function is invoked?
Page 39Classification: Restricted
What happens when a function is invoked?
Page 40Classification: Restricted
What happens when a Function is Invoked?
Page 41Classification: Restricted
What happens when a Function is Invoked?
Page 42Classification: Restricted
Sample program on Function
Page 43Classification: Restricted
Sample program on Functions (Contind..)
Page 44Classification: Restricted
Sample program on Functions(Contd..)
4
Page 45Classification: Restricted
Sample Program on Functions (contd..)
Page 46Classification: Restricted
Sample Program on Functions (contd..)
Page 47Classification: Restricted
Function Calling ways
Page 48Classification: Restricted
Call by Value
• When value of the
primitive data type is
passed as an argument
from the calling
function, data is being
sent to the function.
• At the receiving end, a
new variable is created
and the data is copied.
This is call by value.
• All the programs we
have done till now
is done using call by
value.
Page 49Classification: Restricted
Call by Reference
Page 50Classification: Restricted
Call by Reference
Page 51Classification: Restricted
Polymorphism
Page 52Classification: Restricted
Function Overloading
Page 53Classification: Restricted
Function Overloading (contd.)
Page 54Classification: Restricted
Function Overloading (contd.)
Page 55Classification: Restricted
Function Overloading
Page 56Classification: Restricted
Function Overloading
5
Page 57Classification: Restricted
Program on Function Overloading
Page 58Classification: Restricted
Meet Mr. Letter and Miss Sentence!
Page 59Classification: Restricted
Mr.Letter is from “char datatype”
Page 60Classification: Restricted
Miss Sentence is sad!
Page 61Classification: Restricted
Miss Sentence has her own Place in Java
Page 62Classification: Restricted
Why do we use String?
Page 63Classification: Restricted
String
• String is a class in Java to store string data.
• You can assign string data simply by defining the string object and assign
the string like this:
• You can concatenate two string using + symbol.
• For Example:
• Output of the program is
• Appended string is: HelloWorld
String str;
String str = “Focusthread”
String str = new String (“Focusthread”);
Page 64Classification: Restricted
Where do we use string?
Page 65Classification: Restricted
String Functions
• length()
• Returns the length of the string.
• charAt(int)
• Returns a character at the specified position. Index of the String starts from 0.
• concat (String str)
• It concatenates the with the string object. It is same as using '+' operator for
concatenation.
• equals(String str)
• Checks whether string object and str and return true if they are same else
returns false.
• EqulsIgnoreCase (String str)
• Same as above function except that this function ignores the case and checks
for the equality of the strings.
• indexOf(String str)
• Returns the index of the specified string in the string object.
• lastIndexOf(String str)
• Same as above function but checks from back of the string.
Page 66Classification: Restricted
String Functions
• replace(char ch, char ch1)
• Replaces the character ch with Character ch1 in the string.
• toLowerCase()
• Converts the given string to lowercase.
• toUpperCase()
• Converts the given string to uppercase.
• trim()
• Removes the leading and trailing spaces of the string.
Page 67Classification: Restricted
LAB
Page 68Classification: Restricted
StringBuffer
Page 69Classification: Restricted
Question
When should we use String and
StringBuffer? why?
Page 70Classification: Restricted
Answer
When we do not need to modify string objects then
String can be used else using StringBuffer is a better
option since it is mutable.
Page 71Classification: Restricted
Program on StringBuffer
Page 72Classification: Restricted
StringBuider
Page 73Classification: Restricted
StringBuilder Constructors
Page 74Classification: Restricted
Assignment – Single Dimentional Array
Page 75Classification: Restricted
Assignment – Two Dimentational Array
Page 76Classification: Restricted
Assignment - Functions
Page 77Classification: Restricted
Assignment – Functions Overloading
Page 78Classification: Restricted
Module Assignment
Page 79Classification: Restricted
Module Assignment
Page 80Classification: Restricted
Module Assignment
Page 81Classification: Restricted
Agenda for Next Class
Page 82Classification: Restricted
Pre work
Page 83Classification: Restricted
Thank You

More Related Content

PPSX
Strings in Java
PPSX
Practice Session
PPT
8. String
PPT
10. Introduction to Datastructure
PPT
Knowledge Discovery Query Language (KDQL)
PPTX
DotNet programming & Practices
PPTX
PPT
wrapper classes
Strings in Java
Practice Session
8. String
10. Introduction to Datastructure
Knowledge Discovery Query Language (KDQL)
DotNet programming & Practices
wrapper classes

What's hot (13)

PPTX
L9 wrapper classes
PDF
String handling(string buffer class)
PDF
Wrapper classes
PPT
3. Data types and Variables
PPTX
Java tutorial part 3
PPT
Chapter 4 strings
PPTX
Session 10 - OOP with Java - Abstract Classes and Interfaces
PDF
Text categorization as graph
PDF
Automatic Document Summarization
PDF
The Ring programming language version 1.5.3 book - Part 187 of 194
PDF
The Ring programming language version 1.7 book - Part 90 of 196
L9 wrapper classes
String handling(string buffer class)
Wrapper classes
3. Data types and Variables
Java tutorial part 3
Chapter 4 strings
Session 10 - OOP with Java - Abstract Classes and Interfaces
Text categorization as graph
Automatic Document Summarization
The Ring programming language version 1.5.3 book - Part 187 of 194
The Ring programming language version 1.7 book - Part 90 of 196
Ad

Similar to Data Handling and Function (20)

PPTX
Session 04 - Arrays in Java
PPSX
Arrays in Java
PDF
JAVA Class Presentation.pdf Vsjsjsnheheh
PPTX
Learning core java
PPTX
Data structure and algorithm using java
PDF
DSJ_Unit I & II.pdf
PPTX
II B.Sc IT DATA STRUCTURES.pptx
PPTX
Java ce241
PPTX
2CPP17 - File IO
PPTX
C++ & Data Structure - Unit - first.pptx
PDF
Data-Structure-using-C-Rajesh-Pandey.pdf
PPT
Core java by a introduction sandesh sharma
PDF
Performance van Java 8 en verder - Jeroen Borgers
PPTX
Abstract Data Types (ADTs) in Data Structures
PPTX
Abstract Data Types (ADTs) in Data Structures
PPTX
Abstract Data Types (ADTs) in Data Structures
PPTX
PDF
microC-DAQ
PPT
Data structures
Session 04 - Arrays in Java
Arrays in Java
JAVA Class Presentation.pdf Vsjsjsnheheh
Learning core java
Data structure and algorithm using java
DSJ_Unit I & II.pdf
II B.Sc IT DATA STRUCTURES.pptx
Java ce241
2CPP17 - File IO
C++ & Data Structure - Unit - first.pptx
Data-Structure-using-C-Rajesh-Pandey.pdf
Core java by a introduction sandesh sharma
Performance van Java 8 en verder - Jeroen Borgers
Abstract Data Types (ADTs) in Data Structures
Abstract Data Types (ADTs) in Data Structures
Abstract Data Types (ADTs) in Data Structures
microC-DAQ
Data structures
Ad

More from RatnaJava (14)

PPTX
Review Session and Attending Java Interviews
PPTX
Collections - Lists & sets
PPTX
Collections - Sorting, Comparing Basics
PPTX
Collections Array list
PPTX
Object Class
PPTX
Exception Handling
PPTX
OOPs with Java - Packaging and Access Modifiers
PPTX
OOP with Java - Abstract Classes and Interfaces
PPTX
OOP with Java - Part 3
PPTX
OOP with Java - continued
PPTX
Object Oriented Programming
PPTX
Introduction to Java Part-3
PPTX
Introduction to Java Part-2
PPTX
Introduction to Java
Review Session and Attending Java Interviews
Collections - Lists & sets
Collections - Sorting, Comparing Basics
Collections Array list
Object Class
Exception Handling
OOPs with Java - Packaging and Access Modifiers
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Part 3
OOP with Java - continued
Object Oriented Programming
Introduction to Java Part-3
Introduction to Java Part-2
Introduction to Java

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
Teaching material agriculture food technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing

Data Handling and Function