SlideShare a Scribd company logo
Quality Assurance /
Software Testing Training
Core Java for Selenium
Page 2Classification: Restricted
Agenda
• Java Fundamentals
• Introduction to Java
• Programming Language fundamentals
• Key Java Concepts
• Strings and collections
Page 3Classification: Restricted
1. Java Fundamentals
i. History of Java
ii. Features of java
iii. Introduction to OOPs
Page 4Classification: Restricted
i. History of Java
• Background: Electronic Consumer Device
• Sun Commissioned ‘Project Green’
• Developed language ‘Oak-Later renamed to Java’
• Invented by Dr.James A.Gosling and his team in 1994
• Was dismissed as just another OO programming language
• Became popular with the rising popularity of ‘www’
Page 5Classification: Restricted
ii. Features of Java
• Simple
• Robust
• Distributed
• Secure
• Portable
• Interpreted
• Multithreaded
• Portable
• Object Oriented
Page 6Classification: Restricted
Simple
• Java designed as closely to C++ as possible
• Omits many confusing and rarely used features :
No header files
Structures
Unions
Pointers
Operator overloading
Virtual base class etc..
Page 7Classification: Restricted
Robust
• Java Programs are reliable
• Early checking for potential problems
• Dynamic checking to eliminate error-prone situations.
• Developer doesn’t have to worry about
Bad Pointers
Memory Allocation Errors
Memory Leakage
Page 8Classification: Restricted
Distributed
• An application when divided into smaller units is called as distributed
system
• Extensive library support protocols like TCP/IP, HTTP & FTP
• Applications can access objects across the net with ease.
Creating socket connections
Servlets
CGI Scripting
RMI enables communication between different objects
Page 9Classification: Restricted
Platform Independence
.java file Intermediate
language code
abc.java abc.class
• Java compiler generates byte code
Platform independent
Bytecode code is an architecture-neutral file format to transport code efficiently
independent of hardware and Operating systems
The use of the same bytecode for all JVMs on all platforms
Allows Java to be described as a “compile once, run everywhere”
programming language
Source
Code
Compile
Byte
Code
Window
Linux
Mac
Page 10Classification: Restricted
Secure
• Java applications used in distributed environments require emphasis on
memory
Security Manager
Allows applications to implement a security policy before
performing a possible unsafe or sensitive operation.
ByteCode Verifier
ByteCode Verifier is responsible for verifying the byte codes.
ByteCode do not violate Java’s security restrictions.
Page 11Classification: Restricted
Portable
• Behavior of java basic types & arithmetic operators is consistent
• Java programs’s behavior is same on every platform – no data type
incompatibilities across platforms.
 int is always a 32-bit int
