SlideShare a Scribd company logo
Basics of Java
Session-1
Wathsala Siriwardana
Introduction to Programming
Language
▪A programming language is a set of rules that provides a way
of telling a computer what operations to perform
▪Generally a computer program takes an input and process the
input to produce an output
Input Process Output
Different Programming
Paradigms
▪Functional/procedural programming:
▫program is a list of instructions to the computer
▪Object-oriented programming
▫program is composed of a collection objects that
communicate with each other
Understand Java platform
and environment
▪ JVM - Provides runtime
environment in which java
bytecode can be executed
▪ JRE - Provides runtime
environment. Implements
JVM
▪ JDK - Java Developer Kit
contains tools needed to
develop the Java programs,
and JRE to run the
programs.
Compiler
Debugger
Java
Applet
Viewer
JVM
rt.jar Java.exe
libraries
JRE
JDK
Programmed Translators
▪Some languages use both compiler and interpreter to do the translations
▪E.g. Java compiler translates a java program into a machine independent
intermediate language known as JVM machine language,
▪Then the code in the JVM machine language is interpreted using a java
interpreter
Features of Java
 Simple
Syntax is based on C++
Not required to remove unreferenced objects since Automatic Garbage Collection
is there
 Portable
Write Once Run Anywhere (WORA)
 Object Oriented
 Platform Independent
Java code is compiled by the compiler and converted into bytecode. This is
platform independent thus can be run on multiple platforms
▫ Multithreaded
With Java's multithreaded feature it is possible to write programs that can
perform many tasks simultaneously.
Prerequisites
For this you should have a basic knowledge of Object Oriented Principles (OOPs).
Let’s start with the basics
Object
A real world Entity which has a state and a
behavior
Class
A class is a collection of Objects. It serves as
a template for creating, or instantiating,
specific objects within a program.
E.g:- A Car class can have a model, color, manufacturedYear as
state and drive, reverse as behaviours. Ferrari is a real world
Object that we can create from that class
Fundamentals of OOP
▪ Abstraction – Hiding Internal details and showing only the functionality
Abstract classes, Interfaces are ways of achieving this
▪ Encapsulation – Binding and wrapping code and data together
Java class (having private fields and public accessors,mutators) are an
example for this
▪ Polymorphism – One task is performed in different ways
Method overriding and overloading are ways to achieve this
▪ Inheritance – One object acquires all the propertiese and behaviours of a parent
object
- Inheritance provides code reusability and used to achieve runtime polymorphism
- Java doesn’t allow multiple inheritance
Abstraction
▪ Animals are capable of doing different things like flying, digging and
walking, but there are some common operations as well like eating
and sleeping.
▪ Some common operations are performed by all animals, but in a
different way as well.
▪ When an operation is performed in a different way, it is a good
candidate for an abstract method
Encapsulation
To achieve encapsulation in Java
•Declare the variables of a class as private.
•Provide public setter and getter methods to modify and
view the variables values.
Inheritance
extends is the keyword used to
inherit the properties of a class.
Following is the syntax of extends
keyword.
Basic Structure of a Java
program
public class HelloWorld{
public static void main(String[] args){
System.out.println(“Hello World”);
}
}
Access modifier Class name Method name
Argument
list(expects an
array of String
arguments)
Few important keywords in
Java
▪ Variable - A Java variable is a piece of memory that can contain a data
value. A variable thus has a data type.
▪ Data Type – They further explain the kind of data that needs to be stored
e.g :- int, char
▪ Literals – Source code representation of a fixed value
e.g :- int age=20;
▪ Default Values – If variables are not assigned with a value then compiler
will add a value automatically
e.g :- default value for String is null, default value for boolean is false
 Identifiers – Name of the variable
 Keywords – Reserved words in java
