SlideShare uma empresa Scribd logo
1 de 14
Agenda ,[object Object],Compile-time type safety for collections without casting ,[object Object],Automates use of Iterators to avoid errors ,[object Object],Avoids manual conversion between primitive types (such as int)  and wrapper types (such as Integer) ,[object Object],Provides all the well-known benefits of the Typesafe Enum pattern 1
Generics - Intro Tutorials : http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf ,[object Object]
Methods can be defined to operate on unknown types of Objects without using ‘Objects’ class. And no type casting is required.
Big advantage: collections are now type safe.2 Example : ‘Generify ‘ your Java classes – public class Box<T> {   private T t ;  public void add(Tt ) {  this.t = t;  }  public T get() {  return t;  }  } How to use this : Box<Integer> integerBox = new Box<Integer>();  	… 	integerBox.add(new Integer(25)); //typesafe only Integers can be passed 	Integer myInt = integerBox.get() //no typecasting required T is a type parameter that will be replaced by a real type. T is the name of a type parameter. This name is used as a placeholder for the actual type that will be passed to Gen when an object is created.
Generics – Example 2 3 Another Example  public class GenericFactory<E> {     Class theClass = null;     public GenericFactory(Class theClass) {         this.theClass = theClass;     }     public E createInstance() throws …{         return (E) this.theClass.newInstance();     } Usage : Creates a Factory of Generic Type GenericFactory<MyClass> factory =  new GenericFactory<MyClass>(MyClass.class); MyClass myClassInstance = factory.createInstance();
Generics – Generics in Methods 4 static <T> void fromArrayToCollection(T[] a, Collection<T> c) {         for (T o : a) {             c.add(o);         }     }     static <T> Collection<T> fromArrayToCollectionv2(T[] a) {         Collection<T> c = new ArrayList<T>();         for (T o : a) {             c.add(o);         }         return c ;     } One more Interesting Example… public <T> T ifThenElse(boolean b, T first, T second) {  	return b ? first : second;  }
Generics – With Collections 5 Lists List<String> list = new ArrayList<String>();  list.add(“A String”);  String string2 = list.get(0); // no type casting. Maps (can define multiple typed parameters) 	Map<String, String> map = new HashMap<String, String>();map.put ("key1", "value1");map.put ("key2", "value2");String value1 = map.get("key1"); Iterating a Generic List: List<String> list = new ArrayList<String>();  Iterator<String> iterator = list.iterator();  while(iterator.hasNext()){  String aString = iterator.next();  } Backward Compatibility 	List list = new ArrayList<String>();  Nested Generic Types 	List<List<String>> myListOfListsOfStrings;
Generics – Diving Deeper 6 Generics and Subtyping List<String> ls = new ArrayList<String>();  List<Object> lo = ls; //illegal won’t compile!! What’s the Problem ? lo.add(new Object());  String s = ls.get(0); // attempts to assign an Object to a String! In other words  Collection<Object>  is not a supertype of all the types of collections To cope with this sort of situation use Wildcards static void printCollection2(Collection<?> c) {  // Collection<?> -“collection of unknown”         for (Object e : c) {             System.out.println(e);         }  } Limitation in using unbounded wildcard Any method that takes Generic type of argument cannot be invoked : Collection<?> c = new ArrayList<String>(); c.add(new Object()); // compile time error
Generics – Subtyping continued… 7 Bounded Wildcards List<? extends Shape> is an example of a bounded wildcard. ,[object Object]
A wildcard with a lower bound looks like " ? super Type " Example : public class Collections {    public static <T> void copy     ( List<? super T> dest, List<? extends T> src) {  // uses bounded wildcards        for (int i=0; i<src.size(); i++)          dest.set(i,src.get(i));    }  } List<Object> output = new ArrayList< Object >(); List<Long>    input = new ArrayList< Long >(); ... Collections.copy(output,input);  // fine List<String> output = new ArrayList< String >(); List<Long>    input = new ArrayList< Long >(); ... Collections.copy(output,input);  // error 
Enhanced for-loop or for each loop 8 New syntax of for loop that works for Collections and Arrays -  Collections : void cancelAll(Collection<TimerTask> c) {  for (TimerTask t : c) { 		t.cancel(); 	}  } Arrays : int sum(int[] a) {  	int result = 0;  for (int i : a) { 	result += i;  	} 	return result;  } Nested – for (Suit suit : suits) { 	for (Rank rank : ranks){  		sortedDeck.add(new Card(suit, rank)); 	} } ,[object Object]
 The for-each construct gets rid of the clutter and the opportunity for error.,[object Object]
Enum - Introduction 10 Java Constants Before JDK 1.5 – public static final int SEASON_WINTER = 0;  public static final int SEASON_SPRING = 1;  …… Issues: Not Type-safe  ,[object Object],No Name space ,[object Object],Compile time binding  Print Values not self explanatory. JDK 1.5 gets linguistic support for enumerated types as follows : enum Season { WINTER, SPRING, SUMMER, FALL } ** Don’t confuse enum with the Enumeration interface, an almost obsolete way of iterating over Collections, replaced by Iterator.
Enum - Example 11 How to define them .. public enum Flavor {     CHOCOLATE(100), //declare all the possible values first.      VANILLA(120),     STRAWBERRY(80);     private int fCalories; // can have state (member variables)     int getCalories(){ // cusotm method       return fCalories;     }     private Flavor(int aCalories){ // constructor       fCalories = aCalories;     }   } How to use them … String getColor(Flavor flv){ // Used as normal java objects..  	if(flv == Flavor.VANILLA) // “==“ can be used for value comparison 	  	return “White” ; 	…….	 	switch(flv) {  		case VANILLA :  // You can use enums as case labels 		…… } String color = getColor(Flavor.VANILLA) // no constructor only constant values.

Mais conteúdo relacionado

Mais procurados

Stl Containers
Stl ContainersStl Containers
Stl Containersppd1961
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comShwetaAggarwal56
 
Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Anton Kolotaev
 
Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminarGautam Roy
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++Ilio Catallo
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handlingsanya6900
 
Types, classes and concepts
Types, classes and conceptsTypes, classes and concepts
Types, classes and conceptsNicola Bonelli
 
Life & Work of Robin Milner | Turing100@Persistent
Life & Work of Robin Milner | Turing100@PersistentLife & Work of Robin Milner | Turing100@Persistent
Life & Work of Robin Milner | Turing100@PersistentPersistent Systems Ltd.
 
Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2Mohamed Krar
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenGraham Royce
 

Mais procurados (20)

Stl Containers
Stl ContainersStl Containers
Stl Containers
 
Java generics final
Java generics finalJava generics final
Java generics final
 
Python programming
Python  programmingPython  programming
Python programming
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminar
 
Modern C++
Modern C++Modern C++
Modern C++
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Smart pointers
Smart pointersSmart pointers
Smart pointers
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
Types, classes and concepts
Types, classes and conceptsTypes, classes and concepts
Types, classes and concepts
 
Life & Work of Robin Milner | Turing100@Persistent
Life & Work of Robin Milner | Turing100@PersistentLife & Work of Robin Milner | Turing100@Persistent
Life & Work of Robin Milner | Turing100@Persistent
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Scala
ScalaScala
Scala
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 

Destaque

Introduction à la programmation C#
Introduction à la programmation C#Introduction à la programmation C#
Introduction à la programmation C#hamoji hamoji
 
Plataforma de compiladores .NET, Visual Studio 2015, C# 6 e futuro C# 7
Plataforma de compiladores .NET,Visual Studio 2015, C# 6 e futuro C# 7Plataforma de compiladores .NET,Visual Studio 2015, C# 6 e futuro C# 7
Plataforma de compiladores .NET, Visual Studio 2015, C# 6 e futuro C# 7Rogério Moraes de Carvalho
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116Paulo Morgado
 
The Little Wonders of C# 6
The Little Wonders of C# 6The Little Wonders of C# 6
The Little Wonders of C# 6BlackRabbitCoder
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#Shahzad
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# IntroductionSiraj Memon
 
Crystal reports seminar
Crystal reports seminarCrystal reports seminar
Crystal reports seminarteope_ruvina
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 

Destaque (20)

Crystal Reports
Crystal ReportsCrystal Reports
Crystal Reports
 
Oops
OopsOops
Oops
 
Cr8.5 usermanual
Cr8.5 usermanualCr8.5 usermanual
Cr8.5 usermanual
 
Introduction à la programmation C#
Introduction à la programmation C#Introduction à la programmation C#
Introduction à la programmation C#
 
Learn ASP
Learn ASPLearn ASP
Learn ASP
 
Basic c#
Basic c#Basic c#
Basic c#
 
Plataforma de compiladores .NET, Visual Studio 2015, C# 6 e futuro C# 7
Plataforma de compiladores .NET,Visual Studio 2015, C# 6 e futuro C# 7Plataforma de compiladores .NET,Visual Studio 2015, C# 6 e futuro C# 7
Plataforma de compiladores .NET, Visual Studio 2015, C# 6 e futuro C# 7
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116
 
The Little Wonders of C# 6
The Little Wonders of C# 6The Little Wonders of C# 6
The Little Wonders of C# 6
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
 
Crystal Report
Crystal ReportCrystal Report
Crystal Report
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 
C#.NET
C#.NETC#.NET
C#.NET
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
 
Crystal reports seminar
Crystal reports seminarCrystal reports seminar
Crystal reports seminar
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
C# Crystal Reports
C# Crystal ReportsC# Crystal Reports
C# Crystal Reports
 
C#/.NET Little Pitfalls
C#/.NET Little PitfallsC#/.NET Little Pitfalls
C#/.NET Little Pitfalls
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 

Semelhante a Java New Programming Features

Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Peter Antman
 
Jdk1.5 Features
Jdk1.5 FeaturesJdk1.5 Features
Jdk1.5 Featuresindia_mani
 
javasebeyondbasics
javasebeyondbasicsjavasebeyondbasics
javasebeyondbasicswebuploader
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmersMark Whitaker
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingKeshav Kumar
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingKeshav Kumar
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Andrew Petryk
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxAbhishek Tirkey
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxGauravPandey43518
 
Tiger: Java 5 Evolutions
Tiger: Java 5 EvolutionsTiger: Java 5 Evolutions
Tiger: Java 5 EvolutionsMarco Bresciani
 
Effective Java Second Edition
Effective Java Second EditionEffective Java Second Edition
Effective Java Second Editionlosalamos
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
Javase5generics
Javase5genericsJavase5generics
Javase5genericsimypraz
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancementRakesh Madugula
 

Semelhante a Java New Programming Features (20)

Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)
 
Jdk1.5 Features
Jdk1.5 FeaturesJdk1.5 Features
Jdk1.5 Features
 
javasebeyondbasics
javasebeyondbasicsjavasebeyondbasics
javasebeyondbasics
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
Tiger: Java 5 Evolutions
Tiger: Java 5 EvolutionsTiger: Java 5 Evolutions
Tiger: Java 5 Evolutions
 
final year project center in Coimbatore
final year project center in Coimbatorefinal year project center in Coimbatore
final year project center in Coimbatore
 
Effective Java Second Edition
Effective Java Second EditionEffective Java Second Edition
Effective Java Second Edition
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
Java generics
Java genericsJava generics
Java generics
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Csharp4 generics
Csharp4 genericsCsharp4 generics
Csharp4 generics
 
Javase5generics
Javase5genericsJavase5generics
Javase5generics
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Java tut1
Java tut1Java tut1
Java tut1
 

Último

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Último (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Java New Programming Features

  • 1.
  • 2.
  • 3. Methods can be defined to operate on unknown types of Objects without using ‘Objects’ class. And no type casting is required.
  • 4. Big advantage: collections are now type safe.2 Example : ‘Generify ‘ your Java classes – public class Box<T> { private T t ; public void add(Tt ) { this.t = t; } public T get() { return t; } } How to use this : Box<Integer> integerBox = new Box<Integer>(); … integerBox.add(new Integer(25)); //typesafe only Integers can be passed Integer myInt = integerBox.get() //no typecasting required T is a type parameter that will be replaced by a real type. T is the name of a type parameter. This name is used as a placeholder for the actual type that will be passed to Gen when an object is created.
  • 5. Generics – Example 2 3 Another Example public class GenericFactory<E> { Class theClass = null; public GenericFactory(Class theClass) { this.theClass = theClass; } public E createInstance() throws …{ return (E) this.theClass.newInstance(); } Usage : Creates a Factory of Generic Type GenericFactory<MyClass> factory = new GenericFactory<MyClass>(MyClass.class); MyClass myClassInstance = factory.createInstance();
  • 6. Generics – Generics in Methods 4 static <T> void fromArrayToCollection(T[] a, Collection<T> c) { for (T o : a) { c.add(o); } } static <T> Collection<T> fromArrayToCollectionv2(T[] a) { Collection<T> c = new ArrayList<T>(); for (T o : a) { c.add(o); } return c ; } One more Interesting Example… public <T> T ifThenElse(boolean b, T first, T second) { return b ? first : second; }
  • 7. Generics – With Collections 5 Lists List<String> list = new ArrayList<String>(); list.add(“A String”); String string2 = list.get(0); // no type casting. Maps (can define multiple typed parameters) Map<String, String> map = new HashMap<String, String>();map.put ("key1", "value1");map.put ("key2", "value2");String value1 = map.get("key1"); Iterating a Generic List: List<String> list = new ArrayList<String>(); Iterator<String> iterator = list.iterator(); while(iterator.hasNext()){ String aString = iterator.next(); } Backward Compatibility List list = new ArrayList<String>(); Nested Generic Types List<List<String>> myListOfListsOfStrings;
  • 8. Generics – Diving Deeper 6 Generics and Subtyping List<String> ls = new ArrayList<String>(); List<Object> lo = ls; //illegal won’t compile!! What’s the Problem ? lo.add(new Object()); String s = ls.get(0); // attempts to assign an Object to a String! In other words Collection<Object> is not a supertype of all the types of collections To cope with this sort of situation use Wildcards static void printCollection2(Collection<?> c) { // Collection<?> -“collection of unknown” for (Object e : c) { System.out.println(e); } } Limitation in using unbounded wildcard Any method that takes Generic type of argument cannot be invoked : Collection<?> c = new ArrayList<String>(); c.add(new Object()); // compile time error
  • 9.
  • 10. A wildcard with a lower bound looks like " ? super Type " Example : public class Collections { public static <T> void copy ( List<? super T> dest, List<? extends T> src) { // uses bounded wildcards for (int i=0; i<src.size(); i++) dest.set(i,src.get(i)); } } List<Object> output = new ArrayList< Object >(); List<Long>    input = new ArrayList< Long >(); ... Collections.copy(output,input);  // fine List<String> output = new ArrayList< String >(); List<Long>    input = new ArrayList< Long >(); ... Collections.copy(output,input);  // error 
  • 11.
  • 12.
  • 13.
  • 14. Enum - Example 11 How to define them .. public enum Flavor { CHOCOLATE(100), //declare all the possible values first. VANILLA(120), STRAWBERRY(80); private int fCalories; // can have state (member variables) int getCalories(){ // cusotm method return fCalories; } private Flavor(int aCalories){ // constructor fCalories = aCalories; } } How to use them … String getColor(Flavor flv){ // Used as normal java objects.. if(flv == Flavor.VANILLA) // “==“ can be used for value comparison return “White” ; ……. switch(flv) { case VANILLA : // You can use enums as case labels …… } String color = getColor(Flavor.VANILLA) // no constructor only constant values.
  • 15.
  • 16. These can be passed around as Java objects.
  • 17. Constructors are never invoked outside the Enums (no new operator)
  • 18. Enums are implicitly final subclasses of java.lang.Enum
  • 19.
  • 20. Methods come built in with enums to do do things like convert enums names to ordinals, and combos with enumset.
  • 21. You can attach additional fields and code to enum constants.
  • 22. enums are type safe. With Strings all your items in all categories are the same type. There is nothing to stop you from feeding a fruit category to an animal parameter.
  • 23.