Strings stored in standard Unicode format
Page 12Classification: Restricted
Interpreted
• ByteCode can be executed on any machine that has java interpreter and
java run time system
• Classes are linked only on need basis
• Java is both compiled and interpreted
Page 13Classification: Restricted
iii) Object Oriented Approach
• Key concepts of object oriented programming are
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
Page 14Classification: Restricted
Abstraction
• Abstraction is the process of identifying the key aspects of an entity and
ignoring the rest
• Only those aspects are selected that are important to the current problem
scenario
• Eg) Abstraction of a person object
• Enumerate attributes of a “person object” that needs to be created for
developing a database
• Useful for social survey
• Useful for health care industry
• Useful for payroll system
Page 15Classification: Restricted
Abstraction of a Person Object
Social Survey Health Care Payroll System
Name Name Name
Age Age Age
Marital status -- --
Religion -- --
Income group -- --
Address Address Address
Occupation occupation Occupation
-- Blood group --
-- Weight --
-- Previous record --
-- -- Basic salary
-- -- Department
-- -- Qualification
Page 16Classification: Restricted
Abstraction :Process of identifying the key aspects of an entity & ignoring the
rest
Encapsulation: Ensures that data within an object is protected and accessed
only by its methods
Page 17Classification: Restricted
Encapsulation
• Encapsulation is a mechanism used to hide the data, internal structure and
implementation details of an object
• All interaction with the object is through the public interface of operations
• The user knows only about the interface, any changes to the
implementation does not affect the user
Methods
Variables
Page 18Classification: Restricted
What is an Object?
• An entity is an entity which has a well defined structure and behaviour.
An object possesses certain characteristics as:
• State
• Behavior
• Identity
Page 19Classification: Restricted
State of an Object
• The state of an object includes the current values of all its attributes.
• An attribute can be static or dynamic
• Employee Attributes
empid
name static
gender
Age
Address
Phone
Basicsal dynamic
Education
experience
Page 20Classification: Restricted
Behavior of the Object
• Behavior is how an object acts and reacts, in terms of its changes and
message passing
Employee as an object
calculateSalary
printDetails Employee
Totality of operations – how an employee behaves or
responds to, is the behavior of the person.
Page 21Classification: Restricted
Identity of an Object
• Identity is that property of an object which distinguishes it from all other
objects
• A single or a group of attributes can be an identity of an object
Employee
empId
Name
Gender
Phone
Age
Address
Phone
Basicsal
Education
empId uniquely
identifies a person
among others
Page 22Classification: Restricted
Person as an Object
Attributes State Identity Behavior
empID empId = 10 empId = 10 Swipe Card
Name Name =
“Dhruv”
Fill TimeSheet
Gender Gender =
“male”
Wear Icard
Age Age=27 Calculate
Salary
Address Address =
“pune”
Print details
Phone Phone =
2342432
basicSalary basicSalary=80
00
Education
experience
Page 23Classification: Restricted
Inheritance
• Classification helps in handling complexity
• Inheritance is the process by which one object acquire the properties of
another object
• “is a ”kind of hierarchy
Person
Employee
Wage
Employee Manager
Sales Person
Page 24Classification: Restricted
Inheritance
• Generalization
Factoring out common elements within a set of categories into a more
general category called super class.
Requires good skill of abstraction
• Specialization
Allows to capture specific features of a set of objects.
Requires a depth of knowledge of domain.
Page 25Classification: Restricted
Polymorphism
• The ability of different types of related objects to respond to the same
message in their own ways is called polymorphism
• Polymorphism helps to design extensible software, as new objects can be
added to the design without rewriting existing procedures
Page 26Classification: Restricted
Polymorphism: same method having different implementations
• Compile/ static polymorphism – by function overloading
• Run time polymorphism – by function overriding
Page 27Classification: Restricted
2. Introduction to Java
i. Compilation & execution of Java Program
ii. JDK, JVM & JRE
iii. Class & Object
iv. Access Modifiers
v. Data type
vi. Java class syntax
Page 28Classification: Restricted
i) Compilation & Execution of Java Program
.java file
Java Class libraries
JDK
JRE
Source
code
compiler Byte
code
Class
loader
ByteCode verifier
Interpreter
Native OS
JVM
awt net rmii/o
Page 29Classification: Restricted
ii) JDK, JVM and JRE
• JDK (Java Development Kit)
Comes along with standard class libraries and JVM embedded in it.
Contains software development tools such as a compiler or a debugger
which are used to compile and run the Java program.
• JRE(Java Runtime Environment)
It is an implementation of JVM, which actually executes the Java program
JRE provides some standard libraries and the JVM which can be used to
execute the java program
• JVM(Java Virtual Machine)
• JVM loads the appropriate class files for execution the java program and
then execute it
• JVM is a :
- Abstract specification
- A concrete implementation or
- A runtime instance
Page 30Classification: Restricted
iii) Anatomy of JAVA class
• The term ‘class’ comes from the word called ‘classification’
• A class is a template for creation of like objects
• An object is an instance of class
• Classes are used to map real world entities into data members and member
functions
• By writing a class and creating objects of the class one can map two key
concepts of major pillars of object msodel i.e. Abstraction and
Encapsulation
Page 31Classification: Restricted
Class: A class is a template for the creation of like objects
Page 32Classification: Restricted
Page 33Classification: Restricted
iv) Access Modifiers
• Access modifiers allow to specify the scope of the class members. We use
access modifiers to define the access control for classes, methods and
variables
• Access modifiers are of 4 types:
private – is accessible only within class
default – if we don’t specify any modifier then it is treated as default, this
can be accessible only within package
protected – is accessible within package , outside of the package but
through inheritance only
public – is accessible anywhere
• Non Access Modifiers
Static
Final : more like constant in C
Page 34Classification: Restricted
Modifier Within
Class
Within
Package
Outside of
Package
(By Sub
Class)
Outside of
Package
Private Y N N N
default Y Y N N
protected Y Y Y N
public Y Y Y Y
Page 35Classification: Restricted
v) Data Types : Is the classification of the type of data that variable can hold
in computer programming
Primitive Data Type
Boolean
Type
Numeric
Type
boolean
Integral
Type
Floating
Point Type
float double
Characte
r Type
Integer
Type
char longbyte short int
Page 36Classification: Restricted
vi) Java Class Syntax
By Convention:
class Class_Name class name starts with capital case
{ e.g. class MySample
variable_Declaration;
variable(attribute or property)
method_Declaration() { name starts with small case
….. e.g. int date
…..
}
public static void main(String args[]) Method(behavior) name starts with
{ first word small case then next
…. Words 1st letter capital case called
…. Camel case
} //end of class e.g. void printDate() {
}
Page 37Classification: Restricted
First Java Class
/* This is a comment */
//This is another comment
class MyDate
{ private int day, month, year; //variable
public void initDate() //method 1
{
day = 30;
month = 6;
year =2011;
}
public void printDate() //method 2
{
System.out.println(“Date is:” + day +”/” + month +”/” +year);
}
Page 38Classification: Restricted
Create an Object
//continuation
public static void main(String args[])
{
MyDate d = new MyDate();
//method invocation
d.initDate();
d.printDate();
}
}
Page 39Classification: Restricted
3. Language Fundamentals
i. Operators in Java
ii. Conditional & Loop statements
iii. Arrays in Java
iv. Exception handling
v. File handling
Page 40Classification: Restricted
i) Operators
• Arithmetic operators
Addition, Subtraction, Multiplication, Division, Modulus, Increment,
Decrement
• Relational operators
== , != , > , >= , < , <=
• Logical operators
Logical Not Operator !
Logical AND Operator &&
Logical OR Operator ||
• Assignment operators
=
Page 41Classification: Restricted
ii) Java Conditional & Loop statements
• Single Conditional statements
if(a>b) {
..
}
• Compound Conditional statements
If((a>b) && (a<c)) {
..
}
• Nested Conditions
if(a<b) {
if(a<c) {
if(a>b) {
}
}
}
• Java Switch statement : executes one statement from multiple conditions.
Page 42Classification: Restricted
Loop Statements
• Loop statements are used to iterate a part of the program several times.
• Three types of loops
For loop
for(initialization ; condition ;incr / decr){
//code to be executed
}
While loop
while(condition){
//code to be executed
}
Do.. While loop
do{
//code to be executed
}while(condition);
Page 43Classification: Restricted
Break, Continue & Comments
• Break statement
The Java break is used to break loop or switch statement. It breaks the
current flow of the program at specified condition. In case of inner loop, it
breaks only inner loop.
• Continue statement
The Java continue statement is used to continue loop. It continues the
current flow of the program and skips the remaining code at specified
condition. In case of inner loop, it continues only inner loop.
Comments in Java:
The java comments are statements that are not executed by the compiler
and interpreter. The comments can be used to provide information or
explanation about the variable, method, class or any statement. It can also
be used to hide program code for specific time.
Page 44Classification: Restricted
iii) Arrays in Java
Normally, array is a collection of similar type of elements that have
contiguous memory location. Java array is an object the contains elements
of similar data type
• Advantage:
Code Optimization
Random access
• Disadvantage:
Size limit
Types of Array:
• Single dimensional
• Multi dimensional
Page 45Classification: Restricted
iv. Exception Handling
• There is no perfect world
• Errors are inevitable
• Errors are shipped even with the best software
• Occur due to
Wrong input
Error on platform or system not configured
Program bugs
• Occur when the software is operational
Page 46Classification: Restricted
Types of Errors
• Logical Errors
Counter not incremented in the while loop
Wrong expression written, resulting in incorrect output
• Run time Errors
Division by Zero
Array out of bounds
Dynamic memory allocation failed
File not found
File is corrupt
Page 47Classification: Restricted
v) File Handling in Java
• High level operations/External operation
Create a folder
Delete a folder
Create a text file
Delete a text file
• Low level operations/ Internal operation
Read data from a file
Write data to a file
Page 48Classification: Restricted
4. Key Java Concepts
i. Constructor
ii. Method overloading
iii. Method overriding
iv. Abstract Class
v. Interface
Page 49Classification: Restricted
i) Constructor
• A constructor is used to initialize a newly created object
• It is implicitly invoked just after the memory is allocated for the object
using ‘new’ keyword
• It is a special method with same name as it’s class name
• No return type for constructor. Not even void
• A constructor without input parameter is default constructor
• Constructor can be overloaded
Page 50Classification: Restricted
ii) Method Overloading
• Reusing the same name for method
• The method calls are resolved at compile time using
method signature.
• Compile time error occurs if compiler cannot match the arguments or if
more than one match is possible
• Method signature consists of
Number of arguments passed to a function
Data types of arguments
Sequence in which they are passed
Page 51Classification: Restricted
Sample Program
class MathEngine
{
public int add(int num1, int num2)
{
….
}
public int add(int num1, int num2, int num3)
{
…
}
}
class Program
{
public static void main(String args[])
{
MathEngine obj = new MathEngine();
int result = obj.add(12,13);
int output = obj.add(15,16,17);
}
}
Page 52Classification: Restricted
iii) Method Overriding
• Polymorphism is achieved using overriding functions using inheritance
• It gives ability to define a behavior that’s specific to the sub class type
based on its requirements
• The version of a method that is executed will be determined by the object
that is used to invoke a method
Parent object ---- > parent method
Child object ----- > child method
Page 53Classification: Restricted
vi) Concrete and Abstract Class
• Concrete class
A class which describes the functionality of an object
It can be instantiated
• Abstract class
A class which contains generic non implemented methods.
Descendant classes comes up with the implementation for those methods in
their own ways
It can contain abstract as well as non abstract methods
Abstract methods do not have implementation
Implementation is left to the inheriting sub classes
Cannot be instantiated
Page 54Classification: Restricted
v) Interface
• An interface defines a contract between a provider and a consumer.
• Enables common design even across those classes not in hierarchy
• Defines a standard set of properties, methods and events.
• Any class implementing an interface has to provide the functionality
Interface
(Some
common
design)
Provider
class
Consumer
class
Implemented
by
Used
by
contract
Page 55Classification: Restricted
Features of an Interface
• Interface is essentially a collection of constants and abstract methods
• The interface approach is sometimes known as “programming by contract”
• Data members in an interface are always public, static and final
• A sub class can only have a single superclass in java but a class can
implement any number of interfaces
• If a class implements an interface then have to implement all the methods
of it.
Page 56Classification: Restricted
6. Strings And Collections
i. String Class – StringBuffer & StringBuilder
ii. Generics & collection
Page 57Classification: Restricted
String class
• Java library contains a predefined class called as String.
• The String type is not a primitive type.
• But in certain cases Java treats it like one
• The ability to declare String literals instead of using new to instantiate a
copy of the class
String s = “seed”
• String is the “First class object”
Page 58Classification: Restricted
String Class
• String class represents an “immutable” string.
• ie. Once an instance is created, the string it contains can not be changed.
• To change the String referenced by a string variable, you throw away the
old string and replace it with the modified one.
“Bye”
“Hello”
New String
Old
String
Page 59Classification: Restricted
StringBuffer Class
• StringBuffer class allows to create “mutable” strings
• It reallocates memory of a given length to accommodate changes within a
same object
• StringBuffer is thread safe
• The buffer grows automatically as characters are added.
Eg StringBuffer sb = new StringBuffer();
Page 60Classification: Restricted
StringBuilder Class
• StringBuilder is introduced in Java 5.0 version.
• This is just an alternative to StringBuffer class.
• There is no difference between StringBuffer and StringBuilder
• Methods of StringBuilder class are not thread safe
• Recommended for faster applications.
Page 61Classification: Restricted
Why collections?
• Array size is fixed. Size cannot be increased dynamically.
• In actual development scenario, same type of objects need to be
processed.
• Data is obtained from data source like files or database.
Page 62Classification: Restricted
Collection – Interface hierarchy Java7
Collection
List Queue Set Map
Deque
Navigable
Set
SortedSet
NavigableMap
SortedMap
Iterator
Page 63Classification: Restricted
Collection Interfaces
• Allow collections to support a different browser
Interface Description
List Represents a collection of objects
that is accessed by an index. An
ordered collection
Set Represents a collection that contains
no duplicate elements. An order is
not fixed
Map Represents a collection of key- value
pairs
Queue Represents a collection designed for
holding elements prior to processing
Iterator Supports a simple iteration over
collection
Comparator Comparison function which imposes
a total ordering on some collection
of objects
Page 64Classification: Restricted
List Interface
• Ordered Collection
• May contain duplicates
• Implemented by classes
-- ArrayList [Resizable – array implementation of the List interface]
-- LinkedList [Doubly linked list implementation of the list]
--Vector [the Vector class implements a growable array of objects]
Page 65Classification: Restricted
Set Interface
• Collection of unique elements
• No duplicate elements allowed
• Collection not in any particular order (random)
• Implemented by the Hashset
Page 66Classification: Restricted
Thank You

