SlideShare une entreprise Scribd logo
1  sur  12
Aruna Karunarathna
JavaDocs & Best Practices
Adding Documentation to your code?
● Block Comments
The compiler ignores everything from /* to */.
● Line Comments
// text
The compiler ignores everything from // to the end of the line.
● JavaDoc Comments
/** documentation */
This indicates a documentation comment. (Doc Comments for shorter version...)
Demo
JavaDoc Important Tags
● @param
● @return
● @throws
● @deprecated
● @see
● @since
● @code
● @link
Adding Documentation to your code cntd..
● What is this supposed to do?
Answered only by the javadoc and method signature
● How does it try to do it?
Answered only by the implementation
● Keep in mind the 80/20 rule. When designing API’s
● Refer the JDK code for further reference.. :)
JavaDoc Guidelines..
● Write Javadoc to be read as source code
● Use @param same order as the parameters
● Keep a blank line between the Javadoc text and the @param or
@return
● Public and protected
● Use simple HTML tags, too much HTML not encouraged..!!!
JavaDoc Guidelines Cntd..
● Utilize the first sentence as much as possible.
* This means the first sentence of each member, class, interface or
package description
* A concise but complete description of the API item.
● Use @code and @link wisely
* Java keywords, package names, class names, method names,interface names
field names, argument names, code examples
* Keep in mind that audience is a advanced programmers use @link
economically
JavaDoc Guidelines Cntd...
● Use lists for explaining set of options, choices
● Avoid second person for sentences and use the third person
● Document accepting or returning null
● Use "this" instead of "the" when referring to an object created
from the current class.
● Use a single <p> tag between paragraphs, Don’t write too lengthy
sentences
JavaDoc Guidelines Cntd...
● @param / @return guidelines
@param x the x-coordinate, measured in pixels (Phrase Only)
@param x the x-coordinate. Measured in pixels. (Phrase followed by sentence)
@param x Specifies the x-coordinate, measured in pixels. (Sentence Only)
@param x Specifies the x-coordinate. Measured in pixels. (Multiple Sentences)
JavaDoc Guidelines Cntd...
● Add description beyond the API name.
/**
* Sets the tool tip text.
*
* @param text the text of the tool tip
*/
public void setToolTipText(String text) {... }
/**
* Registers the text to display in a tool tip. The text
* displays when the cursor lingers over the component.
*
* @param text the string to display. If the text is null,
* the tool tip is turned off for this component.
*/
public void setToolTipText(String text) {...}
JavaDoc Guidelines Cntd...
/**
* Gets personal info.
*
* @param userId user id
* @return Personal info dto.
*/
public PersonalInfoDTO getPersonalInfoDTO(int userId) { ... }
/**
* Gets a dto of personal info by querying the current list of users from
* active directory
*
* @param userId The id of the user. Must be greater than 0. The ID is stored
* in the application context or can be retrieved by a call to
getUserIdByName.
* @return A dto containing personal info. Returns null if the specified user
* information was not found.
*/
public PersonalInfoDTO getPersonalInfoDTO(int userId) { ... }
References
● http://www.oracle.com/technetwork/java/javase/documentation/index-
137868.html
● https://github.com/ThreeTen/threeten/blob/0b071a60997f409e44b9bbccde013b
004f24fe22/src/main/java/javax/time/LocalDate.java
● http://blog.joda.org/2012/11/javadoc-coding-standards.html

Contenu connexe

En vedette

SkyWestHeroFlightAttendants4.19.11
SkyWestHeroFlightAttendants4.19.11SkyWestHeroFlightAttendants4.19.11
SkyWestHeroFlightAttendants4.19.11
Jill Caree Anderson
 
Dossier De Presse E Hotel Marketing
Dossier De Presse E Hotel MarketingDossier De Presse E Hotel Marketing
Dossier De Presse E Hotel Marketing
EHotelMarketing
 
Especial Cruceros El Periódico Diciembre 2013
Especial Cruceros El Periódico Diciembre 2013Especial Cruceros El Periódico Diciembre 2013
Especial Cruceros El Periódico Diciembre 2013
Un Mundo de Cruceros
 
Fundamentos.de.matematica.elementar.vol.01.conjuntos.e.funcoes
Fundamentos.de.matematica.elementar.vol.01.conjuntos.e.funcoesFundamentos.de.matematica.elementar.vol.01.conjuntos.e.funcoes
Fundamentos.de.matematica.elementar.vol.01.conjuntos.e.funcoes
Cao Phan Quốc
 
Strengths Based Leadership Managers Workshop
Strengths Based Leadership Managers WorkshopStrengths Based Leadership Managers Workshop
Strengths Based Leadership Managers Workshop
patrickking
 
Warisan kepelbagaian budaya malaysia t2
Warisan kepelbagaian budaya malaysia t2Warisan kepelbagaian budaya malaysia t2
Warisan kepelbagaian budaya malaysia t2
nurfadhillah
 

En vedette (15)

SkyWestHeroFlightAttendants4.19.11
SkyWestHeroFlightAttendants4.19.11SkyWestHeroFlightAttendants4.19.11
SkyWestHeroFlightAttendants4.19.11
 
Dossier De Presse E Hotel Marketing
Dossier De Presse E Hotel MarketingDossier De Presse E Hotel Marketing
Dossier De Presse E Hotel Marketing
 
