What are the naming conventions in Java? https://www.educative.io/answers/what-are-the-namin...
Courses Log In Join for free
Explore
New
CloudLabs
Personalized
Paths
Projects
Skill Paths
Assessments
1 of 8 21/09/2023, 11:52
What are the naming conventions in Java? https://www.educative.io/answers/what-are-the-namin...
Trusted answers to developer questions
Explore
What are the naming conventions in Java?
New
CloudLabs
Free System Design Interview Course
Many candidates are rejected or down-leveled due to poor performance in their
Personalized
System
Paths
Design Interview. Stand out in System Design Interviews and get hired in
2023 with this popular free course.
Get
Projects Free Course
Overview
Skill Paths
Naming
Assessments conventions in Java are a set of rules that apply to Java programs,
and are defined in The Java Language Specification. They include
recommendations for naming packages, classes, methods, and variables.
This shot discusses some basic naming conventions in Java.
PascalCasing
PascalCasing is a naming convention where each word in a compound
word is capitalized. "JavaNamingConventions" is an example of a
PascalCased word in Java.
camelCasing
In camelCasing, the first word in a compound word is not capitalized.
"javaNamingConventions" is an example of a camelCased word in Java.
snake_casing
2 of 8 21/09/2023, 11:52
What are the naming conventions in Java? https://www.educative.io/answers/what-are-the-namin...
In snake_casing, underscores separate the words in a compound word.
Did you find this helpful?
"java_naming_conventions" is an example of a snake_cased word in Java.
Explore
New Naming conventions in Java
CloudLabs
Construct Convention Description Examples
Class PascalCase Classes should be named MyClass, Employee
Personalized
Paths
using PascalCasing, with
the first letter of each
word capitalized. A class
Projects name should be a noun
or a word
representative of an
Skill Paths
object.
Interface PascalCase Interfaces should be Serializable, Runnable
Assessments named using
PascalCasing, with the
first letter of each word
capitalized. An interface
name should be an
adjective.
Method camelCase Method should be main(), print(), println() etc.
named using
camelCasing. Method
names should always
start with a lower case
letter.
Variable camelCase Variables should be num1, name, address
named using
camelCasing. Variable
names should always
start with a lower case
letter.
3 of 8 21/09/2023, 11:52
What are the naming conventions in Java? https://www.educative.io/answers/what-are-the-namin...
Package snake_case Packages should be java, lang, util
(all lower named using
case) snake_casing. Package
names should always
Explore
start with a lower case
letter.
New
Constant snake_case Constant variables MAX_VALUE, MIN_VALUE etc.
CloudLabs (ALL should be named using
UPPER snake_casing. Contant
CASE) variable names should
Personalized
have all upper case
Paths
letters.
Projects
Code example
Skill Paths
Below is a code example demonstrating the usage of Java naming
conventions.
Assessments
package io.educative.example;
public class Employee{
public static final int MAX_AGE=100; //Constant variable naming convention
private String empName; //Variable naming convention
private int age;
public Employee(String name, int age){ //Constructor naming convention
this.empName=name;
this.age=age;
}
public void setName(String name){ //Method naming convention
this.empName = name;
}
public int getAge(){ //Method naming convention
return age;
}
public static void main(String args){ //Main method naming convention
Employee emp1 = new Employee("John Doe", 30);
System.out.println("Employee Name: "+emp1.empName); //Prints Employee Name
System.out.println("Employee Age: "+emp1.getAge()); //Prints Employee Age
}
4 of 8 21/09/2023, 11:52
What are the naming conventions in Java? https://www.educative.io/answers/what-are-the-namin...
Explore
Java code demonstrating naming conventions
New
Explanation
CloudLabs
In the above code example, we follow different naming conventions for
different parts of the code. We use PascalCasing for class and interface
names,
Personalized camelCasing for method and variable names, and snake_casing for
Paths
constant variable names. We also use lower case letters for package names.
Following
Projects
the Java naming conventions makes our code more readable and
consistent. It is not mandatory to follow these conventions, but it is
generally a good idea to do so.
Skill Paths
R E L AT E D TA G S
Assessments
java
CONTRIBUTOR
Tarun Telang
License: Creative Commons-Attribution-ShareAlike 4.0 (CC-BY-SA 4.0)
Related Courses
5 of 8 21/09/2023, 11:52
What are the naming conventions in Java? https://www.educative.io/answers/what-are-the-namin...
Explore
New
CloudLabs
Personalized
Paths
Projects
Skill Paths
Assessments
Keep Exploring
Learn in-demand tech skills in half the time
6 of 8 21/09/2023, 11:52
What are the naming conventions in Java? https://www.educative.io/answers/what-are-the-namin...
PRODUCTS PRICING LEGAL
Learning For Individuals Privacy Policy
Explore
CloudLabs New Free Trial Cookie Policy
New
Onboarding Cookie Settings
Skill Assessments Terms of Service
CloudLabs
Projects Business Terms of
Service
Personalized
Paths Data Processing
Agreement
Projects
CONTRIBUTE RESOURCES ABOUT US
Skill Paths
Become an Author Blog Our Team
Become an Affiliate Sessions Careers Hiring
Assessments
Answers Frequently Asked
Questions
Contact Us
Press
MORE
GitHub Students
Scholarship
Course Catalog
Early Access Courses
Earn Referral Credits
7 of 8 21/09/2023, 11:52
What are the naming conventions in Java? https://www.educative.io/answers/what-are-the-namin...
Copyright ©2023 Educative, Inc. All rights reserved.
Explore
New
CloudLabs
Personalized
Paths
Projects
Skill Paths
Assessments
8 of 8 21/09/2023, 11:52