More Related Content

PPSX
PPTX
JIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosys
PPTX
Jira fundamentals
PPTX
Jira as a Tool for Test Management
PDF
JIRA_Manual_Vol.1
PPTX
Jira Basic Concepts
PPTX
Jira overview
PPTX
Jira training
JIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosys
Jira fundamentals
Jira as a Tool for Test Management
JIRA_Manual_Vol.1
Jira Basic Concepts
Jira overview
Jira training

What's hot (20)

PDF
Structure plug-in introduction for JIRA
PPTX
Agile Software Development with JIRA and Confluence
PDF
Introduction To Jira
PPTX
Jira in action
PPTX
PPTX
Scrum Project Management with Jira as showcase
PDF
Wikidsmart PM: Requirements Management within Confluence, Integrated with JIRA
PDF
PPTX
Jira administration Trantor
PPTX
Application Lifecycle Management with Visual Studio 2013
PPTX
VSO & JIRA Project Management Tool
PPTX
ALM iStack - Application Lifecycle Management using Linked Data
PDF
Introduction to Jira - Bug Tracking tool
PPT
Introduction to jira
PPTX
Jira software 8.0 8.5 community presentation
PPT
Introduction To Jira Slide Share
PDF
Jira as a Project Management Tool
PDF
PantaRei Design Limited - JIRA Software Introduction - Project - Workflow - D...
Structure plug-in introduction for JIRA
Agile Software Development with JIRA and Confluence
Introduction To Jira
Jira in action
Scrum Project Management with Jira as showcase
Wikidsmart PM: Requirements Management within Confluence, Integrated with JIRA
Jira administration Trantor
Application Lifecycle Management with Visual Studio 2013
VSO & JIRA Project Management Tool
ALM iStack - Application Lifecycle Management using Linked Data
Introduction to Jira - Bug Tracking tool
Introduction to jira
Jira software 8.0 8.5 community presentation
Introduction To Jira Slide Share
Jira as a Project Management Tool
PantaRei Design Limited - JIRA Software Introduction - Project - Workflow - D...
Ad

