SlideShare une entreprise Scribd logo
1  sur  7
Writing Effective Methods in Java

                Parag Shah

      http://www.diycomputerscience.com
Always check method parameters for validity
WHY ?

Because we should always fail fast !
An example
What will happen if we do not ?

We may get an Exception which is unrelated
We may get an incorrect result
We may create an object which will fail at a totally
 different and unrelated time
What should be checked ?

Constructors
Public, protected, package methods
When not to check ?

If the check is very expensive
  a method which expects a sorted list
If the check will be done implicitly in the
   computation
  sorting automatically checks for comparable
    instances
Possible to omit checks in private methods

Contenu connexe

Tendances

Extreme optimization good
Extreme optimization goodExtreme optimization good
Extreme optimization good
matt433
 
dotnet3_A610635_aditiDalmia
dotnet3_A610635_aditiDalmiadotnet3_A610635_aditiDalmia
dotnet3_A610635_aditiDalmia
ADITI DALMIA
 
Resource Leaks in Java
Resource Leaks in JavaResource Leaks in Java
Resource Leaks in Java
Coverity
 
I Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingI Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application Testing
Peter Presnell
 

Tendances (20)

React performance
React performanceReact performance
React performance
 
Extreme optimization good
Extreme optimization goodExtreme optimization good
Extreme optimization good
 
Creating a Culture of Software Craftsmanship
Creating a Culture of Software CraftsmanshipCreating a Culture of Software Craftsmanship
Creating a Culture of Software Craftsmanship
 
Automated testing
Automated testingAutomated testing
Automated testing
 
TestWorksConf: Experience exploratory testing
TestWorksConf: Experience exploratory testingTestWorksConf: Experience exploratory testing
TestWorksConf: Experience exploratory testing
 
Goodtests
GoodtestsGoodtests
Goodtests
 
Solving Flaky Automated Tests Using Machine Learning
Solving Flaky Automated Tests Using Machine LearningSolving Flaky Automated Tests Using Machine Learning
Solving Flaky Automated Tests Using Machine Learning
 
dotnet3_A610635_aditiDalmia
dotnet3_A610635_aditiDalmiadotnet3_A610635_aditiDalmia
dotnet3_A610635_aditiDalmia
 
Aistė Stikliutė - Testing in continuous delivery
Aistė Stikliutė - Testing in continuous deliveryAistė Stikliutė - Testing in continuous delivery
Aistė Stikliutė - Testing in continuous delivery
 
Automating Strategically or Tactically when Testing
Automating Strategically or Tactically when TestingAutomating Strategically or Tactically when Testing
Automating Strategically or Tactically when Testing
 
Resource Leaks in Java
Resource Leaks in JavaResource Leaks in Java
Resource Leaks in Java
 
Testing javascript
Testing javascriptTesting javascript
Testing javascript
 
I Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingI Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application Testing
 
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
 
Concurrency Errors in Java
Concurrency Errors in JavaConcurrency Errors in Java
Concurrency Errors in Java
 
Automated Agility?! Let's Talk Truly Agile Testing - Adam Howard - AgileNZ 2017
Automated Agility?! Let's Talk Truly Agile Testing - Adam Howard - AgileNZ 2017Automated Agility?! Let's Talk Truly Agile Testing - Adam Howard - AgileNZ 2017
Automated Agility?! Let's Talk Truly Agile Testing - Adam Howard - AgileNZ 2017
 
Tampere Testing Days: Exploratory Testing an API
Tampere Testing Days: Exploratory Testing an APITampere Testing Days: Exploratory Testing an API
Tampere Testing Days: Exploratory Testing an API
 
Selenium Conference India: Intersection of Automation and Exploratory Testing
Selenium Conference India: Intersection of Automation and Exploratory TestingSelenium Conference India: Intersection of Automation and Exploratory Testing
Selenium Conference India: Intersection of Automation and Exploratory Testing
 
ISTQB Foundation and Selenium Java Automation Testing
ISTQB Foundation and Selenium Java Automation TestingISTQB Foundation and Selenium Java Automation Testing
ISTQB Foundation and Selenium Java Automation Testing
 
Webinar: Estrategias para optimizar los costos de testing
Webinar: Estrategias para optimizar los costos de testingWebinar: Estrategias para optimizar los costos de testing
Webinar: Estrategias para optimizar los costos de testing
 

En vedette (6)

Data structures
Data structuresData structures
Data structures
 
Make defensive copies
Make defensive copiesMake defensive copies
Make defensive copies
 
Effective exceptions
Effective exceptionsEffective exceptions
Effective exceptions
 
Version Control With svn Setting The Stage
Version  Control With svn Setting The StageVersion  Control With svn Setting The Stage
Version Control With svn Setting The Stage
 
General method best_practices
General method best_practicesGeneral method best_practices
General method best_practices
 
Application Development Using Java - DIYComputerScience Course
Application Development Using Java - DIYComputerScience CourseApplication Development Using Java - DIYComputerScience Course
Application Development Using Java - DIYComputerScience Course
 

Plus de parag (12)

Building Internet Reputation
Building Internet ReputationBuilding Internet Reputation
Building Internet Reputation
 
Double checkedlockingjavasingletons
Double checkedlockingjavasingletonsDouble checkedlockingjavasingletons
Double checkedlockingjavasingletons
 
Uml
UmlUml
Uml
 
Internet And New Media For Teaching
Internet And New Media For TeachingInternet And New Media For Teaching
Internet And New Media For Teaching
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Blogging and The Learning Professional
Blogging and The Learning ProfessionalBlogging and The Learning Professional
Blogging and The Learning Professional
 
Inner Classes
Inner ClassesInner Classes
Inner Classes
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Java
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
IO In Java
IO In JavaIO In Java
IO In Java
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 
Goals Of Software Design - The main goals
Goals Of Software Design - The main goalsGoals Of Software Design - The main goals
Goals Of Software Design - The main goals
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Check methods params_for_validity

  • 1. Writing Effective Methods in Java Parag Shah http://www.diycomputerscience.com
  • 2. Always check method parameters for validity
  • 3. WHY ? Because we should always fail fast !
  • 5. What will happen if we do not ? We may get an Exception which is unrelated We may get an incorrect result We may create an object which will fail at a totally different and unrelated time
  • 6. What should be checked ? Constructors Public, protected, package methods
  • 7. When not to check ? If the check is very expensive a method which expects a sorted list If the check will be done implicitly in the computation sorting automatically checks for comparable instances Possible to omit checks in private methods