Below are some naming conventions of 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.
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 capitalised. Interfaces name should also be capitalised just like class names.
- Use whole words and must avoid acronyms and abbreviations.
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 capitalised.
void changeGear(int newValue); void speedUp(int increment); void applyBrakes(int decrement);
- Variables : Variable names should be short yet meaningful.
- Should not start with 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.
// 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.
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;
- 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 organisation’s own internal naming conventions.
com.sun.eng com.apple.quicktime.v2 // java.lang packet in JDK java.lang
This article is contributed by Gaurav Miglani. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Naming a thread and fetching name of current thread in Java
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.function.BiPredicate interface in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java.util.LinkedList.offer(), offerFirst(), offerLast() in Java
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.BitSet class methods in Java with Examples | Set 2