SlideShare a Scribd company logo
Java Best Practices
Naming Conventions, Build
Automation Tools and Functional
Interfaces
SoftUni Team
Technical Trainers
Software University
http://softuni.bg
2
1. Naming conventions
1. File Naming, Class Naming
2. JAR Files
3. Code Conventions
2. Java Documentation
3. Build Automation
1. Tools
2. Maven Examples
4. Functional Interfaces
Table of Contents
Naming Conventions
4
 JAR files names should consist of single word or several words
separated by hyphen
 Can contain version information
 Examples:
 xalan25.jar
 ant-apache-log4j.jar
 Incorrect examples:
 Ant.Apache.Log4J.jar
 Oracle.JDBC.Drivers.jar
Naming JAR Files in Java
5
 Microsoft official C# code conventions
 Design Guidelines for Developing Class Libraries:
http://msdn.microsoft.com/en-us/library/ms229042.aspx
 Java official code conventions
 http://www.oracle.com/technetwork/java/codeconvtoc-136057.html
 Semi-official JavaScript code conventions
 http://javascript.crockford.com/code.html,
http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
 Semi-official PHP conventions
 http://www.php-fig.org/psr/psr-1/
Code Conventions
6
 In C# use single [Tab] after breaking a long line:
 In JavaScript, Java and PHP use double [Tab] in the carried long lines:
Breaking Long Lines in C#, JavaScript,
Java and PHP
if (matrix[x, y] == 0 || matrix[x-1, y] == 0 ||
matrix[x+1, y] == 0 || matrix[x, y-1] == 0 ||
matrix[x, y+1] == 0)
{
matrix[x, y] == 1;
}
if (matrix[x, y] == 0 || matrix[x-1, y] == 0 ||
matrix[x+1, y] == 0 || matrix[x, y-1] == 0 ||
matrix[x, y+1] == 0) {
matrix[x, y] == 1;
}
7
 Packages naming guidelines
 Use camelCase
 Following formats are acceptable:
 com . company . product . component . …
 product . component . …
 Example:
 com.apple.quicktime, hibernate.core
 Incorrect examples:
 IBM.DB2.Data, ibm.db2_data, Tetris.UI
Naming Java Packages / JS Namespaces
8
 Files with source code should have names matching their
content
 File containing a class Student should be names
Student.cs / Student.java / Student.php
 Example:
 StudentDAO.cs, Constants.java,
CryptographyAlgorithms.cs
 Incorrect examples:
 Program.cs, SourceCode.java, _d2.cs,
WebApplication1.jsp, Page1.aspx
Naming Files in C#, Java and PHP
9
 Several formats are acceptable:
 [Noun] or [Verb] or [Adjective]
 Use PascalCase for the enumeration and
CAPITALS for its members
 Examples:
 enum Suit {CLUBS, DIAMONDS, HEARTS, SPADES},
enum Color {RED, GREEN, BLUE, …}
 Incorrect examples:
 enum Color {red, green, blue, white},
enum PAGE_FORMAT {A4, A5, A3, LEGAL, …}
Naming Enumerations in Java and JS
10
 Following formats are acceptable:
 [Verb] + 'able'
 [Noun], [Adjective] + [Noun]
 Examples:
 Serializable, Enumerable, Comparable,
Runnable, CharSequence, OutputStream
 Incorrect examples:
 list, FindUsers, Run, Inumber, OPTIMIZER,
IMemoryOptimize, FastFindInDatabase
Naming Interfaces in Java
JavaDoc Documentation
12
 In Java you can document the code using the built-in JavaDoc tool
 JavaDoc tags are preceded by @ "at"
 You can use HTML tags in the documentation code
 For example:
JavaDoc Documentation
/**
* This method returns the sum of two numbers
* @param num1 The first number to sum
* @param num2 The second number to sum
* @return The sum of the two numbers
*/
public static int sumTwoNumbers(int num1, int num2) {
}
13
 The summary is exactly after the opening "/**" JavaDoc comment
 Some JavaDoc Tags:
 @param - method parameter
 @author - author of the class
 @return - method return value
 @throws/@exception - exceptions that method throws
 {@code } - source code
 @see - reference to other class similar to this
JavaDoc Documentation Tags
Build Automation
15
 Build automation is the act of automating a wide variety of tasks
in the developer’s day-to-day activities
 Compiling
 Resolving dependencies
 Packaging
 Deploying
 Running automated tests
Build Automation
16
 In the Java world there are three widely-spread build
automation tools
 Apache Ant
 Apache Maven
 Gradle (on Groovy)