▪ short
▪ byte
▪ int
▪ long
▪ double
▪ float
▪ char
▪ boolean
Basic Data Types in Java
Data Types
Primitive Data Types Reference Data Types
▪ Objects such as String,
Array, HashMap etc.
▪ Default value is null
▪ Reference can be used to
access the object
integer types
floating points
Operators and
Assignments
In Java
Operators
Assignment
operators
Arithmetic
operators
Relational
operators
Logical
operators
Miscellaneous
operators
Conditional Instance of
Bitwise
operators
=
+=
-=
*=
/=
%=
<<=
>>=
&=
^=
|=
+
-
*
/
%
++
--
==
!=
>
<
>=
<=
&&
||
! ?:
&
|
^
~
<<
>>
>>>
instanceof
Loop control
and Decision
making in
Java
Decision making in java
If
e.g:-
if(num%2 ==0){
//print even
}
If-else
e.g:-
if(num%2 ==0){
//print even
}
else{
//print odd
}
If- else if - else
e.g:-
if(num%2 ==0){
//print even
}
else if(num%2 !=0){
//print odd
}
else{
//print invalid input
}
switch
e.g:-
char grade=‘A’;
switch(g){
case ‘A’ : //print ‘Pass’
break;
case ‘F’ : //print ‘Fail’
break;
default: //print ‘Invalid’
}
Loops in Java
while
e.g:-
int x=0;
while(x<words.length){
//print words[x]
x++;
}
do-while
e.g:-
int x=0;
do{
//print words[x]
x++;
} while(x<words.length);
for
e.g:-
for(int x=0 ; x<words.length ; x++){
//print words[x]
}
foreach
e.g:-
for(String word : words){
//print word
}
String words[]={“apple” , “banana”, “grapes”};
Break and Continue
keywords in Java
Break
e.g:-
int x=0;
while(x<words.length){
if(words[x].equals(“banana”)){
break;
}
else{
System.out.println(words[x]);
}
x++;
}
Continue
e.g:-
int x=0;
while(x<words.length){
if(words[x].equals(“banana”)){
continue;
}
else{
System.out.println(words[x]);
}
x++;
}
String words[]={“apple” , “banana”, “grapes”};
apple apple
grapes
OUT
Conditions and loops
if/else
do/while
for
Switch case
If(x==4) {
// act1
} else {
// act2
}
int i=5;
do {
// act1
i--;
} while(i!=0);
int j;
for(int i=0;i<=9;i++)
{
j+=i;
}
char c=IN.getChar();
switch(c) {
case ‘a’:
case ‘b’:
// act1
break;
default:
// act2
}
Constructors in Java
 Constructor is a special type of method that is used to initialize the object
 There are rules to define a constructor
- Constructor name must be as same as the class name
- Must not have an explicit return type
 There are two types of Constructors in Java
- Default constructor
- Parameterized constructor
 If there is no constructor in a class, compiler will automatically create a
default constructor
 Defaulot construtor will set default values for class variables wheras if
you want to set values of your own then go for a parameterized
constructor
Constructor Overloading in
Java
 A class can have any number of
Constructors
 Number of parameters and type
of them differentiate each one
another e.g:-
Method Overloading in java
 If a class have multiple methods by same name but different parameters it
is known as ‘Method Overloading’
 Method Overloading increaces the readability of the program
 There are two ways that we can overload methods
- By changing the no of arguments
- By changing the data type
Method Overloading in
java…
e.g:- By changing the no of arguments
Method Overloading in
java…
e.g:- By changing the data type
Method Overloading in
java…
 Can we overload methods by changing their return types?
NO, method overloading cannot be achieved by changing the return type of
the methods.
e.g:- int sum(int a, int b){};
double sum(int a, int b){};
int result=sum(10,30); //Compile time error!
 Can we overload main() method of a java program?
YES. You can have any number of main methods in your java class through
method overloading. This is achieved by changing the parameters of the
main method
Method Overloading & Type
promotion
One type is promoted to another type implicitly if no matching data type is
found
byte
short
int
long
char float
double
Since no method with two int arguments are found, the compiler will automatically
considers the method with int, double (second int literal will be promoted to double)
Method Overriding in Java
 If subclass provides the specific implementation of the method that has
been provided by one of its parent class, it is known as method overriding
in java.
 Method overriding is used for runtime polymorphism
 Rules for method overriding in Java
- Method must have the same name as in the parent class
- Method must have same parameter as in the parent class
- There must be an IS-A relationship (inheritance)
 We can override methods by changing their return type only if their
return type is covariant (subtype of the super method’s return type)
Method Overriding in
Java… Example
•
• run() method is overridden in Bike
class with its own implementation
• super keyword is used to access
the parent class method
• During runtime it decides which
method to invoke. This is called
runtime polymorphism
• Static methods cannot be
overridden in java
• Thus main() method cannot be
overridden.
Method Overriding Vs
Method Overloading
Method Overloading Method Overriding
Used to increase the readability of the program Used to provide the specific implementation of the
method that is already provided by its super class
Is performed within the class Occurs in two classes that have an IS-A
relationship (Inheritance)
In case of method overloading, parameter must be
different
In case of method overriding, parameter must be
same
Is an example for compile time polymorphism Is an example for runtime polymorphism
In Java, method overloading cannot be performed
by changing the return type. Return type must be
same or different but you have to change the
parameter
Type must be same or Covariant in method
overriding
‘Super’ Keyword in Java
 Super is a reference variable that is used to refer immediate parent class
