SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Andere mochten auch

SkyWestHeroFlightAttendants4.19.11
SkyWestHeroFlightAttendants4.19.11SkyWestHeroFlightAttendants4.19.11
SkyWestHeroFlightAttendants4.19.11Jill Caree Anderson
 
Dossier De Presse E Hotel Marketing
Dossier De Presse E Hotel MarketingDossier De Presse E Hotel Marketing
Dossier De Presse E Hotel MarketingEHotelMarketing
 
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 2013Un Mundo de Cruceros
 
Compartir Documentos Google
Compartir Documentos GoogleCompartir Documentos Google
Compartir Documentos GoogleAmalia Boccolini
 
Universidad marítima internacional de panamá
Universidad marítima internacional de panamáUniversidad marítima internacional de panamá
Universidad marítima internacional de panamárichard mojica
 
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.funcoesCao Phan Quốc
 
Strengths Based Leadership Managers Workshop
Strengths Based Leadership Managers WorkshopStrengths Based Leadership Managers Workshop
Strengths Based Leadership Managers Workshoppatrickking
 
Warisan kepelbagaian budaya malaysia t2
Warisan kepelbagaian budaya malaysia t2Warisan kepelbagaian budaya malaysia t2
Warisan kepelbagaian budaya malaysia t2nurfadhillah
 
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 deusjonasfreitasdejesus
 

Andere mochten auch (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
 

Kürzlich hochgeladen

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 

Kürzlich hochgeladen (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 

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) { ... }