Friday, 22 September 2017

Java Naming Conventions

Below are some naming conventions of for java programming language. They must be followed while developing software in java for good maintenance and readability of code. Java uses CamelCase as a practice for writing names of methods, variables, classes, packages, and constants.

Naming Conventions Table:


Camel case in Java Programming: It consists of compound words or phrases such that each word or abbreviation begins with a capital letter or first word with a lowercase letter, rest all with capital.
èClasses and Interfaces :
§  Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Interfaces name should also be capitalized just like class names.
§  Use whole words and must avoid acronyms and abbreviations.
Examples:
Interface  Bicycle
Class MountainBike implements Bicyle

Interface Sport
Class Football implements Sport
    èMethods :
§  Methods should be verbs, in mixed case with the first letter lowercase and with the first letter of each internal word capitalized.
Examples:
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
    è Variables: Variable names should be short yet meaningful.
§  Should not start with an underscore(‘_’) or dollar sign ‘$’ characters.
§  Should be mnemonic i.e, designed to indicate to the casual observer the intent of its use.
§  One-character variable names should be avoided except for temporary variables.
§  Common names for temporary variables are I, j, k, m, and n for integers; c, d, and e for characters.
Examples:
    // variables for MountainBike class
    int speed = 0;
    int gear = 1;
    èConstant variables:
§  Should be all uppercase with words separated by underscores (“_”).
§  There are various constants used in predefined classes like Float, Long, String etc.
Examples:
static final int MIN_WIDTH = 4;

// Some  Constant variables used in predefined Float class
public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
public static final float NaN = 0.0f / 0.0f;
   è Packages:
§  The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, like com, edu, gov, mil, net, Org.
§  Subsequent components of the package name vary according to an organization’s own internal naming conventions.
Examples:
com.sun.eng
com.apple.quicktime.v2

// java.lang packet in JDK
java.lang

 

4 comments:

  1. This is a very nice one and gives in-depth information. I am really happy with the quality and presentation of the article.

    Java course in Chennai

    ReplyDelete
  2. amazing writeup. keep posting java classes in pune

    ReplyDelete
  3. Looking for the best forex trading platform and the top forex brokers in 2025? Winprofx stands out as your ultimate partner in navigating the dynamic world of forex trading. In a market flooded with options, Winprofx simplifies your journey by offering powerful tools, real-time insights, and expert guidance that elevate your trading experience. As one of the most trusted names in the industry, Winprofx connects you with top forex brokers who are known for tight spreads, fast execution, and regulatory compliance. Whether you're a beginner or an experienced trader, the Winprofx platform is designed to support your growth with intuitive interfaces, advanced charting tools, and educational resources tailored to your skill level. In 2025, traders demand speed, transparency, and security—and Winprofx delivers all three with consistency. The platform also offers demo accounts, forex signals, and up-to-date market analysis, making it easier for users to make informed decisions. With a focus on client success and industry innovation, Winprofx continues to rank among the best forex trading platforms globally. Join thousands of satisfied traders who trust Winprofx to maximize their potential and reach their financial goals in the fast-paced forex market of 2025.



    Best Forex Trading Platform-





    ReplyDelete