Object
 e.g:- When you create a Student object, a Person
object also being created automatically.
 There are three main usages of ‘super’ key word in Java
Person
Student
‘Super’ Keyword in Java…
1. ‘super’ is used to refer immediate parent class instance variable
‘Super’ Keyword in Java…
2. super() is used to invoke immediate parent class constructor
‘Super’ Keyword in Java…
3. Super is used to invoke immediate parent clas method
Access Modifiers
Access Modifiers in Java
Access Modifier Within Class Within Package
private Yes No
Default Yes Yes
Protected Yes Yes
Public Yes Yes
Note that there is no keyword call Default. A variable/
method defined without any access modifier is a
variable to any other classes in the same package.
E.g:- the fields of an interface are implicitly public static
final, the methods of an interface are by default public
Can’t apply to classes and interfaces . Fields and
methods that are marked as protected in a superclass,
only its subclasses can access them.
Access Modifiers in Java…
Where to use protected access modifier?
• If the openSpeaker() method is
marked as public, then any class
can access it.
• If openSpeaker() method is marked
as private then it is accessible only
within the AudioPlayer class
• To allow only its subclasses to use
it, we have to mark it as protected
Access control and
Inheritance
These rules must be enforced in inheritance
 Methods declared public in super class must be marked as public in all of
its subclasses
 Methods declared protected in super class can either be marked as
protected or public in its subclasses
 Methods declared private are not inherited at all, so theres no rule for
them.
Arrays in Java
 Java Array is an object that contains similar type of data
 We can store a fixed set of elements in Java Array
 Array in Java is indexed based, first element is stored at index 0.
0 1 2 3 4 indicesFirst index
Array length
Arrays in Java…
Advantages of Java Array
 Code optimization (we can retrieve or sort data easily)
 Random Access
Disadvantages
 Size limit – we can store only fixed size of elements in java array. It
doesn’t grow as we store elements at runtime
 Types of Arrays in Java
