Selenium With Java1-Introduction
Selenium With Java1-Introduction
Java is a high-level programming language originally developed by Sun Microsystems and released in
1995.
Oracle purchased Sun Microsystems
Java runs on a different platforms ex: Windows, Mac OS, and the various versions of UNIX.
The latest release of the Java Standard Edition is Java SE 8.
With the advancement of Java and its widespread popularity
Multiple configurations were built to suit various types of platforms.
J2EE for Enterprise Applications, J2ME for Mobile Applications.
Java is guaranteed to be Write Once, Run Anywhere.
Java is −
Platform Independent − When Java is compiled, it is not compiled into platform specific
machine, rather into platform independent byte code.
This byte code is interpreted by the Virtual Machine (JVM) on whichever platform it is being run
on.
Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it
would be easy to master.
Secure − With Java's secure feature it enables to develop virus-free, tamper-free systems.
Authentication techniques are based on public-key encryption.
Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on
compile time error checking and runtime checking.
Multithreaded − it is possible to write programs that can perform many tasks simultaneously.
This feature allows the developers to write applications that can run smoothly.
Interpreted − Java byte code is translated to native machine instructions and is not stored
anywhere.
High Performance − With the use of Just-In-Time compilers, Java enables high performance.
Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to
an evolving environment.
Java programs can carry extensive amount of run-time information that can be used to verify and
resolve accesses to objects on run-time.
In 2006, Sun released Java as free and open source software under the terms of the GNU General Public
License (GPL).
For writing Java Programs, you will need a minimum of 200-MHz computer with a 64 MB of RAM (128
MB of RAM recommended) and the software’s required are
Download and set up Java on your machine, based on version of your operating system.
Once you installed Java on your machine, set environment variables to point to correct installation
directories.
Set Up the Path for Windows
Assuming you have installed Java in c:\Program Files\java\jdkdirectory −
Now, alter the 'Path' variable so that it also contains the path to the Java executable.
Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read
'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.
Notepad − On Windows machine, you can use simple text editor like Notepad
Eclipse − A Java IDE developed by the eclipse open-source community and can be downloaded
from https://www.eclipse.org/.
A Java program can be defined as a collection of objects that communicate by invoking each other's
methods.
o Example: A car has states - color, name, brand as well as behavior such as Start, Stop.
Class − A class can be defined as a template/blueprint that describes the behavior/state that the
object of its type supports.
It is in methods where the logic or code is written, data is manipulated and all the actions are
executed.
Instance Variables − Each object has its unique set of instance variables.
Open a command prompt window and go to the directory where you saved the class.
If there are no errors in your code, the command prompt will take you to the next line If you have set the
path variable correctly.
For all class names the first letter should be in Upper Case.
Example: Assume 'MyFirstProgram' is the class name. Then the file should be saved
as 'MyFirstProgram.java'
Java program processing starts from the main() method which is a mandatory part of every Java
program.
Local Variables
Class Variables are Static Variables
Instance Variables are Non-static Variables
A local variable in Java is a variable that's declared within the body of a method. Then you can use
the variable only within that method. Other methods in the class aren't even aware that the variable exists.
Class variable only have one copy that is shared by all the different objects of a class. A class variable is
a variable defined in a class of which a single copy exists, regardless of how many instances of the
class exist.
An instance variable is a variable defined in a class (i.e. a member variable), for which each instantiated
object of the class has a separate copy, or instance. An instance variable is similar to a class variable.
Instance variables are used by Objects to store their states.
Variables which are defined without the STATIC keyword and are outside any method
declaration are object specific and are known as instance variables.
They are called because their values are instance specific and are not shared among instances.
Comments in Java
Single line comment is given as //
Multiple Line comments given as
/*…….
/
/*
Constructors
Every class has a constructor. If we do not explicitly write a constructor for a class, the Java compiler
builds a default constructor for that class.
Each time a new object is created, at least one constructor will be invoked. The constructor should have
the same name as the class. A class can have more than one constructor.
Object Creation
Initialization − the 'new' keyword is followed by a call to a constructor. This call initializes the new
object.
Example of Constructor and Object
System.out.println(“Invitation:” + name);