SlideShare a Scribd company logo
1 of 13
Page 0Classification: Restricted
Selenium Training
Arrays & Methods
Page 1Classification: Restricted
Agenda
• Switch-Case
• Arrays
• Methods
Page 2Classification: Restricted
Switch-Case
• A switch-case allows the program to choose which statement(s) to
perform based on a condition
Syntax: switch (exp) {
case val1: // statements here
break;
case val2: // statements here
break;
default: // statements here
}
Example: int x = 1;
switch (x) {
case 1: System.out.println ( “Value of x is 1”);
break;
case 2: System.out.println ( “Value of x is NOT 1”);
break;
default: System.out.println ( “Value of x is NULL”);
}
Page 3Classification: Restricted
Arrays
• An array is a sequence of either objects or primitives, all of the same type
under one identifier name
• Basic array declaration syntax:
Syntax: <data_type> [ ] <variable_name>;
<data_type> <variable_name> [ ];
<data_type> [ ] <variable_name> [ ];
Examples : int [ ] myIntegerArray;
String myStringArray [ ];
char [ ] myCharArray [ ];
Page 4Classification: Restricted
Arrays: Manipulation
• Values in arrays can be accessed and manipulated by their index
• An array’s index always start with 0
String[] anotherStringArray = {“Hello", “There”, “How“, “Are”, ”You”};
System.out.println(“The first string is “ + anotherStringArray[0]);
Page 5Classification: Restricted
Arrays: Multi-Dimensional Arrays
• A multi-dimensional array can simply be thought of as arrays of arrays
• Each pair of square brackets ( [ ] ), represent one dimension
Syntax: <data type>[ ] [ ] <variable name>;
<data type>[ ] [ ] [ ] <variable name>;
Example: int[ ][ ] aGridOfIntegers;
int[ ][ ][ ] aCubeOfIntegers;
Page 6Classification: Restricted
Arrays: Manipulation
• Multi-dimensional arrays can be accessed the same way
• Each bracket pair represents one dimension of the array
a b c
d e f
g h i
0 1 2
0
1
2
char][] anotherCharArray = {{a,b,c},{d,e,f},{g,h,i}};
System.out.println(“Accessing center of grid” + anotherCharArray[1][1]);
Page 7Classification: Restricted
Methods
• A method is a collection of one or more statements that performs a
specific task
• Basic syntax of a Java method declaration:
• A method’s signature is a combination of a method’s name and
parameters that uniquely identify a method
Syntax: <return_type> <identifier_name> ( <parameter(s)> ) {
//method implementation here
return <return_value>;
}
Page 8Classification: Restricted
Method Declaration
package sef.module3.sample;
public class MethodSample {
public void greet(){
System.out.println(“Hello!”);
}
public static void greet(String name){
System.out.println(“Hello “ + name + “!”);
}
public int sum(int x, int y) {
return x + y;
}
}
• No parameters with a
‘void’ return type. This
means the method does
not return any value
• You can pass
parameters to a method.
These are considered
local variables
• It has the same name
as the previous method,
but different parameters
•Note a ‘static’ modifier.
This means this method
is a class method and
can be called without an
object reference
•This method has a int
return type. This requires
the method to have a
‘return’ statement that
returns an integer value.
greet()
greet(String)
thirdMethod
Page 9Classification: Restricted
Calling Methods
• To ‘call’ a method, use the method’s name and pass the appropriate
number and type of parameters according to the method’s signature.
• When calling a method, flow control will ‘jump’ to that method.
• When the method finishes, flow control will return to the point where the
method was called.
• Instance methods are attached to an instance of an object. These will
need to be called through an object reference.
• Static methods are attached to a class, and can be called via its class
name.
Page 10Classification: Restricted
Parameter Passing
• Parameters in Java are Passed By Value
• Passing Primitive Data Type Arguments
• A copy of the value is passed to the method.
• Any changes to the value exists only within the scope of the
method.
• When the method returns, any changes to the value are lost. The
original value remains.
• Passing Reference Data Type Arguments
• A copy of the object’s reference’s value is being passed.
• The values of the object's fields can be changed inside the method,
if they have the proper access level.
• When the method returns, the passed-in reference still references
the same object as before. However, the changes in the object’s
fields will be retained.
Page 11Classification: Restricted
Method Declaration
public class MethodSample {
public void greet(){
System.out.println(“Hello!”);
}
public static void greet(String name){
System.out.println(“Hello “ + name + “!”);
}
public int sum(int x, int y) {
return x + y;
}
public static void main(String arg[]){
MethodSample sample = new MethodSample();
sample.greet();
greet(“Java Teacher”);
MethodSample.greet(“Java Student”);
System.out.println(“Sum of 1 and 2 is “ +
sample.sum(1, 2));
}
}
Call an instance
method through its
object
Call class methods
statically and pass
parameters
Call an instance
method that accepts
parameters and
returns values
Page 12Classification: Restricted
Thank You!