Build Automation (2)
17
Maven Project Initiation
 Initiating a Maven project consists of declaring the
 Group ID
 Project unique name e.g. org.apache.commons
 Artifact ID
 Produced binary e.g. jar without version e.g. commons
 Version
 Version like 1.0, 1.5 etc.
18
Maven Project Structure
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/it Integration Tests (primarily for plugins)
src/assembly Assembly descriptors
src/site Site
LICENSE.txt Project's license
NOTICE.txt
Notices and attributions required by libraries
that the project depends on
README.txt Project's readme
19
Maven POM
 POM.xml is the main configuration where it all starts from
 There is described
 How software is built
 Software’s dependencies
20
Maven POM (2)
<project>
<!-- model version is always 4.0.0 for Maven 2.x POMs -->
<modelVersion>4.0.0</modelVersion>
<!-- project coordinates, i.e. a group of values which uniquely identify this project -->
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0</version>
<!-- library dependencies -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</project>
Maven
Live Demo
22
 Naming Conventions
 Project Structures
 JavaDoc
 Build Automation
Summary
?
Java Best Practices
https://softuni.bg/courses/java-basics/
24
 This course (slides, examples, demos, videos, homework, etc.)
is licensed under the "Creative Commons Attribution-
NonCommercial-ShareAlike 4.0 International" license
 Attribution: this work may contain portions from
 "Fundamentals of Computer Programming with Java" book by Svetlin Nakov & Co. under CC-BY-SA license
 "C# Basics" course by Software University under CC-BY-NC-SA license
License
Free Trainings @ Software University
 Software University Foundation – softuni.org
 Software University – High-Quality Education,
Profession and Job for Software Developers
 softuni.bg
 Software University @ Facebook
 facebook.com/SoftwareUniversity
 Software University @ YouTube
 youtube.com/SoftwareUniversity
 Software University Forums – forum.softuni.bg

More Related Content

PPTX
21. High-Quality Programming Code
PPTX
01. Introduction to programming with java
PPTX
01. Introduction to Programming
PPTX
01. introduction to-programming
PPTX
Java Tutorial: Part 2. IntelliJ IDEA
PPT
PPTX
A Comparison of .NET Framework vs. Java Virtual Machine
PPTX
Introduction to java
21. High-Quality Programming Code
01. Introduction to programming with java
01. Introduction to Programming
01. introduction to-programming
Java Tutorial: Part 2. IntelliJ IDEA
A Comparison of .NET Framework vs. Java Virtual Machine
Introduction to java

What's hot (20)

PPTX
Chapter 2.1
PPSX
Java Semimar Slide (Cetpa)
PPTX
Programming
PPTX
Java v/s .NET - Which is Better?
PDF
Curso de Programación Java Intermedio
PPTX
Structure programming – Java Programming – Theory
PPTX
.NET and C# introduction
PDF
JAVA Program Examples
PPT
C#.NET
PPTX
Comparison of Programming Platforms
PPTX
Curso de Programación Java Básico
PPTX
Introduction To C#
PPT
Java for Recruiters
PPTX
Introduction to java
PPSX
A comprehensive software infrastructure of .Net
PPTX
Great cup of java
PDF
Object oriented-programming-in-c-sharp
PPTX
Chapter 1
PPTX
Java vs python
Chapter 2.1
Java Semimar Slide (Cetpa)
Programming
Java v/s .NET - Which is Better?
Curso de Programación Java Intermedio
Structure programming – Java Programming – Theory
.NET and C# introduction
JAVA Program Examples
C#.NET
Comparison of Programming Platforms
Curso de Programación Java Básico
Introduction To C#
Java for Recruiters
Introduction to java
A comprehensive software infrastructure of .Net
Great cup of java
Object oriented-programming-in-c-sharp
Chapter 1
Java vs python
Ad

Similar to 21. Java High Quality Programming Code (20)

PPSX
Coding standard
PPT
Codings Standards
PDF
Java convention
PDF
Standards For Java Coding
PPTX
Writing High Quality Code in C#
PDF
Java, Eclipse, Maven & JSF tutorial
PPT
Oracle Workflow Continuous Integration
PPTX
Java_code_convention_ppt_report for group 1.pptx
PPT
Android coding guide lines
DOCX
Java notes
PPTX
chap 10 : Development (scjp/ocjp)
PPTX
Java and the JVM
PPTX
Beginning Java for .NET developers
PPTX
LECTURE 2 -Object oriented Java Basics.pptx
PDF
Hands On with Maven
PPTX
Intro to programing with java-lecture 1
PDF
1. Coding Conventions [Part 1]
PDF
Java Coding Conventions
PDF
Perfomatix - Android Coding Standards
Coding standard
Codings Standards
Java convention
Standards For Java Coding
Writing High Quality Code in C#
Java, Eclipse, Maven & JSF tutorial
Oracle Workflow Continuous Integration
Java_code_convention_ppt_report for group 1.pptx
Android coding guide lines
Java notes
chap 10 : Development (scjp/ocjp)
Java and the JVM
Beginning Java for .NET developers
LECTURE 2 -Object oriented Java Basics.pptx
Hands On with Maven
Intro to programing with java-lecture 1
1. Coding Conventions [Part 1]
Java Coding Conventions
Perfomatix - Android Coding Standards
Ad

