SlideShare a Scribd company logo
What are Generics in Java | Java Generics Tutorial | Edureka
WHAT IS GENERICS IN JAVA?
TYPES OF JAVA GENERICS
GENERIC FUNCTIONS
ADVANTAGES OF GENERICS IN JAVA
WHY GENERICS?
www.edureka.co/java-j2ee-soa-training
www.edureka.co/java-j2ee-soa-training
WHAT IS GENERICS IN JAVA?
Generics is a term that denotes a set of
language features related to the definition and
use of Generic types and methods.
www.edureka.co/java-j2ee-soa-training
www.edureka.co/java-j2ee-soa-training
WHY JAVA GENERICS?
www.edureka.co/java-j2ee-soa-training
TYPES OF JAVA GENERICS
www.edureka.co/java-j2ee-soa-training
TYPES OF
JAVA
GENERICS
Generic Type Class
class Genericclass{
private Object x;
public void set(Object x) { this.x = x; }
public Object get() { return x; }
}
www.edureka.co/java-j2ee-soa-training
TYPES OF
JAVA
GENERICS
Generic Type Interface
interface GenericInterface<T1, T2>
{
T2 PerformExecution(T1 x);
T1 ReverseExecution(T2 x); }
class Genericclass implements
GenericInterface<String, Integer> {
public Integer PerformExecution(String x)
{//execution code }
public String ReverseExecution(Integer x)
{ //execution code }
}
www.edureka.co/java-j2ee-soa-training
TYPES OF
JAVA
GENERICS
Generic Type Method
public static <T> int countAllOccurrences(T[]
list, T element) {
int count = 0;
if (element == null) {
for ( T listElement : list )
if (listElement == null)
count++;
}
else {
for ( T listElement : list )
if (element.equals(listElement))
count++;
}
return count;
}
www.edureka.co/java-j2ee-soa-training
TYPES OF
JAVA
GENERICS
Generic Type Constructor
class Dimension<T> {
private T length;
private T width;
private T height; }
public Dimension(T length, T width, T height){
super();
this.length = length;
this.width = width;
this.height = height;
}
www.edureka.co/java-j2ee-soa-training
GENERIC FUNCTIONS
www.edureka.co/java-j2ee-soa-training
GENERIC FUNCTIONS
We can also write generic functions that can be
called with different types of arguments based
on the type of arguments passed to generic
method, & further the compiler handles each
method.
www.edureka.co/java-j2ee-soa-training
www.edureka.co/java-j2ee-soa-training
ADVANTAGES OF
GENERICS IN
JAVA
Code Reusability
Type Safety
Individual type casting not required
Implementing non generic algorithms
www.edureka.co/java-j2ee-soa-training
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
www.edureka.co/java-j2ee-soa-training

More Related Content

What's hot (18)

DOCX
Interface in java
Hitesh Kumar
 
PPTX
computer science JAVA ppt
brijesh kumar
 
ODP
Basic of Java
Ajeet Kumar Verma
 
PPT
Chapter 9 Interface
OUM SAOKOSAL
 
PPTX
Concepts of core java
AkshitaMangrulkar
 
DOCX
Bca 4020 java programming
smumbahelp
 
PPTX
Abstract class and Interface
Haris Bin Zahid
 
PDF
Genesis and Overview of Java
Ravi_Kant_Sahu
 
PDF
8 abstract classes and interfaces
Tuan Ngo
 
PPTX
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
PPTX
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
Simplilearn
 
PDF
Javanotes
John Cutajar
 
PPTX
Java interfaces
jehan1987
 
PPTX
Abstract class and interface
Mazharul Sabbir
 
PPT
Java Language
tikret
 
PPTX
Polymorphism and interface in vb.net
KarthigaGunasekaran1
 
PPTX
How do i use inheritance in java?
kritikumar16
 
PPTX
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
Simplilearn
 
Interface in java
Hitesh Kumar
 
computer science JAVA ppt
brijesh kumar
 
Basic of Java
Ajeet Kumar Verma
 
Chapter 9 Interface
OUM SAOKOSAL
 
Concepts of core java
AkshitaMangrulkar
 
Bca 4020 java programming
smumbahelp
 
Abstract class and Interface
Haris Bin Zahid
 
Genesis and Overview of Java
Ravi_Kant_Sahu
 
8 abstract classes and interfaces
Tuan Ngo
 
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
Simplilearn
 
Javanotes
John Cutajar
 
Java interfaces
jehan1987
 
Abstract class and interface
Mazharul Sabbir
 
Java Language
tikret
 
Polymorphism and interface in vb.net
KarthigaGunasekaran1
 
How do i use inheritance in java?
kritikumar16
 
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
Simplilearn
 

Similar to What are Generics in Java | Java Generics Tutorial | Edureka (20)

PPT
Generic programming in java
anshu_atri
 
PPTX
Generic Collections and learn how to use it
halaplay385
 
PPTX
Generics
Shahjahan Samoon
 
PPT
SOEN6441.generics.ppt
ElieMambou1
 
PPT
SOEN6441.genericsSOEN6441.genericsSOEN6441.generics
tahircs1
 
PDF
08-L19-Generics.pdfGenerics Module 2.pptx
AlvasCSE
 
PPT
Generic Programming seminar
Gautam Roy
 
PPTX
Generics Module 2Generics Module Generics Module 2.pptx
AlvasCSE
 
PDF
Generics
Ravi_Kant_Sahu
 
PDF
Introducing generic types
Ivelin Yanev
 
PPT
Generics lecture
Bradford Bazemore
 
PDF
Generic Programming
Muhammad Alhalaby
 
PDF
Generics Tutorial
wasntgosu
 
PDF
117 A Outline 25
wasntgosu
 
PDF
Generics Past, Present and Future
RichardWarburton
 
PDF
Generics Tutorial
wasntgosu
 
PDF
Generics Past, Present and Future (Latest)
RichardWarburton
 
PDF
Generics and collections in Java
Gurpreet singh
 
PPT
Generic Types in Java (for ArtClub @ArtBrains Software)
Andrew Petryk
 
Generic programming in java
anshu_atri
 
Generic Collections and learn how to use it
halaplay385
 
SOEN6441.generics.ppt
ElieMambou1
 
SOEN6441.genericsSOEN6441.genericsSOEN6441.generics
tahircs1
 
08-L19-Generics.pdfGenerics Module 2.pptx
AlvasCSE
 
Generic Programming seminar
Gautam Roy
 
Generics Module 2Generics Module Generics Module 2.pptx
AlvasCSE
 
Generics
Ravi_Kant_Sahu
 
Introducing generic types
Ivelin Yanev
 
Generics lecture
Bradford Bazemore
 
Generic Programming
Muhammad Alhalaby
 
Generics Tutorial
wasntgosu
 
117 A Outline 25
wasntgosu
 
Generics Past, Present and Future
RichardWarburton
 
Generics Tutorial
wasntgosu
 
Generics Past, Present and Future (Latest)
RichardWarburton
 
Generics and collections in Java
Gurpreet singh
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Andrew Petryk
 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Biography of Daniel Podor.pdf
Daniel Podor
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 

What are Generics in Java | Java Generics Tutorial | Edureka