Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

What are Generics in Java | Java Generics Tutorial | Edureka

32 views

Published on

YouTube Link: https://youtu.be/9Tb-DyCirbA
** Java Certification Training: https://www.edureka.co/java-j2ee-training-course **
This Edureka PPT on Generics in Java will talk about what is generics, its methods, functions, etc. It will also showcase a demo to help you understand Java Generics concepts in a detailed way. Below topics are covered in this PPT:
What is Generics in Java?
Why Generics?
Types of Generics in Java
Generic Functions
Advantages of Generics in Java

Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in

Published in: Technology
  • Be the first to comment

  • Be the first to like this

What are Generics in Java | Java Generics Tutorial | Edureka

  1. 1. 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
  2. 2. www.edureka.co/java-j2ee-soa-training
  3. 3. 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
  4. 4. www.edureka.co/java-j2ee-soa-training
  5. 5. WHY JAVA GENERICS? www.edureka.co/java-j2ee-soa-training
  6. 6. TYPES OF JAVA GENERICS www.edureka.co/java-j2ee-soa-training
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. GENERIC FUNCTIONS www.edureka.co/java-j2ee-soa-training
  12. 12. 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
  13. 13. www.edureka.co/java-j2ee-soa-training
  14. 14. 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
  15. 15. Copyright � 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co
  16. 16. www.edureka.co/java-j2ee-soa-training

×