Fall 2013 Cooking Flyer
Fall 2013 Cooking FlyerFall 2013 Cooking Flyer
Fall 2013 Cooking Flyer
 
Ciudad De San Jose2
Ciudad De  San  Jose2Ciudad De  San  Jose2
Ciudad De San Jose2
 
"BULE VERDE" CULTURA E ARTES
"BULE VERDE" CULTURA E ARTES"BULE VERDE" CULTURA E ARTES
"BULE VERDE" CULTURA E ARTES
 
Especial Cruceros El Periódico Diciembre 2013
Especial Cruceros El Periódico Diciembre 2013Especial Cruceros El Periódico Diciembre 2013
Especial Cruceros El Periódico Diciembre 2013
 
JNNYC Wel Come
JNNYC Wel ComeJNNYC Wel Come
JNNYC Wel Come
 
Compartir Documentos Google
Compartir Documentos GoogleCompartir Documentos Google
Compartir Documentos Google
 
Universidad marítima internacional de panamá
Universidad marítima internacional de panamáUniversidad marítima internacional de panamá
Universidad marítima internacional de panamá
 
Fundamentos.de.matematica.elementar.vol.01.conjuntos.e.funcoes
Fundamentos.de.matematica.elementar.vol.01.conjuntos.e.funcoesFundamentos.de.matematica.elementar.vol.01.conjuntos.e.funcoes
Fundamentos.de.matematica.elementar.vol.01.conjuntos.e.funcoes
 
Polishop Opportunity
Polishop OpportunityPolishop Opportunity
Polishop Opportunity
 
Strengths Based Leadership Managers Workshop
Strengths Based Leadership Managers WorkshopStrengths Based Leadership Managers Workshop
Strengths Based Leadership Managers Workshop
 
Who Texted My Boyfriend?
Who Texted My Boyfriend?Who Texted My Boyfriend?
Who Texted My Boyfriend?
 
Warisan kepelbagaian budaya malaysia t2
Warisan kepelbagaian budaya malaysia t2Warisan kepelbagaian budaya malaysia t2
Warisan kepelbagaian budaya malaysia t2
 
Usos e costmes defendidos pela igreja a assembleia de deus
Usos e costmes defendidos pela igreja  a assembleia de deusUsos e costmes defendidos pela igreja  a assembleia de deus
Usos e costmes defendidos pela igreja a assembleia de deus
 

Dernier

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Dernier (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 

Java Docs and Best Practices

  • 2. Adding Documentation to your code? ● Block Comments The compiler ignores everything from /* to */. ● Line Comments // text The compiler ignores everything from // to the end of the line. ● JavaDoc Comments /** documentation */ This indicates a documentation comment. (Doc Comments for shorter version...)
  • 4. JavaDoc Important Tags ● @param ● @return ● @throws ● @deprecated ● @see ● @since ● @code ● @link
  • 5. Adding Documentation to your code cntd.. ● What is this supposed to do? Answered only by the javadoc and method signature ● How does it try to do it? Answered only by the implementation ● Keep in mind the 80/20 rule. When designing API’s ● Refer the JDK code for further reference.. :)
  • 6. JavaDoc Guidelines.. ● Write Javadoc to be read as source code ● Use @param same order as the parameters ● Keep a blank line between the Javadoc text and the @param or @return ● Public and protected ● Use simple HTML tags, too much HTML not encouraged..!!!
  • 7. JavaDoc Guidelines Cntd.. ● Utilize the first sentence as much as possible. * This means the first sentence of each member, class, interface or package description * A concise but complete description of the API item. ● Use @code and @link wisely * Java keywords, package names, class names, method names,interface names field names, argument names, code examples * Keep in mind that audience is a advanced programmers use @link economically
  • 8. JavaDoc Guidelines Cntd... ● Use lists for explaining set of options, choices ● Avoid second person for sentences and use the third person ● Document accepting or returning null ● Use "this" instead of "the" when referring to an object created from the current class. ● Use a single <p> tag between paragraphs, Don’t write too lengthy sentences
  • 9. JavaDoc Guidelines Cntd... ● @param / @return guidelines @param x the x-coordinate, measured in pixels (Phrase Only) @param x the x-coordinate. Measured in pixels. (Phrase followed by sentence) @param x Specifies the x-coordinate, measured in pixels. (Sentence Only) @param x Specifies the x-coordinate. Measured in pixels. (Multiple Sentences)
  • 10. JavaDoc Guidelines Cntd... ● Add description beyond the API name. /** * Sets the tool tip text. * * @param text the text of the tool tip */ public void setToolTipText(String text) {... } /** * Registers the text to display in a tool tip. The text * displays when the cursor lingers over the component. * * @param text the string to display. If the text is null, * the tool tip is turned off for this component. */ public void setToolTipText(String text) {...}
  • 11. JavaDoc Guidelines Cntd... /** * Gets personal info. * * @param userId user id * @return Personal info dto. */ public PersonalInfoDTO getPersonalInfoDTO(int userId) { ... } /** * Gets a dto of personal info by querying the current list of users from * active directory * * @param userId The id of the user. Must be greater than 0. The ID is stored * in the application context or can be retrieved by a call to getUserIdByName. * @return A dto containing personal info. Returns null if the specified user * information was not found. */ public PersonalInfoDTO getPersonalInfoDTO(int userId) { ... }