More from Intro C# Book (20)

PPTX
17. Java data structures trees representation and traversal
PPTX
Java Problem solving
PPTX
20.5 Java polymorphism
PPTX
20.4 Java interfaces and abstraction
PPTX
20.3 Java encapsulation
PPTX
20.2 Java inheritance
PPTX
20.1 Java working with abstraction
PPTX
19. Java data structures algorithms and complexity
PPTX
18. Java associative arrays
PPTX
16. Java stacks and queues
PPTX
14. Java defining classes
PPTX
13. Java text processing
PPTX
12. Java Exceptions and error handling
PPTX
11. Java Objects and classes
PPTX
09. Java Methods
PPTX
05. Java Loops Methods and Classes
PPTX
07. Java Array, Set and Maps
PPTX
03 and 04 .Operators, Expressions, working with the console and conditional s...
PPTX
02. Data Types and variables
PPTX
23. Methodology of Problem Solving
17. Java data structures trees representation and traversal
Java Problem solving
20.5 Java polymorphism
20.4 Java interfaces and abstraction
20.3 Java encapsulation
20.2 Java inheritance
20.1 Java working with abstraction
19. Java data structures algorithms and complexity
18. Java associative arrays
16. Java stacks and queues
14. Java defining classes
13. Java text processing
12. Java Exceptions and error handling
11. Java Objects and classes
09. Java Methods
05. Java Loops Methods and Classes
07. Java Array, Set and Maps
03 and 04 .Operators, Expressions, working with the console and conditional s...
02. Data Types and variables
23. Methodology of Problem Solving

Recently uploaded (20)

PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PDF
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
Digital Literacy And Online Safety on internet
PPTX
ppt for upby gurvinder singh padamload.pptx
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
Introduction to Information and Communication Technology
DOCX
Unit-3 cyber security network security of internet system
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
innovation process that make everything different.pptx
PPTX
CSharp_Syntax_Basics.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Internet___Basics___Styled_ presentation
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
RPKI Status Update, presented by Makito Lay at IDNOG 10
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
introduction about ICD -10 & ICD-11 ppt.pptx
Digital Literacy And Online Safety on internet
ppt for upby gurvinder singh padamload.pptx
WebRTC in SignalWire - troubleshooting media negotiation
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Sims 4 Historia para lo sims 4 para jugar
Introduction to Information and Communication Technology
Unit-3 cyber security network security of internet system
Job_Card_System_Styled_lorem_ipsum_.pptx
innovation process that make everything different.pptx
CSharp_Syntax_Basics.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxx
522797556-Unit-2-Temperature-measurement-1-1.pptx
Internet___Basics___Styled_ presentation
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Unit-1 introduction to cyber security discuss about how to secure a system

