Selenium Tutorial 13: Built in Methods in Java

preview_player
Показать описание
Built in Methods in Java tutorial explains Java String methods, Number methods, Character methods, Array methods and Date & Time methods. Java Built-in methods for Selenium Test Automation.
Рекомендации по теме
Комментарии
Автор

Class Notes:
Selenium Class 13: Built-in Methods in Java

Categories of Built in Methods

i) String Methods

ii) Number Methods

iii) Character Methods

iv) Array Methods etc...

i) String Methods

1) compareTo() Method (It compares two strings, supports 3-way comparison)

Result Criteria for 3-way comparison

If str1 = str2 then 0
If str1 > str2 then positive value
If str1 < str2 then negative value

Result Criteria for 2-way comparison

If str1 = str2 then true
If str1 (Greater than or Less than) str2 then false


Example:

public static void main (String [] args){
String str1 = "selenium";
String str2 = "SELENIUM";
String str3 = "seleniuma";
String str4 = "selenium";

value
value

}
}

2) equals () Method (It compares two strings and supports 2-way comparison)

Example:

public static void main (String [] args){
String str1 = "selenium";
String str2 = "SELENIUM";
String str3 = "selenium";



}

3) concat() Method (It concatenates two strings /Joins two strings)

public static void main (String [] args){
String str1 = "Selenium";
String str2 = "Testing";


System.out.println(str1 + str2);//SeleniumTesting
}

4) charAt() Method (Returns a character by index position)

public static void main (String [] args){
String str1 = "Selenium";


}

5) equalsIgorecase() Method

public static void main (String [] args){
String str1 = "SELENIUM";
String str2 = "selenium";
String str3 = "UFT";


}

6) toUpperCase () - Converts values to Upper case)

public static void main (String [] args){
String str1 = "SELENIUM";
String str2 = "selenium";
String str3 = "SELEnium";
String str4 = "selenium123";





}

7) toLowerCase() -Converts values to Lower case

public static void main (String [] args){
String str1 = "SELENIUM";
String str2 = "selenium";
String str3 = "SELEnium";
String str4 = "selenium123";





}

8) trim() Method (Removes spaces from both sides of a String)

public static void main (String [] args){
String str1 = " Selenium ";

System.out.println(str1);

}

9) substring () Method

public static void main (String [] args){
String str = "Welecome to Selenium Testing";

Testing

System.out.println(str.substring(12, 20));//Selenium
System.out.println(str.substring(9, 11));//to
}

10) endsWith() -Ends with specified suffix

public static void main (String [] args){
String str = "Welcome to Selenium Testing";

Testing"));//true


}

11) length() (returns string length)

public static void main (String [] args){
String str = "Selenium Testing";
String str2 = "Selenium";


}

ii) Number Methods

1) compareTo() Method (Number, 3-way comparison)

public static void main (String [] args){
// Integer class wraps a value of the primitive type int in an object
//An object of type Integer contains a single field whose type is int.

int x = 5;
Integer a =x;



}

2) equals() Method (Number, 2-way comparison)

public static void main (String [] args){
// Integer class wraps a value of the primitive type int in an object
//An object of type Integer contains a single field whose type is int.

int x = 5;
Integer a =x;



}

3) abs() -Returns absolute value

public static void main (String [] args){
double a =10.234;
double b =-10.784;


}

4) round() -It rounds the value to nearest integer

public static void main (String [] args){
double a =10.234;
double b =-10.784;
double c =10.51;



}

5) min() - Returns minimum value between two numbers

public static void main (String [] args){
int a=10, b=20;
double c =10.234, d =10.345;
System.out.println(Math.min(a, b));//10
System.out.println(Math.min(c, d));//10.234
System.out.println(Math.min(7, 9));//7
System.out.println(Math.min(1.23, 1.234));//1.23
}

6) max()-Returns maximum value between two numbers

public static void main (String [] args){
int a=10, b=20;
double c =10.234, d =10.345;
System.out.println(Math.max(a, b));//20
System.out.println(Math.max(c, d));//10.345
System.out.println(Math.max(7, 9));//9
System.out.println(Math.max(1.23, 1.234));//1.234
}

7) random() - Generates a random number

public static void main (String [] args){

}

iii) Character Methods

1) isLetter() - Checks weather the value is Alfa byte or not?

public static void main (String [] args){
//The Character class wraps a value of primitive data type char is an object

char a ='A';
char b ='1';






}

public static void main (String [] args){
//The Character class wraps a value of primitive data type char is an object
char a ='A';
char b ='1';





}

Assignment:

What is the difference between isLetter() and isAlphabetic()

2) isDigit() -Checks weather the value is Number or not?

public static void main (String [] args){
//The Character class wraps a value of primitive data type char is an object

char a ='A';
char b ='1';





}

3) isUpperCase() - Checks weather the value is Upper case or not?

4) isLowerCase()-Checks weather the value is Lower case or not?

Examples:

public static void main (String [] args){
//The Character class wraps a value of primitive data type char is an object

char a ='A';
char b ='z';
char c ='1';








}

iv) Array Methods

1) length -It returns length of the Array.

public class Sample1 {

public static void main (String [] args){
int [] array1 = {10, 20, 30, 40};

}
}

2) toString() -It prints an Array.

public static void main (String [] args){
String [] array1 = {"Selenium", "UFT", "LoadRunner", "RFT"};
String str = Arrays.toString(array1);
System.out.println(str);
}

3) contains() - Checks if the Array contains certain value or not?

public static void main (String [] args){
String [] array1 = {"Selenium", "UFT", "LoadRunner", "RFT"};
boolean a =
boolean b =

System.out.println(a);//true
System.out.println(b);//false
}

Method syntax:

Object.method()

Class.method

Class/Object.property.method

gcreddy
Автор

Excellent Sir..! This is my 1st time learning Automation, I'm in IT industry past 10 years. Never seen anyone teaching this clearly in easy way to understand. Thanks a lot !!! Keep doing this kind of Tutorials which will save lot of ppl career...!

Dollar-Dhesa-Tamizhan
Автор

Hii sir, the class is excellent. i have a doubt. i want to know,
How to reverse a string?
how to use split()?

dharaniramamanogna
Автор

can i have a notes for this v ideo?? thanks in advance sir..

Gauravsingh-herq
Автор

Hi Sir,
I am using th following as mentioned in your class, for some reason Arrays is getting recognized

public class toString_Ex_Array {

public static void main(String[] args) {

String a [] = {"Selenium", " UFT", "LoadRunner"};
String b = Arrays.toString(a);

}

}

sumanpalisetty