More Related Content

What's hot

Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysDevaKumari Vijay
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threadsDevaKumari Vijay
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructorsJan Niño Acierto
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Nuzhat Memon
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
Refactoring bad codesmell
Refactoring bad codesmellRefactoring bad codesmell
Refactoring bad codesmellhyunglak kim
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and VariablesNilesh Dalvi
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 

What's hot (20)

Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Hemajava
HemajavaHemajava
Hemajava
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Java Programming - 05 access control in java
Java Programming - 05 access control in javaJava Programming - 05 access control in java
Java Programming - 05 access control in java
 
LISP:Object System Lisp
LISP:Object System LispLISP:Object System Lisp
LISP:Object System Lisp
 
Refactoring bad codesmell
Refactoring bad codesmellRefactoring bad codesmell
Refactoring bad codesmell
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
 
Java session4
Java session4Java session4
Java session4
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 

Similar to Session 08 - Arrays and Methods

LISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP Content
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...vekariyakashyap
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptxakila m
 
chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)It Academy
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHPVibrant Technologies & Computers
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorialrajkamaltibacademy
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritanceteach4uin
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritanceteach4uin
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 

Similar to Session 08 - Arrays and Methods (20)

LISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP: Object Sytstem Lisp
LISP: Object Sytstem Lisp
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
Delegate
DelegateDelegate
Delegate
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
 
Lec4
Lec4Lec4
Lec4
 
chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)
 
Java
JavaJava
Java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
Unit 3
Unit 3Unit 3
Unit 3
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Core java oop
Core java oopCore java oop
Core java oop
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 

More from SiddharthSelenium

Session 07 - Flow Control Statements
Session 07 - Flow Control StatementsSession 07 - Flow Control Statements
Session 07 - Flow Control StatementsSiddharthSelenium
 
Session 05 - Introduction to WebDriver - Part 02
Session 05 - Introduction to WebDriver - Part 02Session 05 - Introduction to WebDriver - Part 02
Session 05 - Introduction to WebDriver - Part 02SiddharthSelenium
 
Session 04 - Creating Test Suites in IDE
Session 04 - Creating Test Suites in IDESession 04 - Creating Test Suites in IDE
Session 04 - Creating Test Suites in IDESiddharthSelenium
 
Session 02 - Selenium IDE - Part 2
Session 02 - Selenium IDE - Part 2Session 02 - Selenium IDE - Part 2
Session 02 - Selenium IDE - Part 2SiddharthSelenium
 
Session 02 - Object Identification - Part 1
Session 02 - Object Identification - Part 1Session 02 - Object Identification - Part 1
Session 02 - Object Identification - Part 1SiddharthSelenium
 
Session 01 - Introduction to Selenium - Part 2
Session 01 - Introduction to Selenium - Part 2Session 01 - Introduction to Selenium - Part 2
Session 01 - Introduction to Selenium - Part 2SiddharthSelenium
 
Session 01 - Introduction to Automation - Part 1
Session 01 - Introduction to Automation - Part 1Session 01 - Introduction to Automation - Part 1
Session 01 - Introduction to Automation - Part 1SiddharthSelenium
 

More from SiddharthSelenium (9)

Session 09 - OOPS
Session 09 - OOPSSession 09 - OOPS
Session 09 - OOPS
 
Session 07 - Flow Control Statements
Session 07 - Flow Control StatementsSession 07 - Flow Control Statements
Session 07 - Flow Control Statements
 
Session 06 - Java Basics
Session 06 - Java BasicsSession 06 - Java Basics
Session 06 - Java Basics
 
Session 05 - Introduction to WebDriver - Part 02
Session 05 - Introduction to WebDriver - Part 02Session 05 - Introduction to WebDriver - Part 02
Session 05 - Introduction to WebDriver - Part 02
 
Session 04 - Creating Test Suites in IDE
Session 04 - Creating Test Suites in IDESession 04 - Creating Test Suites in IDE
Session 04 - Creating Test Suites in IDE
 
Session 02 - Selenium IDE - Part 2
Session 02 - Selenium IDE - Part 2Session 02 - Selenium IDE - Part 2
Session 02 - Selenium IDE - Part 2
 
Session 02 - Object Identification - Part 1
Session 02 - Object Identification - Part 1Session 02 - Object Identification - Part 1
Session 02 - Object Identification - Part 1
 
Session 01 - Introduction to Selenium - Part 2
Session 01 - Introduction to Selenium - Part 2Session 01 - Introduction to Selenium - Part 2
Session 01 - Introduction to Selenium - Part 2
 
