Book Image

Learning Selenium Testing Tools - Third Edition

Book Image

Learning Selenium Testing Tools - Third Edition

Overview of this book

Table of Contents (22 chapters)
Learning Selenium Testing Tools Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

About Java programming


Java is a general-purpose computer programming language that is concurrent, class-based, and object-oriented. It includes the following functionalities:

  • Real-world programming

  • Reusability (reuse of components once created)

  • Modularity (modifying a required object without affecting the functionality of the other object)

  • Resilience to change (redefining the system without any major change in other parts)

  • Information hiding (limited access to information can be given to the user, resulting in security in a program)

How does Java work?

  1. Java programs are written in .java files.

  2. When the .java file is executed, Java Virtual Machine (JVM) will interact with one of its components, Compiler, which will convert the .java file to a .class file.

  3. Interpreter is another component of Java Virtual Machine that will interact with the .class file in runtime, that is, at the time of execution, and this provides the output.

    Note

    JVM (Java Virtual Machine) + JRE (Java Runtime Environment) = JDK (Java Development Kit)

Package

A package is a collection of classes and interfaces that provides a high-level layer of access protection and namespace management.

At a high level, its a folder where the Java classes are placed.

Class

A class defines the structure and behavior of an object or set of objects.

Objects

Objects are the basic building blocks of the OOP, and they can also be defined as an instance of a class.

Objects have the following characteristics:

  • State: The state of an object is indicated by a set of attributes and the values of these attributes.

  • Behavior: The behavior of an object refers to the change of its state over a period of time.

  • Identity: Each object has a unique identity for identification.

  • A class in the object-oriented methodology is a collection of various attributes, such as data and methods. You can access the data of a class using its methods.

    Note

    The Main method is the entry point of execution in a Java program.

Importing the sample Java project in the Eclipse workspace

The following are the steps to run the sample programs:

  1. Launch Eclipse.

  2. Import the project (File | Import | Existing Project | Java project path) MySampleJavaProject as an existing project.

  3. Enable the Navigator view on Eclipse (from Window Tab | Show View).

  4. Right-click on the .java file and select Run as Java Application.

A simple Java program example

The following is an example of a Java program:

package pckg1;
public class example1 {
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("I am done with my 1st program on java");
  }
}

The output for the preceding code will be as follows:

I am done with my 1st program on java