1. Single dimensional Array
2. Multidimensional Array
Arrays in Java…
Declaration syntax for single dimensional Array
dataType[] arr;
dataType []arr;
dataType arr[];
Declaration syntax for multi dimensional Array
dataType[][] arrayRefVar;
dataType [][]arrayRefVar;
dataType arrayRefVar [][];
dataType []arrayRefVar [];
Arrays in Java…
Initializing Single dimensional
Arrays in Java
int arr;
arr=new int[10];
arr[0]=23;
arr[1]=54; etc…
OR
int arr[]={23,54};
Initializing Multi dimensional
Arrays in Java
int[][] arr;
arr=new int[3][3];
arr[0][0]=10;
arr[0][1]=30;
OR
Int arr[][]={{1,2,3},{4,6,7}, …};
Final keyword
final class Base {
final int i=5;
final void foo() {
i=10;
//what will the compiler say
about this?
}
}
class Derived extends Base {
// Error
// another foo ...
void foo() {
▪final member data
Constant member
▪final member function
The method can’t be
overridden.
▪final class
‘Base’ is final, thus it can’t be
extended
(ie: String class is final)
Contd..
Thank You

More Related Content

What's hot

Byteman - Carving up your Java code
Byteman - Carving up your Java codeByteman - Carving up your Java code
Byteman - Carving up your Java code
Chris Sinjakli
 
Rational Robot (http://www.geektester.blogspot.com)
Rational Robot (http://www.geektester.blogspot.com)Rational Robot (http://www.geektester.blogspot.com)
Rational Robot (http://www.geektester.blogspot.com)
raj.kamal13
 
Software Testing - Tool support for testing (CAST) - Mazenet Solution
Software Testing - Tool support for testing (CAST) - Mazenet SolutionSoftware Testing - Tool support for testing (CAST) - Mazenet Solution
Software Testing - Tool support for testing (CAST) - Mazenet Solution
Mazenetsolution
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
Somkiat Puisungnoen
 
Robot Framework
Robot FrameworkRobot Framework
Robot Framework
Onur Baskirt
 
Java architecture
Java architectureJava architecture
Java architecture
Rakesh Vadnala
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
Derek Binkley
 
Sphinx + robot framework = documentation as result of functional testing
Sphinx + robot framework = documentation as result of functional testingSphinx + robot framework = documentation as result of functional testing
Sphinx + robot framework = documentation as result of functional testing
plewicki
 
Basics of QTP Framework
Basics of QTP FrameworkBasics of QTP Framework
Basics of QTP Framework
Anish10110
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
Nikhil Sharma
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnit
kleinron
 
EasyTest Test Automation Tool Introduction
EasyTest Test Automation Tool IntroductionEasyTest Test Automation Tool Introduction
EasyTest Test Automation Tool Introduction
Zhu Zhong
 
UFT Automation Framework Introduction
UFT Automation Framework IntroductionUFT Automation Framework Introduction
UFT Automation Framework IntroductionHimal Bandara
 
Lecture - 1 introduction to java
Lecture - 1 introduction to javaLecture - 1 introduction to java
Lecture - 1 introduction to java
manish kumar
 
Robot framework and selenium2 library
Robot framework and selenium2 libraryRobot framework and selenium2 library
Robot framework and selenium2 library
krishantha_samaraweera
 
Python in Test automation
Python in Test automationPython in Test automation
Python in Test automation
Krishnana Sreeraman
 
Robot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs IntegrationRobot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs Integration
Sauce Labs
 
Implementing Refactorings in IntelliJ IDEA
Implementing Refactorings in IntelliJ IDEAImplementing Refactorings in IntelliJ IDEA
Implementing Refactorings in IntelliJ IDEA
intelliyole
 
Architecture diagram of jvm
Architecture diagram of jvmArchitecture diagram of jvm
Architecture diagram of jvm
home
 

What's hot (20)

Byteman - Carving up your Java code
Byteman - Carving up your Java codeByteman - Carving up your Java code
Byteman - Carving up your Java code
 
Rational Robot (http://www.geektester.blogspot.com)
Rational Robot (http://www.geektester.blogspot.com)Rational Robot (http://www.geektester.blogspot.com)
Rational Robot (http://www.geektester.blogspot.com)
 
Software Testing - Tool support for testing (CAST) - Mazenet Solution
Software Testing - Tool support for testing (CAST) - Mazenet SolutionSoftware Testing - Tool support for testing (CAST) - Mazenet Solution
Software Testing - Tool support for testing (CAST) - Mazenet Solution
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 
Robot Framework
Robot FrameworkRobot Framework
Robot Framework
 
Java architecture
Java architectureJava architecture
Java architecture
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
 
Sphinx + robot framework = documentation as result of functional testing
Sphinx + robot framework = documentation as result of functional testingSphinx + robot framework = documentation as result of functional testing
Sphinx + robot framework = documentation as result of functional testing
 
Basics of QTP Framework
Basics of QTP FrameworkBasics of QTP Framework
Basics of QTP Framework
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnit
 
EasyTest Test Automation Tool Introduction
EasyTest Test Automation Tool IntroductionEasyTest Test Automation Tool Introduction
EasyTest Test Automation Tool Introduction
 
UFT Automation Framework Introduction
UFT Automation Framework IntroductionUFT Automation Framework Introduction
UFT Automation Framework Introduction
 
JVM
JVMJVM
JVM
 
Lecture - 1 introduction to java
Lecture - 1 introduction to javaLecture - 1 introduction to java
Lecture - 1 introduction to java
 
Robot framework and selenium2 library
Robot framework and selenium2 libraryRobot framework and selenium2 library
Robot framework and selenium2 library
 
Python in Test automation
Python in Test automationPython in Test automation
Python in Test automation
 
Robot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs IntegrationRobot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs Integration
 
Implementing Refactorings in IntelliJ IDEA
Implementing Refactorings in IntelliJ IDEAImplementing Refactorings in IntelliJ IDEA
Implementing Refactorings in IntelliJ IDEA
 
Architecture diagram of jvm
Architecture diagram of jvmArchitecture diagram of jvm
Architecture diagram of jvm
 

Similar to Java basics training 1

Basics of Java
Basics of JavaBasics of Java
Basics of Java
Sherihan Anver
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
lokeshpappaka10
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and BytecodeYoav Avrahami
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
sureshkumara29
 
CS8392 OOP
CS8392 OOPCS8392 OOP
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
Sherihan Anver
 
Java basic
Java basicJava basic
Java basic
Pooja Thakur
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritter
Simon Ritter
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
SadhanaParameswaran
 
Java notes
Java notesJava notes
Java notes
Debasish Biswas
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
SURBHI SAROHA
 
Viva file
Viva fileViva file
Viva file
anupamasingh87
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
apoorvams
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classesyoavwix
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
zynofustechnology
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
mshanajoel6
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
Raja Sekhar
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
AnsgarMary
 

Similar to Java basics training 1 (20)

Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
Java basic
Java basicJava basic
Java basic
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritter
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
Java notes
Java notesJava notes
Java notes
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
Viva file
Viva fileViva file
Viva file
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classes
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 

More from Kushan Shalindra Amarasiri - Technical QE Specialist

Selenium test automation framework design & development
Selenium test automation framework design & developmentSelenium test automation framework design & development
Selenium test automation framework design & development
Kushan Shalindra Amarasiri - Technical QE Specialist
 
Mobile test automation in simple steps
Mobile test automation in simple stepsMobile test automation in simple steps
Mobile test automation in simple steps
Kushan Shalindra Amarasiri - Technical QE Specialist
 
Implicit and explicit waits
Implicit and explicit waitsImplicit and explicit waits
Manipulating web elements with web driver
Manipulating web elements with web driverManipulating web elements with web driver
Manipulating web elements with web driver
Kushan Shalindra Amarasiri - Technical QE Specialist
 
Test Automation Ground Up
Test Automation Ground UpTest Automation Ground Up
Test automation with trends
Test automation with trendsTest automation with trends
Testing microservices with rest assured
Testing microservices with rest assuredTesting microservices with rest assured
Testing microservices with rest assured
Kushan Shalindra Amarasiri - Technical QE Specialist
 
Protractor
ProtractorProtractor
End to end test automation with cypress
End to end test automation with cypressEnd to end test automation with cypress
End to end test automation with cypress
Kushan Shalindra Amarasiri - Technical QE Specialist
 
How to be an awesome test automation professional
How to be an awesome test automation professionalHow to be an awesome test automation professional
How to be an awesome test automation professional
Kushan Shalindra Amarasiri - Technical QE Specialist
 
Test automation within a scrum process
Test automation within a scrum processTest automation within a scrum process
Test automation within a scrum process
Kushan Shalindra Amarasiri - Technical QE Specialist
 

More from Kushan Shalindra Amarasiri - Technical QE Specialist (12)

Selenium test automation framework design & development
Selenium test automation framework design & developmentSelenium test automation framework design & development
Selenium test automation framework design & development
 
Mobile test automation in simple steps
Mobile test automation in simple stepsMobile test automation in simple steps
Mobile test automation in simple steps
 
Implicit and explicit waits
Implicit and explicit waitsImplicit and explicit waits
Implicit and explicit waits
 
Locator strategies
Locator strategiesLocator strategies
Locator strategies
 
Manipulating web elements with web driver
Manipulating web elements with web driverManipulating web elements with web driver
Manipulating web elements with web driver
 
Test Automation Ground Up
Test Automation Ground UpTest Automation Ground Up
Test Automation Ground Up
 
Test automation with trends
Test automation with trendsTest automation with trends
Test automation with trends
 
Testing microservices with rest assured
Testing microservices with rest assuredTesting microservices with rest assured
Testing microservices with rest assured
 
Protractor
ProtractorProtractor
Protractor
 
End to end test automation with cypress
End to end test automation with cypressEnd to end test automation with cypress
End to end test automation with cypress
 
How to be an awesome test automation professional
How to be an awesome test automation professionalHow to be an awesome test automation professional
How to be an awesome test automation professional
 
Test automation within a scrum process
Test automation within a scrum processTest automation within a scrum process
Test automation within a scrum process
 

Recently uploaded

Corporate Presentation Probe June 2024.pdf
Corporate Presentation Probe June 2024.pdfCorporate Presentation Probe June 2024.pdf
Corporate Presentation Probe June 2024.pdf
Probe Gold
 
2024-deutsche-bank-global-consumer-conference.pdf
2024-deutsche-bank-global-consumer-conference.pdf2024-deutsche-bank-global-consumer-conference.pdf
2024-deutsche-bank-global-consumer-conference.pdf
Sysco_Investors
 
Osisko Development - Investor Presentation - June 24
Osisko Development - Investor Presentation - June 24Osisko Development - Investor Presentation - June 24
Osisko Development - Investor Presentation - June 24
Philip Rabenok
 
一比一原版(UW毕业证)华盛顿大学毕业证成绩单专业办理
一比一原版(UW毕业证)华盛顿大学毕业证成绩单专业办理一比一原版(UW毕业证)华盛顿大学毕业证成绩单专业办理
一比一原版(UW毕业证)华盛顿大学毕业证成绩单专业办理
ybout
 
Snam 2023-27 Industrial Plan - Financial Presentation
Snam 2023-27 Industrial Plan - Financial PresentationSnam 2023-27 Industrial Plan - Financial Presentation
Snam 2023-27 Industrial Plan - Financial Presentation
Valentina Ottini
 
Collective Mining | Corporate Presentation - May 2024
Collective Mining | Corporate Presentation - May 2024Collective Mining | Corporate Presentation - May 2024
Collective Mining | Corporate Presentation - May 2024
CollectiveMining1
 
cyberagent_For New Investors_EN_240424.pdf
cyberagent_For New Investors_EN_240424.pdfcyberagent_For New Investors_EN_240424.pdf
cyberagent_For New Investors_EN_240424.pdf
CyberAgent, Inc.
 
Investor Day 2024 Presentation Sysco 2024
Investor Day 2024 Presentation Sysco 2024Investor Day 2024 Presentation Sysco 2024
Investor Day 2024 Presentation Sysco 2024
Sysco_Investors
 

Recently uploaded (8)

Corporate Presentation Probe June 2024.pdf
Corporate Presentation Probe June 2024.pdfCorporate Presentation Probe June 2024.pdf
Corporate Presentation Probe June 2024.pdf
 
2024-deutsche-bank-global-consumer-conference.pdf
2024-deutsche-bank-global-consumer-conference.pdf2024-deutsche-bank-global-consumer-conference.pdf
2024-deutsche-bank-global-consumer-conference.pdf
 
Osisko Development - Investor Presentation - June 24
Osisko Development - Investor Presentation - June 24Osisko Development - Investor Presentation - June 24
Osisko Development - Investor Presentation - June 24
 
一比一原版(UW毕业证)华盛顿大学毕业证成绩单专业办理
一比一原版(UW毕业证)华盛顿大学毕业证成绩单专业办理一比一原版(UW毕业证)华盛顿大学毕业证成绩单专业办理
一比一原版(UW毕业证)华盛顿大学毕业证成绩单专业办理
 
Snam 2023-27 Industrial Plan - Financial Presentation
Snam 2023-27 Industrial Plan - Financial PresentationSnam 2023-27 Industrial Plan - Financial Presentation
Snam 2023-27 Industrial Plan - Financial Presentation
 
Collective Mining | Corporate Presentation - May 2024
Collective Mining | Corporate Presentation - May 2024Collective Mining | Corporate Presentation - May 2024
Collective Mining | Corporate Presentation - May 2024
 
cyberagent_For New Investors_EN_240424.pdf
cyberagent_For New Investors_EN_240424.pdfcyberagent_For New Investors_EN_240424.pdf
cyberagent_For New Investors_EN_240424.pdf
 
Investor Day 2024 Presentation Sysco 2024
Investor Day 2024 Presentation Sysco 2024Investor Day 2024 Presentation Sysco 2024
Investor Day 2024 Presentation Sysco 2024
 

Java basics training 1

  • 2. Introduction to Programming Language ▪A programming language is a set of rules that provides a way of telling a computer what operations to perform ▪Generally a computer program takes an input and process the input to produce an output Input Process Output
  • 3. Different Programming Paradigms ▪Functional/procedural programming: ▫program is a list of instructions to the computer ▪Object-oriented programming ▫program is composed of a collection objects that communicate with each other
  • 4. Understand Java platform and environment ▪ JVM - Provides runtime environment in which java bytecode can be executed ▪ JRE - Provides runtime environment. Implements JVM ▪ JDK - Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the programs. Compiler Debugger Java Applet Viewer JVM rt.jar Java.exe libraries JRE JDK
  • 5. Programmed Translators ▪Some languages use both compiler and interpreter to do the translations ▪E.g. Java compiler translates a java program into a machine independent intermediate language known as JVM machine language, ▪Then the code in the JVM machine language is interpreted using a java interpreter
  • 6. Features of Java  Simple Syntax is based on C++ Not required to remove unreferenced objects since Automatic Garbage Collection is there  Portable Write Once Run Anywhere (WORA)  Object Oriented  Platform Independent Java code is compiled by the compiler and converted into bytecode. This is platform independent thus can be run on multiple platforms ▫ Multithreaded With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously.
  • 7. Prerequisites For this you should have a basic knowledge of Object Oriented Principles (OOPs). Let’s start with the basics Object A real world Entity which has a state and a behavior Class A class is a collection of Objects. It serves as a template for creating, or instantiating, specific objects within a program. E.g:- A Car class can have a model, color, manufacturedYear as state and drive, reverse as behaviours. Ferrari is a real world Object that we can create from that class
  • 8. Fundamentals of OOP ▪ Abstraction – Hiding Internal details and showing only the functionality Abstract classes, Interfaces are ways of achieving this ▪ Encapsulation – Binding and wrapping code and data together Java class (having private fields and public accessors,mutators) are an example for this ▪ Polymorphism – One task is performed in different ways Method overriding and overloading are ways to achieve this ▪ Inheritance – One object acquires all the propertiese and behaviours of a parent object - Inheritance provides code reusability and used to achieve runtime polymorphism - Java doesn’t allow multiple inheritance
  • 9. Abstraction ▪ Animals are capable of doing different things like flying, digging and walking, but there are some common operations as well like eating and sleeping. ▪ Some common operations are performed by all animals, but in a different way as well. ▪ When an operation is performed in a different way, it is a good candidate for an abstract method
  • 10. Encapsulation To achieve encapsulation in Java •Declare the variables of a class as private. •Provide public setter and getter methods to modify and view the variables values.
  • 11. Inheritance extends is the keyword used to inherit the properties of a class. Following is the syntax of extends keyword.
  • 12. Basic Structure of a Java program public class HelloWorld{ public static void main(String[] args){ System.out.println(“Hello World”); } } Access modifier Class name Method name Argument list(expects an array of String arguments)
  • 13. Few important keywords in Java ▪ Variable - A Java variable is a piece of memory that can contain a data value. A variable thus has a data type. ▪ Data Type – They further explain the kind of data that needs to be stored e.g :- int, char ▪ Literals – Source code representation of a fixed value e.g :- int age=20; ▪ Default Values – If variables are not assigned with a value then compiler will add a value automatically e.g :- default value for String is null, default value for boolean is false  Identifiers – Name of the variable  Keywords – Reserved words in java
  • 14. ▪ short ▪ byte ▪ int ▪ long ▪ double ▪ float ▪ char ▪ boolean Basic Data Types in Java Data Types Primitive Data Types Reference Data Types ▪ Objects such as String, Array, HashMap etc. ▪ Default value is null ▪ Reference can be used to access the object integer types floating points
  • 18. Decision making in java If e.g:- if(num%2 ==0){ //print even } If-else e.g:- if(num%2 ==0){ //print even } else{ //print odd } If- else if - else e.g:- if(num%2 ==0){ //print even } else if(num%2 !=0){ //print odd } else{ //print invalid input } switch e.g:- char grade=‘A’; switch(g){ case ‘A’ : //print ‘Pass’ break; case ‘F’ : //print ‘Fail’ break; default: //print ‘Invalid’ }
  • 19. Loops in Java while e.g:- int x=0; while(x<words.length){ //print words[x] x++; } do-while e.g:- int x=0; do{ //print words[x] x++; } while(x<words.length); for e.g:- for(int x=0 ; x<words.length ; x++){ //print words[x] } foreach e.g:- for(String word : words){ //print word } String words[]={“apple” , “banana”, “grapes”};
  • 20. Break and Continue keywords in Java Break e.g:- int x=0; while(x<words.length){ if(words[x].equals(“banana”)){ break; } else{ System.out.println(words[x]); } x++; } Continue e.g:- int x=0; while(x<words.length){ if(words[x].equals(“banana”)){ continue; } else{ System.out.println(words[x]); } x++; } String words[]={“apple” , “banana”, “grapes”}; apple apple grapes OUT
  • 21. Conditions and loops if/else do/while for Switch case If(x==4) { // act1 } else { // act2 } int i=5; do { // act1 i--; } while(i!=0); int j; for(int i=0;i<=9;i++) { j+=i; } char c=IN.getChar(); switch(c) { case ‘a’: case ‘b’: // act1 break; default: // act2 }
  • 22. Constructors in Java  Constructor is a special type of method that is used to initialize the object  There are rules to define a constructor - Constructor name must be as same as the class name - Must not have an explicit return type  There are two types of Constructors in Java - Default constructor - Parameterized constructor  If there is no constructor in a class, compiler will automatically create a default constructor  Defaulot construtor will set default values for class variables wheras if you want to set values of your own then go for a parameterized constructor
  • 23. Constructor Overloading in Java  A class can have any number of Constructors  Number of parameters and type of them differentiate each one another e.g:-
  • 24. Method Overloading in java  If a class have multiple methods by same name but different parameters it is known as ‘Method Overloading’  Method Overloading increaces the readability of the program  There are two ways that we can overload methods - By changing the no of arguments - By changing the data type
  • 25. Method Overloading in java… e.g:- By changing the no of arguments
  • 26. Method Overloading in java… e.g:- By changing the data type
  • 27. Method Overloading in java…  Can we overload methods by changing their return types? NO, method overloading cannot be achieved by changing the return type of the methods. e.g:- int sum(int a, int b){}; double sum(int a, int b){}; int result=sum(10,30); //Compile time error!  Can we overload main() method of a java program? YES. You can have any number of main methods in your java class through method overloading. This is achieved by changing the parameters of the main method
  • 28. Method Overloading & Type promotion One type is promoted to another type implicitly if no matching data type is found byte short int long char float double Since no method with two int arguments are found, the compiler will automatically considers the method with int, double (second int literal will be promoted to double)
  • 29. Method Overriding in Java  If subclass provides the specific implementation of the method that has been provided by one of its parent class, it is known as method overriding in java.  Method overriding is used for runtime polymorphism  Rules for method overriding in Java - Method must have the same name as in the parent class - Method must have same parameter as in the parent class - There must be an IS-A relationship (inheritance)  We can override methods by changing their return type only if their return type is covariant (subtype of the super method’s return type)
  • 30. Method Overriding in Java… Example • • run() method is overridden in Bike class with its own implementation • super keyword is used to access the parent class method • During runtime it decides which method to invoke. This is called runtime polymorphism • Static methods cannot be overridden in java • Thus main() method cannot be overridden.
  • 31. Method Overriding Vs Method Overloading Method Overloading Method Overriding Used to increase the readability of the program Used to provide the specific implementation of the method that is already provided by its super class Is performed within the class Occurs in two classes that have an IS-A relationship (Inheritance) In case of method overloading, parameter must be different In case of method overriding, parameter must be same Is an example for compile time polymorphism Is an example for runtime polymorphism In Java, method overloading cannot be performed by changing the return type. Return type must be same or different but you have to change the parameter Type must be same or Covariant in method overriding
  • 32. ‘Super’ Keyword in Java  Super is a reference variable that is used to refer immediate parent class Object  e.g:- When you create a Student object, a Person object also being created automatically.  There are three main usages of ‘super’ key word in Java Person Student
  • 33. ‘Super’ Keyword in Java… 1. ‘super’ is used to refer immediate parent class instance variable
  • 34. ‘Super’ Keyword in Java… 2. super() is used to invoke immediate parent class constructor
  • 35. ‘Super’ Keyword in Java… 3. Super is used to invoke immediate parent clas method
  • 37. Access Modifiers in Java Access Modifier Within Class Within Package private Yes No Default Yes Yes Protected Yes Yes Public Yes Yes Note that there is no keyword call Default. A variable/ method defined without any access modifier is a variable to any other classes in the same package. E.g:- the fields of an interface are implicitly public static final, the methods of an interface are by default public Can’t apply to classes and interfaces . Fields and methods that are marked as protected in a superclass, only its subclasses can access them.
  • 38. Access Modifiers in Java… Where to use protected access modifier? • If the openSpeaker() method is marked as public, then any class can access it. • If openSpeaker() method is marked as private then it is accessible only within the AudioPlayer class • To allow only its subclasses to use it, we have to mark it as protected
  • 39. Access control and Inheritance These rules must be enforced in inheritance  Methods declared public in super class must be marked as public in all of its subclasses  Methods declared protected in super class can either be marked as protected or public in its subclasses  Methods declared private are not inherited at all, so theres no rule for them.
  • 40. Arrays in Java  Java Array is an object that contains similar type of data  We can store a fixed set of elements in Java Array  Array in Java is indexed based, first element is stored at index 0. 0 1 2 3 4 indicesFirst index Array length
  • 41. Arrays in Java… Advantages of Java Array  Code optimization (we can retrieve or sort data easily)  Random Access Disadvantages  Size limit – we can store only fixed size of elements in java array. It doesn’t grow as we store elements at runtime  Types of Arrays in Java 1. Single dimensional Array 2. Multidimensional Array
  • 42. Arrays in Java… Declaration syntax for single dimensional Array dataType[] arr; dataType []arr; dataType arr[]; Declaration syntax for multi dimensional Array dataType[][] arrayRefVar; dataType [][]arrayRefVar; dataType arrayRefVar [][]; dataType []arrayRefVar [];
  • 43. Arrays in Java… Initializing Single dimensional Arrays in Java int arr; arr=new int[10]; arr[0]=23; arr[1]=54; etc… OR int arr[]={23,54}; Initializing Multi dimensional Arrays in Java int[][] arr; arr=new int[3][3]; arr[0][0]=10; arr[0][1]=30; OR Int arr[][]={{1,2,3},{4,6,7}, …};
  • 44. Final keyword final class Base { final int i=5; final void foo() { i=10; //what will the compiler say about this? } } class Derived extends Base { // Error // another foo ... void foo() { ▪final member data Constant member ▪final member function The method can’t be overridden. ▪final class ‘Base’ is final, thus it can’t be extended (ie: String class is final)