Session 01 - Introduction to Automation - Part 1
Session 01 - Introduction to Automation - Part 1Session 01 - Introduction to Automation - Part 1
Session 01 - Introduction to Automation - Part 1
 

Recently uploaded

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 

Session 08 - Arrays and Methods

  • 1. Page 0Classification: Restricted Selenium Training Arrays & Methods
  • 2. Page 1Classification: Restricted Agenda • Switch-Case • Arrays • Methods
  • 3. Page 2Classification: Restricted Switch-Case • A switch-case allows the program to choose which statement(s) to perform based on a condition Syntax: switch (exp) { case val1: // statements here break; case val2: // statements here break; default: // statements here } Example: int x = 1; switch (x) { case 1: System.out.println ( “Value of x is 1”); break; case 2: System.out.println ( “Value of x is NOT 1”); break; default: System.out.println ( “Value of x is NULL”); }
  • 4. Page 3Classification: Restricted Arrays • An array is a sequence of either objects or primitives, all of the same type under one identifier name • Basic array declaration syntax: Syntax: <data_type> [ ] <variable_name>; <data_type> <variable_name> [ ]; <data_type> [ ] <variable_name> [ ]; Examples : int [ ] myIntegerArray; String myStringArray [ ]; char [ ] myCharArray [ ];
  • 5. Page 4Classification: Restricted Arrays: Manipulation • Values in arrays can be accessed and manipulated by their index • An array’s index always start with 0 String[] anotherStringArray = {“Hello", “There”, “How“, “Are”, ”You”}; System.out.println(“The first string is “ + anotherStringArray[0]);
  • 6. Page 5Classification: Restricted Arrays: Multi-Dimensional Arrays • A multi-dimensional array can simply be thought of as arrays of arrays • Each pair of square brackets ( [ ] ), represent one dimension Syntax: <data type>[ ] [ ] <variable name>; <data type>[ ] [ ] [ ] <variable name>; Example: int[ ][ ] aGridOfIntegers; int[ ][ ][ ] aCubeOfIntegers;
  • 7. Page 6Classification: Restricted Arrays: Manipulation • Multi-dimensional arrays can be accessed the same way • Each bracket pair represents one dimension of the array a b c d e f g h i 0 1 2 0 1 2 char][] anotherCharArray = {{a,b,c},{d,e,f},{g,h,i}}; System.out.println(“Accessing center of grid” + anotherCharArray[1][1]);
  • 8. Page 7Classification: Restricted Methods • A method is a collection of one or more statements that performs a specific task • Basic syntax of a Java method declaration: • A method’s signature is a combination of a method’s name and parameters that uniquely identify a method Syntax: <return_type> <identifier_name> ( <parameter(s)> ) { //method implementation here return <return_value>; }
  • 9. Page 8Classification: Restricted Method Declaration package sef.module3.sample; public class MethodSample { public void greet(){ System.out.println(“Hello!”); } public static void greet(String name){ System.out.println(“Hello “ + name + “!”); } public int sum(int x, int y) { return x + y; } } • No parameters with a ‘void’ return type. This means the method does not return any value • You can pass parameters to a method. These are considered local variables • It has the same name as the previous method, but different parameters •Note a ‘static’ modifier. This means this method is a class method and can be called without an object reference •This method has a int return type. This requires the method to have a ‘return’ statement that returns an integer value. greet() greet(String) thirdMethod
  • 10. Page 9Classification: Restricted Calling Methods • To ‘call’ a method, use the method’s name and pass the appropriate number and type of parameters according to the method’s signature. • When calling a method, flow control will ‘jump’ to that method. • When the method finishes, flow control will return to the point where the method was called. • Instance methods are attached to an instance of an object. These will need to be called through an object reference. • Static methods are attached to a class, and can be called via its class name.
  • 11. Page 10Classification: Restricted Parameter Passing • Parameters in Java are Passed By Value • Passing Primitive Data Type Arguments • A copy of the value is passed to the method. • Any changes to the value exists only within the scope of the method. • When the method returns, any changes to the value are lost. The original value remains. • Passing Reference Data Type Arguments • A copy of the object’s reference’s value is being passed. • The values of the object's fields can be changed inside the method, if they have the proper access level. • When the method returns, the passed-in reference still references the same object as before. However, the changes in the object’s fields will be retained.
  • 12. Page 11Classification: Restricted Method Declaration public class MethodSample { public void greet(){ System.out.println(“Hello!”); } public static void greet(String name){ System.out.println(“Hello “ + name + “!”); } public int sum(int x, int y) { return x + y; } public static void main(String arg[]){ MethodSample sample = new MethodSample(); sample.greet(); greet(“Java Teacher”); MethodSample.greet(“Java Student”); System.out.println(“Sum of 1 and 2 is “ + sample.sum(1, 2)); } } Call an instance method through its object Call class methods statically and pass parameters Call an instance method that accepts parameters and returns values