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

What's hot

Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Pratima Parida
 
Programming
ProgrammingProgramming
Programming
mafffffe19
 
Java v/s .NET - Which is Better?
Java v/s .NET - Which is Better?Java v/s .NET - Which is Better?
Java v/s .NET - Which is Better?
NIIT India
 
Curso de Programación Java Intermedio
Curso de Programación Java IntermedioCurso de Programación Java Intermedio
Curso de Programación Java Intermedio
Universidad de Occidente
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
OXUS 20
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
Peter Gfader
 
JAVA Program Examples
JAVA Program ExamplesJAVA Program Examples
JAVA Program Examples
Prof Chethan Raj C
 
Comparison of Programming Platforms
Comparison of Programming PlatformsComparison of Programming Platforms
Comparison of Programming Platforms
Anup Hariharan Nair
 
Curso de Programación Java Básico
Curso de Programación Java BásicoCurso de Programación Java Básico
Curso de Programación Java Básico
Universidad de Occidente
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#rahulsahay19
 
Java for Recruiters
Java for RecruitersJava for Recruiters
Java for Recruitersph7 -
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Java Lover
 
A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net  A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net
Prognoz Technologies Pvt. Ltd.
 
Great cup of java
Great  cup of javaGreat  cup of java
Great cup of javaCIB Egypt
 
Object oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharpObject oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharpAbefo
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
siragezeynu
 
Java vs python
Java vs pythonJava vs python
Java vs python
Rutuja Gholap
 

What's hot (20)

Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
 
Programming
ProgrammingProgramming
Programming
 
Java v/s .NET - Which is Better?
Java v/s .NET - Which is Better?Java v/s .NET - Which is Better?
Java v/s .NET - Which is Better?
 
Java notes
Java notesJava notes
Java notes
 
Curso de Programación Java Intermedio
Curso de Programación Java IntermedioCurso de Programación Java Intermedio
Curso de Programación Java Intermedio
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
 
JAVA Program Examples
JAVA Program ExamplesJAVA Program Examples
JAVA Program Examples
 
C#.NET
C#.NETC#.NET
C#.NET
 
Comparison of Programming Platforms
Comparison of Programming PlatformsComparison of Programming Platforms
Comparison of Programming Platforms
 
Curso de Programación Java Básico
Curso de Programación Java BásicoCurso de Programación Java Básico
Curso de Programación Java Básico
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Java for Recruiters
Java for RecruitersJava for Recruiters
Java for Recruiters
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net  A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net
 
Great cup of java
Great  cup of javaGreat  cup of java
Great cup of java
 
Object oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharpObject oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharp
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Java vs python
Java vs pythonJava vs python
Java vs python
 

Similar to 21. Java High Quality Programming Code

Java basic
Java basicJava basic
Java basic
Arati Gadgil
 
Java platform
Java platformJava platform
Java platform
BG Java EE Course
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
Nicola Pedot
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
José Paumard
 
Testing Toolbox
Testing ToolboxTesting Toolbox
Testing Toolbox
Michael Peters
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
Rich Helton
 
Introduction
IntroductionIntroduction
Introduction
richsoden
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java
Abdelmonaim Remani
 
Ecom lec3 16_ej_bs
Ecom lec3 16_ej_bsEcom lec3 16_ej_bs
Ecom lec3 16_ej_bs
Zainab Khallouf
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
Sadayuki Furuhashi
 
Synapse India Reviews
Synapse India ReviewsSynapse India Reviews
Synapse India Reviews
Synapseindiappsdevelopment
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
Madhura Bhalerao
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introductionvstorm83
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmers
jphl
 
Java Basic PART I
Java Basic PART IJava Basic PART I
Java Basic PART I
Soumen Santra
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
OpenDaylight
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
vmadan89
 
J introtojava1-pdf
J introtojava1-pdfJ introtojava1-pdf
J introtojava1-pdf
Emmanuel Alimpolos
 

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

Java basic
Java basicJava basic
Java basic
 
Java platform
Java platformJava platform
Java platform
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Testing Toolbox
Testing ToolboxTesting Toolbox
Testing Toolbox
 
Java Intro
Java IntroJava Intro
Java Intro
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Introduction
IntroductionIntroduction
Introduction
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java
 
Ecom lec3 16_ej_bs
Ecom lec3 16_ej_bsEcom lec3 16_ej_bs
Ecom lec3 16_ej_bs
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Synapse India Reviews
Synapse India ReviewsSynapse India Reviews
Synapse India Reviews
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmers
 
Java Basic PART I
Java Basic PART IJava Basic PART I
Java Basic PART I
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
J introtojava1-pdf
J introtojava1-pdfJ introtojava1-pdf
J introtojava1-pdf
 

More from Intro C# Book

17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
Intro C# Book
 
Java Problem solving
Java Problem solving Java Problem solving
Java Problem solving
Intro C# Book
 
20.5 Java polymorphism
20.5 Java polymorphism 20.5 Java polymorphism
20.5 Java polymorphism
Intro C# Book
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
Intro C# Book
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
Intro C# Book
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
Intro C# Book
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
Intro C# Book
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity
Intro C# Book
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arrays
Intro C# Book
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
Intro C# Book
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
Intro C# Book
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
Intro C# Book
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
Intro C# Book
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
Intro C# Book
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
Intro C# Book
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
Intro C# Book
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
Intro C# Book
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
Intro C# Book
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
Intro C# Book
 
23. Methodology of Problem Solving
23. Methodology of Problem Solving23. Methodology of Problem Solving
23. Methodology of Problem Solving
Intro C# Book
 

More from Intro C# Book (20)

17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
 
Java Problem solving
Java Problem solving Java Problem solving
Java Problem solving
 
20.5 Java polymorphism
20.5 Java polymorphism 20.5 Java polymorphism
20.5 Java polymorphism
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arrays
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
 
23. Methodology of Problem Solving
23. Methodology of Problem Solving23. Methodology of Problem Solving
23. Methodology of Problem Solving
 

Recently uploaded

History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
VivekSinghShekhawat2
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 

Recently uploaded (20)

History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 

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