21. Java High Quality Programming Code

  • 1. Java Best Practices Naming Conventions, Build Automation Tools and Functional Interfaces SoftUni Team Technical Trainers Software University http://softuni.bg
  • 2. 2 1. Naming conventions 1. File Naming, Class Naming 2. JAR Files 3. Code Conventions 2. Java Documentation 3. Build Automation 1. Tools 2. Maven Examples 4. Functional Interfaces Table of Contents
  • 4. 4  JAR files names should consist of single word or several words separated by hyphen  Can contain version information  Examples:  xalan25.jar  ant-apache-log4j.jar  Incorrect examples:  Ant.Apache.Log4J.jar  Oracle.JDBC.Drivers.jar Naming JAR Files in Java
  • 5. 5  Microsoft official C# code conventions  Design Guidelines for Developing Class Libraries: http://msdn.microsoft.com/en-us/library/ms229042.aspx  Java official code conventions  http://www.oracle.com/technetwork/java/codeconvtoc-136057.html  Semi-official JavaScript code conventions  http://javascript.crockford.com/code.html, http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml  Semi-official PHP conventions  http://www.php-fig.org/psr/psr-1/ Code Conventions
  • 6. 6  In C# use single [Tab] after breaking a long line:  In JavaScript, Java and PHP use double [Tab] in the carried long lines: Breaking Long Lines in C#, JavaScript, Java and PHP if (matrix[x, y] == 0 || matrix[x-1, y] == 0 || matrix[x+1, y] == 0 || matrix[x, y-1] == 0 || matrix[x, y+1] == 0) { matrix[x, y] == 1; } if (matrix[x, y] == 0 || matrix[x-1, y] == 0 || matrix[x+1, y] == 0 || matrix[x, y-1] == 0 || matrix[x, y+1] == 0) { matrix[x, y] == 1; }
  • 7. 7  Packages naming guidelines  Use camelCase  Following formats are acceptable:  com . company . product . component . …  product . component . …  Example:  com.apple.quicktime, hibernate.core  Incorrect examples:  IBM.DB2.Data, ibm.db2_data, Tetris.UI Naming Java Packages / JS Namespaces
  • 8. 8  Files with source code should have names matching their content  File containing a class Student should be names Student.cs / Student.java / Student.php  Example:  StudentDAO.cs, Constants.java, CryptographyAlgorithms.cs  Incorrect examples:  Program.cs, SourceCode.java, _d2.cs, WebApplication1.jsp, Page1.aspx Naming Files in C#, Java and PHP
  • 9. 9  Several formats are acceptable:  [Noun] or [Verb] or [Adjective]  Use PascalCase for the enumeration and CAPITALS for its members  Examples:  enum Suit {CLUBS, DIAMONDS, HEARTS, SPADES}, enum Color {RED, GREEN, BLUE, …}  Incorrect examples:  enum Color {red, green, blue, white}, enum PAGE_FORMAT {A4, A5, A3, LEGAL, …} Naming Enumerations in Java and JS
  • 10. 10  Following formats are acceptable:  [Verb] + 'able'  [Noun], [Adjective] + [Noun]  Examples:  Serializable, Enumerable, Comparable, Runnable, CharSequence, OutputStream  Incorrect examples:  list, FindUsers, Run, Inumber, OPTIMIZER, IMemoryOptimize, FastFindInDatabase Naming Interfaces in Java
  • 12. 12  In Java you can document the code using the built-in JavaDoc tool  JavaDoc tags are preceded by @ "at"  You can use HTML tags in the documentation code  For example: JavaDoc Documentation /** * This method returns the sum of two numbers * @param num1 The first number to sum * @param num2 The second number to sum * @return The sum of the two numbers */ public static int sumTwoNumbers(int num1, int num2) { }
  • 13. 13  The summary is exactly after the opening "/**" JavaDoc comment  Some JavaDoc Tags:  @param - method parameter  @author - author of the class  @return - method return value  @throws/@exception - exceptions that method throws  {@code } - source code  @see - reference to other class similar to this JavaDoc Documentation Tags
  • 15. 15  Build automation is the act of automating a wide variety of tasks in the developer’s day-to-day activities  Compiling  Resolving dependencies  Packaging  Deploying  Running automated tests Build Automation
  • 16. 16  In the Java world there are three widely-spread build automation tools  Apache Ant  Apache Maven  Gradle (on Groovy) Build Automation (2)
  • 17. 17 Maven Project Initiation  Initiating a Maven project consists of declaring the  Group ID  Project unique name e.g. org.apache.commons  Artifact ID  Produced binary e.g. jar without version e.g. commons  Version  Version like 1.0, 1.5 etc.
  • 18. 18 Maven Project Structure src/main/java Application/Library sources src/main/resources Application/Library resources src/main/filters Resource filter files src/main/webapp Web application sources src/test/java Test sources src/test/resources Test resources src/test/filters Test resource filter files src/it Integration Tests (primarily for plugins) src/assembly Assembly descriptors src/site Site LICENSE.txt Project's license NOTICE.txt Notices and attributions required by libraries that the project depends on README.txt Project's readme
  • 19. 19 Maven POM  POM.xml is the main configuration where it all starts from  There is described  How software is built  Software’s dependencies
  • 20. 20 Maven POM (2) <project> <!-- model version is always 4.0.0 for Maven 2.x POMs --> <modelVersion>4.0.0</modelVersion> <!-- project coordinates, i.e. a group of values which uniquely identify this project --> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1.0</version> <!-- library dependencies --> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> </dependency> </dependencies> </project>
  • 22. 22  Naming Conventions  Project Structures  JavaDoc  Build Automation Summary
  • 24. 24  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" license  Attribution: this work may contain portions from  "Fundamentals of Computer Programming with Java" book by Svetlin Nakov & Co. under CC-BY-SA license  "C# Basics" course by Software University under CC-BY-NC-SA license License
  • 25. Free Trainings @ Software University  Software University Foundation – softuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg  Software University @ Facebook  facebook.com/SoftwareUniversity  Software University @ YouTube  youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bg