SlideShare uma empresa Scribd logo
1 de 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!

Mais conteúdo relacionado

Mais procurados

Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
Jan Niño Acierto
 

Mais procurados (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
 

Semelhante a Session 08 - Arrays and Methods

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
Sandesh Sharma
 
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
 

Semelhante a 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
 

Mais de SiddharthSelenium

Mais de 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
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

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