Core Java for Selenium

Java for Selenium video. Click here.

Java for selenium

String class in java Part1

String class in java Part2

Declaring Classes

class SeleniumTestClass {
// field, constructor, and
// method declarations

This is a class declaration.

Tester can provide more information about the class, such as the name of its superclass, whether it implements any interfaces, and so on, at the start of the class declaration. For example,

class SeleniumTestClass extends TestBaseClass implements YourInterface {
// field, constructor, and
// method declarations

Therefore, class declarations can include these components, in order:

a) Modifiers such as public, private, and a number of others that you will encounter later.
b) The class name, with the initial letter capitalized by convention.
c) The name of the class’s parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent.
d) A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.
e) The class body, surrounded by braces, {}.

Declaring Member Variables

There are several kinds of variables:

  • Member variables in a class—these are called fields.
  • Variables in a method or block of code—these are called local variables.
  • Variables in method declarations—these are called parameters.

Defining Methods

Here is an example of a typical method declaration:

The only required elements of a method declaration are the method’s return type, name, a pair of parentheses, (), and a body between braces, {}.

More generally, method declarations have six components, in order:

  1. Modifiers—such as public, private etc.
  2. The return type—the data type of the value returned by the method, or void if the method does not return a value.
  3. The method name (e.g.    getTestResult )
  4. The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.
  5. An exception list
  6. The method body, enclosed between braces—the method’s code, including the declaration of local variables, goes here.

Definition: Two of the components of a method declaration comprise the method signature—the method’s name and the parameter types.

The signature of the method declared above is:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *