blob: 4ecea61f4f5711cf0624cb18025c276ed8e5ca97 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Coding Standards :: Apache Felix</title>
<link rel="canonical" href="https://felix.apache.org/documentation/development/coding-standards.html">
<meta name="generator" content="Antora 2.3.4">
<link rel="stylesheet" href="../../_/css/site.css">
<link rel="icon" href="../../_/img/favicon.png" type="image/x-icon">
</head>
<body class="article">
<header class="header">
<nav class="navbar">
<div class="navbar-brand">
<a class="navbar-item" href="https://felix.apache.org/index.html">
<span>
<img src="../../_/img/logo.png">
</span>
</a>
<button class="navbar-burger" data-target="topbar-nav">
<span></span>
<span></span>
<span></span>
</button>
</div>
<div id="topbar-nav" class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item" href="https://felix.apache.org/index.html">Home</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Subprojects</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="../subprojects/apache-felix-dependency-manager.html">Dependency Manager</a>
<a class="navbar-item" href="../subprojects/apache-felix-event-admin.html">Event Admin</a>
<a class="navbar-item" href="../subprojects/apache-felix-file-install.html">File Install</a>
<a class="navbar-item" href="../subprojects/apache-felix-framework.html">Framework</a>
<a class="navbar-item" href="../subprojects/apache-felix-gogo.html">Gogo Shell</a>
<a class="navbar-item" href="../subprojects/apache-felix-healthchecks.html">Health Checks</a>
<a class="navbar-item" href="../subprojects/apache-felix-inventory.html">Inventory</a>
<a class="navbar-item" href="../subprojects/apache-felix-log.html">Log</a>
<a class="navbar-item" href="../subprojects/apache-felix-logback.html">Logback</a>
<a class="navbar-item" href="../subprojects/apache-felix-maven-bundle-plugin.html">Maven bundle plugin</a>
<a class="navbar-item" href="../subprojects/apache-felix-maven-scr-plugin.html">Maven SCR plugin</a>
<a class="navbar-item" href="../subprojects/apache-felix-metatype-service.html">Metatype Service</a>
<a class="navbar-item" href="../subprojects/apache-felix-preferences-service.html">Preferences Service</a>
<a class="navbar-item" href="../subprojects/apache-felix-remote-shell.html">Remote Shell</a>
<a class="navbar-item" href="../subprojects/apache-felix-script-console-plugin.html">Script console plugin</a>
<a class="navbar-item" href="../subprojects/apache-felix-shell.html">Lightweight shell</a>
<a class="navbar-item" href="../subprojects/apache-felix-shell-tui.html">Shell TUI</a>
<a class="navbar-item" href="../subprojects/apache-felix-web-console.html">Web Console</a>
</div>
</div>
<div class="navbar-item">
<span class="control">
<a class="button is-primary" href="../downloads.html">Downloads</a>
</span>
</div>
</div>
</div>
</nav>
</header>
<div class="body">
<div class="nav-container" data-component="documentation" data-version="master">
<aside class="nav">
<div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
<nav class="nav-menu">
<h3 class="title"><a href="../index.html">Documentation</a></h3>
<ul class="nav-list">
<li class="nav-item" data-depth="0">
<ul class="nav-list">
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../documentation.html">Documentation</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../downloads.html">Downloads</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../getting-started.html">Getting Started</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../news.html">News</a>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">Community</span>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../community/project-info.html">Apache Felix Project Info</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../community/contributing.html">Contributing</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../community/projects-using-felix.html">Projects Using Felix</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">Development</span>
<ul class="nav-list">
<li class="nav-item is-current-page" data-depth="2">
<a class="nav-link" href="coding-standards.html">Coding Standards</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="dependencies-file-template.html">DEPENDENCIES file template</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="provisional-osgi-api-policy.html">Provisional OSGi API Policy</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="release-management-nexus.html">Release Management</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="site-how-to.html">Site How To</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="using-the-osgi-compliance-tests.html">Using the OSGi Compliance Tests</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../faqs.html">FAQS</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../faqs/apache-felix-bundle-plugin-faq.html">Apache Felix Bundle Plugin Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../faqs/apache-felix-scr-plugin-faq.html">Apache Felix SCR Plugin Frequently Asked Questions</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../subprojects.html">Subprojects</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager.html">Apache Felix Dependency Manager</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Guides</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/migrating-from-earlier-versions.html">Apache Felix Dependency Manager - Migrating from earlier versions</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/annotations.html">Dependency Manager - Annotations</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/background.html">Dependency Manager - Background</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/bundles-and-dependencies.html">Dependency Manager - Bundles and Dependencies</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/design-patterns.html">Dependency Manager - Design Patterns</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/development.html">Dependency Manager - Development</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/history.html">Dependency Manager - History</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/javadocs.html">Dependency Manager - JavaDocs</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/migrating-from-other-solutions.html">Dependency Manager - Migrating from other solutions.</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/performance-tuning.html">Dependency Manager - Performance Tuning</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/resources.html">Dependency Manager - Resource adapters</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/whatsnew.html">Dependency Manager - What&#8217;s new in version 4?</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/dm-lambda.html">Dependency Manager Lambda</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/guides/whatsnew-r15.html">What&#8217;s New in R15</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Reference</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/component-adapter.html">Dependency Manager - Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/component-aspect.html">Dependency Manager - Aspect</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/component-bundle-adapter.html">Dependency Manager - Bundle Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/dependency-bundle.html">Dependency Manager - Bundle Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/components.html">Dependency Manager - Components</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/dependency-configuration.html">Dependency Manager - Configuration Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/dependencies.html">Dependency Manager - Dependencies</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/external-links.html">Dependency Manager - External Links</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/component-factory-configuration-adapter.html">Dependency Manager - Factory Configuration Adapter Service</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/component-resource-adapter.html">Dependency Manager - Resource Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/dependency-resource.html">Dependency Manager - Resource Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/dependency-service.html">Dependency Manager - Service Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/service-scopes.html">Dependency Manager - Service Scopes</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/component-singleton.html">Dependency Manager - Singleton Component</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/thread-model.html">Dependency Manager - Thread Model</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/reference/dm-annotations.html">Dependency Manager Annotations</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Tutorials</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/tutorials/working-with-annotations.html">Dependency Manager - Annotations</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/tutorials/getting-started.html">Dependency Manager - Getting Started</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/tutorials/leveraging-the-shell.html">Dependency Manager - Leveraging the shell</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-dependency-manager/tutorials/sample-code.html">Dependency Manager sample projects</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-event-admin.html">Apache Felix Event Admin</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-file-install.html">Apache Felix File Install</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../subprojects/apache-felix-framework.html">Apache Felix Framework</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-framework/apache-felix-framework-bundle-cache.html">Apache Felix Framework Bundle Cache</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-framework/apache-felix-framework-configuration-properties.html">Apache Felix Framework Configuration Properties</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-framework/apache-felix-framework-faq.html">Apache Felix Framework Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-framework/apache-felix-framework-launching-and-embedding.html">Apache Felix Framework Launching and Embedding</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-framework/apache-felix-framework-usage-documentation.html">Apache Felix Framework Usage Documentation</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-framework-security.html">Apache Felix Framework Security</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../subprojects/apache-felix-gogo.html">Apache Felix Gogo</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-gogo/rfc-147-overview.html">RFC 147 Overview</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-healthchecks.html">Apache Felix Health Checks</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-inventory.html">Apache Felix Inventory Printer</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-log.html">Apache Felix Log</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-logback.html">Apache Felix Logback</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-maven-bundle-plugin-bnd.html">Apache Felix Maven Bundle Plugin (BND)</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-metatype-service.html">Apache Felix Metatype Service</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-osgi-bundle-repository.html">Apache Felix OSGi Bundle Repository (OBR)</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-preferences-service.html">Apache Felix Preferences Service</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-remote-shell.html">Apache Felix Remote Shell</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-shell.html">Apache Felix Shell</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../subprojects/apache-felix-shell-tui.html">Apache Felix Shell TUI</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../subprojects/apache-felix-web-console.html">Apache Felix Web Console</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console.html">Extending the Apache Felix Web Console</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-web-console/web-console-restful-api.html">Web Console RESTful API</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-web-console/web-console-security-provider.html">Web Console Security Provider</a>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Extensions</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/branding-the-web-console.html">Branding the Web Console</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/providing-resources.html">Providing Resources</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/providing-web-console-plugins.html">Providing Web Console Plugins</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/web-console-logging.html">Web Console Logging</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/web-console-output-templating.html">Web Console Output Templating</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">Maven SCR plugin</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-maven-scr-plugin/apache-felix-maven-scr-plugin-use.html">Apache Felix Maven SCR Plugin Use</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-bndtools-use.html">Apache Felix SCR Annotations BndTools Use</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-ant-task-use.html">Apache Felix SCR Ant Task Use</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-maven-scr-plugin/extending-scr-annotations.html">Extending SCR Annotations Excerpt: How add new Annotations extending the base Annotations</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-maven-scr-plugin/scr-annotations.html">SCR Annotations Excerpt: Using Java 5 Annotations to describe the component or service.</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../subprojects/apache-felix-maven-scr-plugin/scr-javadoc-tags.html">SCR JavaDoc Tags Excerpt: Using JavaDoc Tags to describe the component or service.</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../tutorials-examples-and-presentations.html">Tutorials</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-application-demonstration.html">Apache Felix Application Demonstration</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial.html">Apache Felix OSGi Tutorial</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-faq.html">OSGi Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">OSGI Tutorial</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-1.html">Apache Felix Tutorial Example 1 - Service Event Listener Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-2.html">Apache Felix Tutorial Example 2</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-2b.html">Apache Felix Tutorial Example 2b</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-3.html">Apache Felix Tutorial Example 3</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-4.html">Apache Felix Tutorial Example 4</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-5.html">Apache Felix Tutorial Example 5</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-6.html">Example 6 - Spell Checker Service Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-7.html">Example 7 - Spell Checker Client Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-8.html">Example 8 - Spell Checker Service using Service Binder</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-9.html">Example 9 - Spell Checker Service using Declarative Services</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../license.html">Apache License 2.0</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../site-map.html">Site map</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
<div class="context">
<span class="title">Documentation</span>
<span class="version">master</span>
</div>
<ul class="components">
<li class="component is-current">
<span class="title">Documentation</span>
<ul class="versions">
<li class="version is-current is-latest">
<a href="../index.html">master</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
<a href="../index.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
<ul>
<li><a href="../index.html">Documentation</a></li>
<li>Development</li>
<li><a href="coding-standards.html">Coding Standards</a></li>
</ul>
</nav>
<div class="edit-this-page"><a href="https://github.com/apache/felix-antora-site/edit/main/modules/ROOT/pages/development/coding-standards.adoc">Edit this Page</a></div>
</div>
<div class="content">
<article class="doc">
<h1 class="page">Coding Standards</h1>
<div class="sect1">
<h2 id="_guidelines_summary"><a class="anchor" href="#_guidelines_summary"></a>Guidelines Summary</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This style guide is intended to help the computer professional produce better Java programs.
It presents a set of specific guidelines for using the features of Java in a disciplined manner.
The goal is to develop high quality, reliable, reusable, portable software.
For a number of reasons, no programming language can ensure the achievements of these desirable objectives on its own.
Programming must be embedded in a disciplined development process that addresses a number of topics in a well managed way.
The use of Java is one of those.
It must conform to good programming practices be based on well established software engineering principles.
This style guide is intended to bridge the gap between these principles and the actual practice of programming in Java.</p>
</div>
<div class="paragraph">
<p>Clear, readable, understandable source text eases program evolution, adaptation and maintenance.
First, such source text is more likely to be correct and reliable.
Second, effective code adaptation is a prerequisite to code reuse, a technique that has the potential for drastic reductions in system development costs.
Easy adaptation requires thorough understanding of the software, and that is facilitated considerably by clarity.
Finally, since maintenance (really evolution) is a costly process that continues throughout the life of a system, clarity plays a major role in keeping maintenance costs down.
Over the entire life cycle, code has to be read and understood far more often than it is written;
the investment of effort in writing readable, understandable code is thus well worthwhile.
Many of the guidelines in this style guide are designed to promote clarity of the source text.</p>
</div>
<div class="paragraph">
<p>This style guide is intended for those involved in the development of real software systems written in Java.
Different roles in a software project can exploit the style guide in different ways.
The programmer can use it as a reference on good Java style.
It can be used in code reviews as a common reference.
Finally, lessons learned in real projects can be captured by extending the style guide.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_class_layout_and_comments"><a class="anchor" href="#_class_layout_and_comments"></a>Class layout and comments</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_files_and_filenames"><a class="anchor" href="#_files_and_filenames"></a>Files and filenames</h3>
<div class="paragraph">
<p>Files longer than 2000 lines are cumbersome and should be avoided.</p>
</div>
<div class="sect3">
<h4 id="_file_names"><a class="anchor" href="#_file_names"></a>File names</h4>
<div class="paragraph">
<p>The file must be named after the class it represents.
As for most cases each file contains only one class, this is an easy naming convention.
For nested or inner classes the name of the main class must be the name of the file.
As names in Java are case-sensitive, the filename is case-sensitive also.</p>
</div>
</div>
<div class="sect3">
<h4 id="_file_organization"><a class="anchor" href="#_file_organization"></a>File organization</h4>
<div class="paragraph">
<p>Each Java source file contains a single class or interface.
Of course, this excludes inner classes as these must be defined without an (outer) class, and thus in the same file.</p>
</div>
<div class="paragraph">
<p>Java source files have the following ordering:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Beginning comments</p>
</li>
<li>
<p>Package and import statements</p>
</li>
<li>
<p>Class and interface declarations</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="_beginning_comments"><a class="anchor" href="#_beginning_comments"></a>Beginning comments</h4>
<div class="paragraph">
<p>All source files must begin with the comments shown in the following code sample.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-text hljs" data-lang="text"> /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that this comment part is not according to the JavaDoc style (See: How to write doc comments for JavaDoc - Sun Microsystems, Inc.) as this is file specific information that is not relevant in generated API documentation.</p>
</div>
<div class="sect4">
<h5 id="_package_and_import_statements"><a class="anchor" href="#_package_and_import_statements"></a>Package and import Statements</h5>
<div class="paragraph">
<p>The first non-comment line of most Java source files is a package statement.
After an empty line import statements can follow.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">package org.apache.felix.whatever.this.is;
import java.awt.Frame;
import java.io.InputStream;
import java.util.Vector;</code></pre>
</div>
</div>
<div class="paragraph">
<p>A few notes must be made here:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Package rules.
When not using an explicit package statement in your code the code still is in a package, the default package.
This easily results in name clashes and as package naming should be a part of the design, always use an explicit package name.
For naming rules of packages see 3.4 Naming conventions.</p>
</li>
<li>
<p>Import statements need to be explicit in order to overcome name clashes.
They should be grouped by name.
When the number of import statements of the same package exceeds the 'readability' limit (please use common sense), then import the complete package by adding '.*'.</p>
</li>
<li>
<p>Import order.
First in this section should be the standard Java imports like: java.lang.Throwable.
Second should be the Java extensions (i.e.
javax), third, the third party stuff.
Finally the project-specific imports should be added.</p>
</li>
</ol>
</div>
</div>
<div class="sect4">
<h5 id="_class_and_interface_declarations"><a class="anchor" href="#_class_and_interface_declarations"></a>Class and interface Declarations</h5>
<div class="paragraph">
<p>The following comment block is an example for the comment that belongs to the declaration of a class or an interface.
The combination of JavaDoc syntax and keywords that are expanded by the source integrity tool result in the following block:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> /**
* This class is not really a class, because this file is just
* a template that shows how the file header and class header
* should look like.
*
* @author &lt;a href="mailto:dev@felix.apache.org"&gt;Felix Project Team&lt;/a&gt;
*/</code></pre>
</div>
</div>
<div class="paragraph">
<p>The following table describes the parts of a class or interface declaration, in the order that they should appear.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Part of Class/Interface Declaration</th>
<th class="tableblock halign-left valign-top">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Class/Interface documentation</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">According to comment block as shown above.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Class or interface statement</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Class (static) variables</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">These should be grouped by functionality rather than by scope.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Instance variables</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">These should be grouped by functionality rather than by scope.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Constructors</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Start with the default constructor if any.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Methods that belong to the class (see also 2.1.3.4 Class methods versus specific interface methods and event methods)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">These methods should also be grouped by functionality rather than by scope or accessibility.
E.g.
a private class method can be in between two public instance methods.
The goal is to make reading and understanding the code easier.
When implementing an interface, group the methods that are part of the interface.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Methods of interfaces that are implemented by the class.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Automatically grouped by functionality if grouped by interface.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Inner classes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">As they are only visible within their top-level class, they are placed at the bottom of the file.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_indentation"><a class="anchor" href="#_indentation"></a>Indentation</h3>
<div class="paragraph">
<p>Four spaces should be used as unit of indentation.
Use spaces or let your editor convert tabs to spaces as some editors might show the tabs different than they were intended!
Tabs must be set exactly every 4 spaces.</p>
</div>
<div class="sect3">
<h4 id="_line_length"><a class="anchor" href="#_line_length"></a>Line length</h4>
<div class="paragraph">
<p>There is no explicit limit for the length of a line.
Make sure that the flow of the code is clear and that, when printing the file, it is well formed when using a reasonable font.
A reasonable length would be around 80 characters.</p>
</div>
</div>
<div class="sect3">
<h4 id="_wrapping_lines"><a class="anchor" href="#_wrapping_lines"></a>Wrapping lines</h4>
<div class="paragraph">
<p>When an expression will not fit on a single line, break it according to these general principles:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>break after a comma;</p>
</li>
<li>
<p>break before an operator;</p>
</li>
<li>
<p>prefer higher level breaks to lower level breaks;</p>
</li>
<li>
<p>align the new line with the beginning of the expression after the assignment;</p>
</li>
<li>
<p>if the above rules lead to confusing code or to code that&#8217;s squished up against the right margin, please use common sense.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Some examples breaking an arithmetic expression.
The first is preferred, since the break occurs outside the parenthesised expression:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> longName1 = longName2 * (longName3 + longName4 - longName5)
+ 4; // preferred
longName1 = longName2 * (longName3 + longName4
- longName5) + 4;</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_comment"><a class="anchor" href="#_comment"></a>Comment</h3>
<div class="sect3">
<h4 id="_comment_styles"><a class="anchor" href="#_comment_styles"></a>Comment styles</h4>
<div class="paragraph">
<p>The Java language supports three different kinds of comments:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> // text</code></pre>
</div>
</div>
<div class="paragraph">
<p>The compiler ignores everything from // to the end of the line.
Use this style when adding a description or some kind of explanation at the same line of code.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> /* text */</code></pre>
</div>
</div>
<div class="paragraph">
<p>The compiler ignores everything from /* to */.
The next documentation style is preferred.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> /** Documentation. */</code></pre>
</div>
</div>
<div class="paragraph">
<p>This indicates a documentation comment (doc comment, for short).
The compiler ignores this kind of comment, just like it ignores comments that use /* and */.
The JDK JavaDoc tool uses doc comments when preparing automatically generated documentation (See: JavaDoc keywords and HTML tags).
But JavaDoc only uses this documentation when it occurs at an expected position in the file like the class definition or a member declaration.</p>
</div>
</div>
<div class="sect3">
<h4 id="_block_comments"><a class="anchor" href="#_block_comments"></a>Block comments</h4>
<div class="paragraph">
<p>Block comments are used to provide English descriptions of the contents of files, the task of methods and the description of data structures and algorithms.
Block comments should be used at the beginning of each file and before each method.
They can also be used in other places, such as within methods.</p>
</div>
<div class="paragraph">
<p>For a description of class comment see 2.1.3.3 Class and Interface Declarations.
A method block comment looks as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> /**
* Position the splitter location at a specified position.
* This method can for instance be used when the last position
* is stored as a preference setting for the user.
*
* @param position New position of divider, defined in pixels
* from the left of the containing window
* @see com.sun.java.swing.JSplitPane
* @exception org.apache.felix.player.PositionException
* Whenever an invalid position is passed.
*/
public void setSplitterLocation(int position) throws PositionException</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_javadoc_keywords_and_html_tags"><a class="anchor" href="#_javadoc_keywords_and_html_tags"></a>JavaDoc keywords and HTML tags</h4>
<div class="paragraph">
<p>For class headers, method headers and member variables JavaDoc is used in order to generate API documentation from the source later on (See: JavaDoc homepage - Sun Microsystems, Inc.).
A few specific JavaDoc keywords are:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Keyword</th>
<th class="tableblock halign-left valign-top">Short description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">@version</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Can be used to label a specific version of a package or application so the documentation shows this version number also.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">@author</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The name entered here is shown as the author.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">@param</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Used to define one parameter and describe this parameter.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">@see</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">When there are similarities with another class this tag is used to offer the reader a hyperlink to the mentioned class.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">@exception or @throws</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Offered as hyperlink to the exception that can be thrown by a method.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">@return</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Return value of a method</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>Some HTML-tags that can be used in order to make the comment blocks more readable:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Tag</th>
<th class="tableblock halign-left valign-top">Short description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;p&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">New paragraph.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><br></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Break, a carriage return.
For separation of two paragraphs, usage of &lt;p&gt; is preferred.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;ul&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Unordered list of items;
each item should start with a &lt;li&gt; tag.
By most browsers, this is formatted as a bulleted list.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">``</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Code samples;
use this when refering to class names, method names, parameter names, etc.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;pre&gt;&lt;/pre&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Preformatted text.
Use these tags to protect figures and schemas "drawn" in Ascii, against formatting by the browser (which normally ignores whitespace and line breaks)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;dl&gt;&lt;dt&gt;&lt;/dt&gt;&lt;dd&gt;&lt;/dd&gt;&lt;/dl&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Definition lists;
&lt;dt&gt; specifies the term that is defined and &lt;dd&gt; the definition of this term.
Not frequently used.</p></td>
</tr>
</tbody>
</table>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
there is no need to embed the parameter name in the @param tag in ` tags;
this is done by javadoc automatically.
The same holds for the exception name in the @exception or @throws tag.
In the clarifying text however, use the `
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> /**
* Prints a range from an object array. The range
* is specified by the first element to print, and
* ranges to the last element of the array.
*
* @param array contains the objects to print
* @param first index of first element in
* the &lt;code&gt;array&lt;/code&gt; to print
*/
public void printRange(Object[] array, int first)</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_java_syntax_and_its_layout"><a class="anchor" href="#_java_syntax_and_its_layout"></a>Java syntax and its layout</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_declarations"><a class="anchor" href="#_declarations"></a>Declarations</h3>
<div class="paragraph">
<p>When declaring a variable or method make the accessibility as restrictive as possible.
When using multiple keywords use the following ordering of keywords:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>accessibility Start with the accessibility as it makes clear if the method or variable is reachable at all.</p>
</li>
<li>
<p>static (if applicable)</p>
</li>
<li>
<p>final (if applicable)</p>
</li>
<li>
<p>return type (methods only) or type (for variables) The type is for readability as close as possible to the name.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>This order is also compatible with the order that is used in Java for the main() method.
This results in following sequence:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> // A familiar one:
public static void main(String[] args) {}
private static String m_lastCreated = null;
private static final int RED = 4711;</code></pre>
</div>
</div>
<div class="sect3">
<h4 id="_number_per_line"><a class="anchor" href="#_number_per_line"></a>Number per line</h4>
<div class="paragraph">
<p>One declaration per line is recommended since it encourages commenting and it does not lead to confusing code.
It also is more clear about the explicit initialization of variables as discussed in Initialization.</p>
</div>
<div class="paragraph">
<p>Example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> int level = 0; // level where user enters the system
int horizontalSize = 0; // horizontal size of current level layer</code></pre>
</div>
</div>
<div class="paragraph">
<p>is preferred over:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> int level, horizontalSize; // level and size of current level layer</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_placement"><a class="anchor" href="#_placement"></a>Placement</h4>
<div class="paragraph">
<p>In a method, declare local variables just before they are needed.
This overcomes the problem of a big list of parameters at the beginning of a method and the use of a variable becomes more clearly in the context of the code, .e.g.
its initialization.</p>
</div>
</div>
<div class="sect3">
<h4 id="_initialization"><a class="anchor" href="#_initialization"></a>Initialization</h4>
<div class="paragraph">
<p>The initialization of class variables is strictly not necessary because of the default initialization that takes place for these kinds of members.
For some types, e.g.
Booleans, this requires detailed knowledge of all the default values so it is more clear and explicit to initialize each member.
Variables that are used and declared within methods must always be initialized explicitly (the compiler will generate an error when you forget this).</p>
</div>
</div>
<div class="sect3">
<h4 id="_class_and_interface_declarations_2"><a class="anchor" href="#_class_and_interface_declarations_2"></a>Class and Interface Declarations</h4>
<div class="paragraph">
<p>When coding Java classes and interfaces, the following formatting rules should be followed:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>no space between a method and its parameter list</p>
</li>
<li>
<p>"{" is on a line by itself indented to match its corresponding opening statetment, except when it is a null statement, in which case the "{" should appear on the same line as the opening statement</p>
</li>
<li>
<p>"}" starts a line by itself indented to match its corresponding opening statement, except when it is a null statement, in which the case the "}" should appear immediately after the "{".</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">class ShipmoTrial extends Trial
{
int m_index = 0;
ShipmoTrial(int index)
{
m_index = index;
}
void emptyMethod() {}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_statements"><a class="anchor" href="#_statements"></a>Statements</h3>
<div class="sect3">
<h4 id="_simple_statements"><a class="anchor" href="#_simple_statements"></a>Simple statements</h4>
<div class="paragraph">
<p>Each line should contain at most one statement.</p>
</div>
<div class="paragraph">
<p>Example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> // Do not use this
argv++; argc++;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_compound_statements"><a class="anchor" href="#_compound_statements"></a>Compound statements</h4>
<div class="paragraph">
<p>Compound statements are statements that contain lists of statements enclosed in braces ("{&#8230;&#8203;}"):</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The enclosed statements should be indented one more level than the compound statement.</p>
</li>
<li>
<p>The opening brace should be at the end of the line that begins the compound statement;
the closing brace should begin a line and be indented to the beginning of the compound statement.</p>
</li>
<li>
<p>Braces are used around all statements, even single statements, when they are part of a control structure, such as a if-else or for statement.
This makes it easier to add statements without accidentally introducing bugs due to forgetting to add braces.</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="_if_if_else_if_else_if_else_statements"><a class="anchor" href="#_if_if_else_if_else_if_else_statements"></a>if, if-else, if else-if else statements</h4>
<div class="paragraph">
<p>There are a lot of nested possibilities for if-else constructions.
All these variations can be programmed in very cryptic ways that easily and often will lead to buggy code.
By being more explicit in the used coding style a lot of confusion can be taken away.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
When using only one statement in a compound block brackets are optional.
It can be a good practice to use always brackets because mistakes can be made easily when adding a second statement and brackets are forgotten.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The following example illustrates the correct use of brackets in a few different if-then-else constructions:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">if (condition)
{
statement1;
statement2;
}
else
{
statement3;
}
if (condition)
{
statement1;
statement2;
}
else if (condition1)
{
statement3;
statement4;
}
else
{
statement5;
statement6;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that in the example the else if construction is started at a new line so the statement can not be overlooked.</p>
</div>
</div>
<div class="sect3">
<h4 id="_switch"><a class="anchor" href="#_switch"></a>switch</h4>
<div class="paragraph">
<p>When using a switch statement use following guidelines:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Every switch statement should include a default case.
The break in the default case is redundant, but it prevents a fall-through error if later another case is added.</p>
</li>
<li>
<p>The so-called fall-through construction should be avoided.
Only when there are good reasons to use it, make sure that it is very clear that a fall-through is used (comment it).</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The next example shows the sample code that uses the guidelines for a switch statement:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> switch (condition)
{
case A:
statements;
// falls through here!!
case B:
statements;
break;
default:
statements;
break;
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_try_catch"><a class="anchor" href="#_try_catch"></a>try - catch</h4>
<div class="paragraph">
<p>A try - catch statement should have the following format:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> try
{
statements;
}
catch (ExceptionClass ex)
{
statements;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>When using finally to add code that always will be executed this will look like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> try
{
statements;
}
catch (ExceptionClass ex)
{
statements;
}
finally
{
statements;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that the catch and the finally start at a new line in order to be compliant to the guidelines for if-then-else statements.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_white_space"><a class="anchor" href="#_white_space"></a>White Space</h3>
<div class="sect3">
<h4 id="_blank_lines"><a class="anchor" href="#_blank_lines"></a>Blank lines</h4>
<div class="paragraph">
<p>Blank lines improve readability by setting of sections of code that are logically related.</p>
</div>
<div class="paragraph">
<p>Two blank lines should always be used in the following circumstances:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>between class and interface definitions;</p>
</li>
<li>
<p>between a group of methods that belong together (by its functionality or because they are part of the same interface).</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>One blank line should always be used in the following circumstances:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>between methods;</p>
</li>
<li>
<p>before a block or single line comment;</p>
</li>
<li>
<p>between logical sections inside a method to improve readability.</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="_blank_spaces"><a class="anchor" href="#_blank_spaces"></a>Blank spaces</h4>
<div class="paragraph">
<p>Blank spaces should be used in the following circumstances:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A keyword followed by a parenthesis should be separated by a space.</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">while (ready == false) { ...
}</code></pre>
</div>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>Note that blanks should not be used between a method call and its opening parenthesis.
This helps to distinguish keywords from function calls.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Blanks should appear after commas in argument lists.</p>
</li>
<li>
<p>All binary operators except "." should be separated from their operands by spaces.
Blanks should never separate unary operators such as unary minus, increment("&#43;&#43;") and decrement("--") from their operands.</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">a += c + d;
a = (a + b) / (c * d);
xCoord{pp};</code></pre>
</div>
</div>
</li>
<li>
<p>The expressions in a for statement should be separated by blanks.</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">for (expr1; cond1; expr2)</code></pre>
</div>
</div>
</li>
<li>
<p>Casts should be followed by a blank.</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">myInstance.doIt((TreeFrame) frame);</code></pre>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_naming_conventions"><a class="anchor" href="#_naming_conventions"></a>Naming conventions</h3>
<div class="paragraph">
<p>Naming conventions make programs more understandable by making them easier to read.
They can also give information about the function of the identifier.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Identifier Type</th>
<th class="tableblock halign-left valign-top">Rules for Naming</th>
<th class="tableblock halign-left valign-top">Examples</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Interfaces</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Interface names should be capitalized like class names.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">interface Enumeration;</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Methods</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Methods should be verbs in mixed case with the first letter lowercase.
Within each method name capital letters separate words.
Property methods or get-set methods are used as follows:</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Constant (static final) variables</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Names should be all uppercase with words separated by underscores ("_").</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">public static final int BLACK = 99;</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Exceptions</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Like class names;
always ending in "Exception"</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">InputException</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Packages</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Lowercase only;
avoid lengthy package names;
always start with org.apache.felix.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.felix.demo.bundle</p></td>
</tr>
</tbody>
</table>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
All Java identifiers are case sensitive.
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_references"><a class="anchor" href="#_references"></a>References</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>Java Code Conventions - Sun Microsystems, Inc.
No ref.
number, only hyperlink: <a href="http://java.sun.com/docs/codeconv/" class="bare">http://java.sun.com/docs/codeconv/</a></p>
</li>
<li>
<p>How to Write Doc Comments for JavaDoc - Sun Microsystems, Inc.
<a href="http://java.sun.com/products/jdk/javadoc/writingdoccomments.html" class="bare">http://java.sun.com/products/jdk/javadoc/writingdoccomments.html</a></p>
</li>
<li>
<p>JavaDoc homepage - Sun Microsystems, Inc.
<a href="http://java.sun.com/products/jdk/javadoc/" class="bare">http://java.sun.com/products/jdk/javadoc/</a></p>
</li>
<li>
<p><a href="https://issues.apache.org/jira/secure/attachment/12419890/Apache+Felix+Eclipse+Template.xml">Eclipse formatting template</a>.</p>
</li>
</ul>
</div>
</div>
</div>
</article>
<aside class="toc sidebar" data-title="Contents" data-levels="2">
<div class="toc-menu"></div>
</aside>
</div>
</main>
</div>
<footer class="footer">
<p>Content licensed under AL2. UI licensed under MPL-2.0 with extensions licensed under AL2</p>
</footer>
<script src="../../_/js/site.js"></script>
<script async src="../../_/js/vendor/highlight.js"></script>
</body>
</html>