package conventions;
class JavaNamingConventions
{
  static final double PI_VALUE = 3.14;
  
  static int circleRadius = 10;

  public static void circleArea()
  {
    System.out.println("Circle Area: " + (PI_VALUE * circleRadius * circleRadius));
  }

  public static void main(String args[])
  {
    // method circleArea() is of static type so we do not need to create an object
    circleArea();
  }
}

static : If a variable or method is of static in nature then we can access it directly without creating an object.
In above java program we used variables, methods, constants, class etc. If you notice then class name is written with first letter as capital of each word. Similarly different naming conventions is followed for constants, variables and methods.
Using naming conventions makes the program more easier to read and understand for you and the other programmer as well.
Before we start with java naming conventions you must know about the camel case as we would we using this term while discussing naming conventions.

CamelCase : CamelCase is a naming convention in which a name is formed of multiple words that are joined together as single word with first letter of each of multiple word as Capital letter. CamelCase may start with a capital or especially in programming languages as lowercase letter.

For example : Love java programming can be written as : LoveJavaProgramming or loveJavaProgramming

Java Naming Conventions For Classes

Classes always start with a capital letter and are CamelCase. Class name should be a noun.
  • class Circle
  • class VehicleSpecification
  • class JavaNamingConventions

Java Naming Conventions For Variables And Methods

Variables and Methods always start with a lowercase letter and are camelCase too. Method name should be a verb.
  • double area = 10.5;
  • int circleRadius = 10;
  • circleRadius( );
  • rectanglePerimeter( );

Java Naming Conventions For Constants

final instance variables can never change and therefore are constant. Constants are always in capital letter, with any breaks between words represented by an underscore.
  • final String TOPIC = “Java Naming Conventions “;
  • final double PI_VALUE = 3.14;
  • final String MY_GIRLFRIEND_NAME = ” Anything which you would like “;

Java Naming Conventions For Packages

Package names are written in all lowercase so as to avoid conflict with the name of classes and interfaces.
  • package integer;
  • package integer.number;

Java Naming Conventions For Interfaces

Interface name is capitalized as class name.
  • interface Sorting
  • interface RectangleProperties
  • interface SortingAndSearching

    You can read naming conventions as mentioned by Oracle : Java Code Conventions

Leave a comment

Your email address will not be published. Required fields are marked *