Similar to Core Java for Selenium (20)

PPT
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
PDF
‏‏oop lecture 2 taiz univercity object programming.pdf
PPTX
PPTX
Basic Concepts of Object Oriented Programming
PPTX
Introduction to OOP concepts
PPTX
Presentation2.ppt java basic core ppt .
PPTX
Object Oriented Programming
PPTX
Untitled presentation about object oriented.pptx
PDF
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
PPTX
2CPP09 - Encapsulation
PPTX
Object Oriented Programming - Cheat sheet.pptx
DOC
Questpond - Top 10 Interview Questions and Answers on OOPS
PPTX
UNIT IV DESIGN PATTERNS.pptx
PPTX
Need of object oriented programming
PPTX
1_Object Oriented Programming.pptx
PPT
Java Hibernate Basics
PPT
Hibernate basics
PPT
Unit 1- Basic concept of object-oriented-programming.ppt
PPT
Java OOP s concepts and buzzwords
PPTX
Introduction to Java
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
‏‏oop lecture 2 taiz univercity object programming.pdf
Basic Concepts of Object Oriented Programming
Introduction to OOP concepts
Presentation2.ppt java basic core ppt .
Object Oriented Programming
Untitled presentation about object oriented.pptx
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
2CPP09 - Encapsulation
Object Oriented Programming - Cheat sheet.pptx
Questpond - Top 10 Interview Questions and Answers on OOPS
UNIT IV DESIGN PATTERNS.pptx
Need of object oriented programming
1_Object Oriented Programming.pptx
Java Hibernate Basics
Hibernate basics
Unit 1- Basic concept of object-oriented-programming.ppt
Java OOP s concepts and buzzwords
Introduction to Java
Ad

More from Rajathi-QA (7)

PPSX
HP ALM
PPSX
Selenium WebDriver
PPSX
Quick Test Professional (QTP/UFT)
PPSX
Other Testing Types
PPSX
Introduction to Software Testing
PPSX
Defects and Categories
PPSX
Test Execution
HP ALM
Selenium WebDriver
Quick Test Professional (QTP/UFT)
Other Testing Types
Introduction to Software Testing
Defects and Categories
Test Execution

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
KodekX | Application Modernization Development
PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Spectroscopy.pptx food analysis technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Per capita expenditure prediction using model stacking based on satellite ima...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KodekX | Application Modernization Development
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Spectroscopy.pptx food analysis technology
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
Advanced methodologies resolving dimensionality complications for autism neur...

Core Java for Selenium

  • 1. Quality Assurance / Software Testing Training Core Java for Selenium
  • 2. Page 2Classification: Restricted Agenda • Java Fundamentals • Introduction to Java • Programming Language fundamentals • Key Java Concepts • Strings and collections
  • 3. Page 3Classification: Restricted 1. Java Fundamentals i. History of Java ii. Features of java iii. Introduction to OOPs
  • 4. Page 4Classification: Restricted i. History of Java • Background: Electronic Consumer Device • Sun Commissioned ‘Project Green’ • Developed language ‘Oak-Later renamed to Java’ • Invented by Dr.James A.Gosling and his team in 1994 • Was dismissed as just another OO programming language • Became popular with the rising popularity of ‘www’
  • 5. Page 5Classification: Restricted ii. Features of Java • Simple • Robust • Distributed • Secure • Portable • Interpreted • Multithreaded • Portable • Object Oriented
  • 6. Page 6Classification: Restricted Simple • Java designed as closely to C++ as possible • Omits many confusing and rarely used features : No header files Structures Unions Pointers Operator overloading Virtual base class etc..
  • 7. Page 7Classification: Restricted Robust • Java Programs are reliable • Early checking for potential problems • Dynamic checking to eliminate error-prone situations. • Developer doesn’t have to worry about Bad Pointers Memory Allocation Errors Memory Leakage
  • 8. Page 8Classification: Restricted Distributed • An application when divided into smaller units is called as distributed system • Extensive library support protocols like TCP/IP, HTTP & FTP • Applications can access objects across the net with ease. Creating socket connections Servlets CGI Scripting RMI enables communication between different objects
  • 9. Page 9Classification: Restricted Platform Independence .java file Intermediate language code abc.java abc.class • Java compiler generates byte code Platform independent Bytecode code is an architecture-neutral file format to transport code efficiently independent of hardware and Operating systems The use of the same bytecode for all JVMs on all platforms Allows Java to be described as a “compile once, run everywhere” programming language Source Code Compile Byte Code Window Linux Mac
  • 10. Page 10Classification: Restricted Secure • Java applications used in distributed environments require emphasis on memory Security Manager Allows applications to implement a security policy before performing a possible unsafe or sensitive operation. ByteCode Verifier ByteCode Verifier is responsible for verifying the byte codes. ByteCode do not violate Java’s security restrictions.
  • 11. Page 11Classification: Restricted Portable • Behavior of java basic types & arithmetic operators is consistent • Java programs’s behavior is same on every platform – no data type incompatibilities across platforms.  int is always a 32-bit int Strings stored in standard Unicode format
  • 12. Page 12Classification: Restricted Interpreted • ByteCode can be executed on any machine that has java interpreter and java run time system • Classes are linked only on need basis • Java is both compiled and interpreted
  • 13. Page 13Classification: Restricted iii) Object Oriented Approach • Key concepts of object oriented programming are • Abstraction • Encapsulation • Inheritance • Polymorphism
  • 14. Page 14Classification: Restricted Abstraction • Abstraction is the process of identifying the key aspects of an entity and ignoring the rest • Only those aspects are selected that are important to the current problem scenario • Eg) Abstraction of a person object • Enumerate attributes of a “person object” that needs to be created for developing a database • Useful for social survey • Useful for health care industry • Useful for payroll system
  • 15. Page 15Classification: Restricted Abstraction of a Person Object Social Survey Health Care Payroll System Name Name Name Age Age Age Marital status -- -- Religion -- -- Income group -- -- Address Address Address Occupation occupation Occupation -- Blood group -- -- Weight -- -- Previous record -- -- -- Basic salary -- -- Department -- -- Qualification
  • 16. Page 16Classification: Restricted Abstraction :Process of identifying the key aspects of an entity & ignoring the rest Encapsulation: Ensures that data within an object is protected and accessed only by its methods
  • 17. Page 17Classification: Restricted Encapsulation • Encapsulation is a mechanism used to hide the data, internal structure and implementation details of an object • All interaction with the object is through the public interface of operations • The user knows only about the interface, any changes to the implementation does not affect the user Methods Variables
  • 18. Page 18Classification: Restricted What is an Object? • An entity is an entity which has a well defined structure and behaviour. An object possesses certain characteristics as: • State • Behavior • Identity
  • 19. Page 19Classification: Restricted State of an Object • The state of an object includes the current values of all its attributes. • An attribute can be static or dynamic • Employee Attributes empid name static gender Age Address Phone Basicsal dynamic Education experience
  • 20. Page 20Classification: Restricted Behavior of the Object • Behavior is how an object acts and reacts, in terms of its changes and message passing Employee as an object calculateSalary printDetails Employee Totality of operations – how an employee behaves or responds to, is the behavior of the person.
  • 21. Page 21Classification: Restricted Identity of an Object • Identity is that property of an object which distinguishes it from all other objects • A single or a group of attributes can be an identity of an object Employee empId Name Gender Phone Age Address Phone Basicsal Education empId uniquely identifies a person among others
  • 22. Page 22Classification: Restricted Person as an Object Attributes State Identity Behavior empID empId = 10 empId = 10 Swipe Card Name Name = “Dhruv” Fill TimeSheet Gender Gender = “male” Wear Icard Age Age=27 Calculate Salary Address Address = “pune” Print details Phone Phone = 2342432 basicSalary basicSalary=80 00 Education experience
  • 23. Page 23Classification: Restricted Inheritance • Classification helps in handling complexity • Inheritance is the process by which one object acquire the properties of another object • “is a ”kind of hierarchy Person Employee Wage Employee Manager Sales Person
  • 24. Page 24Classification: Restricted Inheritance • Generalization Factoring out common elements within a set of categories into a more general category called super class. Requires good skill of abstraction • Specialization Allows to capture specific features of a set of objects. Requires a depth of knowledge of domain.
  • 25. Page 25Classification: Restricted Polymorphism • The ability of different types of related objects to respond to the same message in their own ways is called polymorphism • Polymorphism helps to design extensible software, as new objects can be added to the design without rewriting existing procedures
  • 26. Page 26Classification: Restricted Polymorphism: same method having different implementations • Compile/ static polymorphism – by function overloading • Run time polymorphism – by function overriding
  • 27. Page 27Classification: Restricted 2. Introduction to Java i. Compilation & execution of Java Program ii. JDK, JVM & JRE iii. Class & Object iv. Access Modifiers v. Data type vi. Java class syntax
  • 28. Page 28Classification: Restricted i) Compilation & Execution of Java Program .java file Java Class libraries JDK JRE Source code compiler Byte code Class loader ByteCode verifier Interpreter Native OS JVM awt net rmii/o
  • 29. Page 29Classification: Restricted ii) JDK, JVM and JRE • JDK (Java Development Kit) Comes along with standard class libraries and JVM embedded in it. Contains software development tools such as a compiler or a debugger which are used to compile and run the Java program. • JRE(Java Runtime Environment) It is an implementation of JVM, which actually executes the Java program JRE provides some standard libraries and the JVM which can be used to execute the java program • JVM(Java Virtual Machine) • JVM loads the appropriate class files for execution the java program and then execute it • JVM is a : - Abstract specification - A concrete implementation or - A runtime instance
  • 30. Page 30Classification: Restricted iii) Anatomy of JAVA class • The term ‘class’ comes from the word called ‘classification’ • A class is a template for creation of like objects • An object is an instance of class • Classes are used to map real world entities into data members and member functions • By writing a class and creating objects of the class one can map two key concepts of major pillars of object msodel i.e. Abstraction and Encapsulation
  • 31. Page 31Classification: Restricted Class: A class is a template for the creation of like objects
  • 33. Page 33Classification: Restricted iv) Access Modifiers • Access modifiers allow to specify the scope of the class members. We use access modifiers to define the access control for classes, methods and variables • Access modifiers are of 4 types: private – is accessible only within class default – if we don’t specify any modifier then it is treated as default, this can be accessible only within package protected – is accessible within package , outside of the package but through inheritance only public – is accessible anywhere • Non Access Modifiers Static Final : more like constant in C
  • 34. Page 34Classification: Restricted Modifier Within Class Within Package Outside of Package (By Sub Class) Outside of Package Private Y N N N default Y Y N N protected Y Y Y N public Y Y Y Y
  • 35. Page 35Classification: Restricted v) Data Types : Is the classification of the type of data that variable can hold in computer programming Primitive Data Type Boolean Type Numeric Type boolean Integral Type Floating Point Type float double Characte r Type Integer Type char longbyte short int
  • 36. Page 36Classification: Restricted vi) Java Class Syntax By Convention: class Class_Name class name starts with capital case { e.g. class MySample variable_Declaration; variable(attribute or property) method_Declaration() { name starts with small case ….. e.g. int date ….. } public static void main(String args[]) Method(behavior) name starts with { first word small case then next …. Words 1st letter capital case called …. Camel case } //end of class e.g. void printDate() { }
  • 37. Page 37Classification: Restricted First Java Class /* This is a comment */ //This is another comment class MyDate { private int day, month, year; //variable public void initDate() //method 1 { day = 30; month = 6; year =2011; } public void printDate() //method 2 { System.out.println(“Date is:” + day +”/” + month +”/” +year); }
  • 38. Page 38Classification: Restricted Create an Object //continuation public static void main(String args[]) { MyDate d = new MyDate(); //method invocation d.initDate(); d.printDate(); } }
  • 39. Page 39Classification: Restricted 3. Language Fundamentals i. Operators in Java ii. Conditional & Loop statements iii. Arrays in Java iv. Exception handling v. File handling
  • 40. Page 40Classification: Restricted i) Operators • Arithmetic operators Addition, Subtraction, Multiplication, Division, Modulus, Increment, Decrement • Relational operators == , != , > , >= , < , <= • Logical operators Logical Not Operator ! Logical AND Operator && Logical OR Operator || • Assignment operators =
  • 41. Page 41Classification: Restricted ii) Java Conditional & Loop statements • Single Conditional statements if(a>b) { .. } • Compound Conditional statements If((a>b) && (a<c)) { .. } • Nested Conditions if(a<b) { if(a<c) { if(a>b) { } } } • Java Switch statement : executes one statement from multiple conditions.
  • 42. Page 42Classification: Restricted Loop Statements • Loop statements are used to iterate a part of the program several times. • Three types of loops For loop for(initialization ; condition ;incr / decr){ //code to be executed } While loop while(condition){ //code to be executed } Do.. While loop do{ //code to be executed }while(condition);
  • 43. Page 43Classification: Restricted Break, Continue & Comments • Break statement The Java break is used to break loop or switch statement. It breaks the current flow of the program at specified condition. In case of inner loop, it breaks only inner loop. • Continue statement The Java continue statement is used to continue loop. It continues the current flow of the program and skips the remaining code at specified condition. In case of inner loop, it continues only inner loop. Comments in Java: The java comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement. It can also be used to hide program code for specific time.
  • 44. Page 44Classification: Restricted iii) Arrays in Java Normally, array is a collection of similar type of elements that have contiguous memory location. Java array is an object the contains elements of similar data type • Advantage: Code Optimization Random access • Disadvantage: Size limit Types of Array: • Single dimensional • Multi dimensional
  • 45. Page 45Classification: Restricted iv. Exception Handling • There is no perfect world • Errors are inevitable • Errors are shipped even with the best software • Occur due to Wrong input Error on platform or system not configured Program bugs • Occur when the software is operational
  • 46. Page 46Classification: Restricted Types of Errors • Logical Errors Counter not incremented in the while loop Wrong expression written, resulting in incorrect output • Run time Errors Division by Zero Array out of bounds Dynamic memory allocation failed File not found File is corrupt
  • 47. Page 47Classification: Restricted v) File Handling in Java • High level operations/External operation Create a folder Delete a folder Create a text file Delete a text file • Low level operations/ Internal operation Read data from a file Write data to a file
  • 48. Page 48Classification: Restricted 4. Key Java Concepts i. Constructor ii. Method overloading iii. Method overriding iv. Abstract Class v. Interface
  • 49. Page 49Classification: Restricted i) Constructor • A constructor is used to initialize a newly created object • It is implicitly invoked just after the memory is allocated for the object using ‘new’ keyword • It is a special method with same name as it’s class name • No return type for constructor. Not even void • A constructor without input parameter is default constructor • Constructor can be overloaded
  • 50. Page 50Classification: Restricted ii) Method Overloading • Reusing the same name for method • The method calls are resolved at compile time using method signature. • Compile time error occurs if compiler cannot match the arguments or if more than one match is possible • Method signature consists of Number of arguments passed to a function Data types of arguments Sequence in which they are passed
  • 51. Page 51Classification: Restricted Sample Program class MathEngine { public int add(int num1, int num2) { …. } public int add(int num1, int num2, int num3) { … } } class Program { public static void main(String args[]) { MathEngine obj = new MathEngine(); int result = obj.add(12,13); int output = obj.add(15,16,17); } }
  • 52. Page 52Classification: Restricted iii) Method Overriding • Polymorphism is achieved using overriding functions using inheritance • It gives ability to define a behavior that’s specific to the sub class type based on its requirements • The version of a method that is executed will be determined by the object that is used to invoke a method Parent object ---- > parent method Child object ----- > child method
  • 53. Page 53Classification: Restricted vi) Concrete and Abstract Class • Concrete class A class which describes the functionality of an object It can be instantiated • Abstract class A class which contains generic non implemented methods. Descendant classes comes up with the implementation for those methods in their own ways It can contain abstract as well as non abstract methods Abstract methods do not have implementation Implementation is left to the inheriting sub classes Cannot be instantiated
  • 54. Page 54Classification: Restricted v) Interface • An interface defines a contract between a provider and a consumer. • Enables common design even across those classes not in hierarchy • Defines a standard set of properties, methods and events. • Any class implementing an interface has to provide the functionality Interface (Some common design) Provider class Consumer class Implemented by Used by contract
  • 55. Page 55Classification: Restricted Features of an Interface • Interface is essentially a collection of constants and abstract methods • The interface approach is sometimes known as “programming by contract” • Data members in an interface are always public, static and final • A sub class can only have a single superclass in java but a class can implement any number of interfaces • If a class implements an interface then have to implement all the methods of it.
  • 56. Page 56Classification: Restricted 6. Strings And Collections i. String Class – StringBuffer & StringBuilder ii. Generics & collection
  • 57. Page 57Classification: Restricted String class • Java library contains a predefined class called as String. • The String type is not a primitive type. • But in certain cases Java treats it like one • The ability to declare String literals instead of using new to instantiate a copy of the class String s = “seed” • String is the “First class object”
  • 58. Page 58Classification: Restricted String Class • String class represents an “immutable” string. • ie. Once an instance is created, the string it contains can not be changed. • To change the String referenced by a string variable, you throw away the old string and replace it with the modified one. “Bye” “Hello” New String Old String
  • 59. Page 59Classification: Restricted StringBuffer Class • StringBuffer class allows to create “mutable” strings • It reallocates memory of a given length to accommodate changes within a same object • StringBuffer is thread safe • The buffer grows automatically as characters are added. Eg StringBuffer sb = new StringBuffer();
  • 60. Page 60Classification: Restricted StringBuilder Class • StringBuilder is introduced in Java 5.0 version. • This is just an alternative to StringBuffer class. • There is no difference between StringBuffer and StringBuilder • Methods of StringBuilder class are not thread safe • Recommended for faster applications.
  • 61. Page 61Classification: Restricted Why collections? • Array size is fixed. Size cannot be increased dynamically. • In actual development scenario, same type of objects need to be processed. • Data is obtained from data source like files or database.
  • 62. Page 62Classification: Restricted Collection – Interface hierarchy Java7 Collection List Queue Set Map Deque Navigable Set SortedSet NavigableMap SortedMap Iterator
  • 63. Page 63Classification: Restricted Collection Interfaces • Allow collections to support a different browser Interface Description List Represents a collection of objects that is accessed by an index. An ordered collection Set Represents a collection that contains no duplicate elements. An order is not fixed Map Represents a collection of key- value pairs Queue Represents a collection designed for holding elements prior to processing Iterator Supports a simple iteration over collection Comparator Comparison function which imposes a total ordering on some collection of objects
  • 64. Page 64Classification: Restricted List Interface • Ordered Collection • May contain duplicates • Implemented by classes -- ArrayList [Resizable – array implementation of the List interface] -- LinkedList [Doubly linked list implementation of the list] --Vector [the Vector class implements a growable array of objects]
  • 65. Page 65Classification: Restricted Set Interface • Collection of unique elements • No duplicate elements allowed • Collection not in any particular order (random) • Implemented by the Hashset