According to standard Java naming conventions, you make your code easier to read for yourself and for other programmers. There are following points should be follow by each developers.
Popular Tutorials
There are following points of best practices in programming to decide name of Variables, Methods, Classes and Packages.
Meaningless Names of Variables should be avoid like name as xyz, a, aa, bbb, i, iii, temp etc. Meaningless names doesn’t reveal intent, they simply reduce readability. You should never use pointless or meaningless name even you are making Hello Java project because it makes your habit. In a real project it would never acceptable by code reviewer because hello world programs are not maintained but a real project is maintained for years.
This point is counterpart of first point. According to best practice of naming conventions inn java you should always use meaningful name instead of pointless names. For example variable name index is much better than like i,ii,j etc and method name with getJoinDate() is also much better than getJD(), jDate(), jdt() because method name getJoinDate() understandable name in future for any other developers in somewhere in my code.
Shorter name is always preferable over longer name if it reveal intent clearly. For example between getJoinDate() and getEmpSalary() both are able to reveal purpose, shorter ones are easy to read and write, but don’t forget to follow Java bean naming convention e.g. if variable name is joinDate then getter method name must be getJoinDate().
This point is counterpart of above point. In programming intent revealing is also important point to decide name of variables, methods etc. For example getJoinDate() is fine but getESal() is not as good as getEmployeeSalary() or getEmpSalary(). So prefer shorter name if and only if it reveal intent completely, otherwise choose longer and descriptive name.
Never use similar names like employee and employees, both variable have every same character except last one. This kind of variable names might be reason of very hard to spot and subtle bugs and also these names are even harder to find during code reviews. For single employee use employee or emp and for list employees always use like listOfEmp or listOfEmployees over employees.
According to best practice of programming, you should always use consistent naming convention in a project. Suppose for a project you are using close(), finish(), kill() etc. for releasing the resources, these names are not in consistent so we always consist with one name of them for resource release. This will make your API more usable, as programmer will be able to predict and search more easily.
Class name should be noun, Interface name should describe ability and method names should start with verb. For example class names should be Employee, Student, Manager, Method names should start with verb e.g. get, set, do, invoke etc and Interface name should Cloneable can clone, Runnable can run, Callable can be called etc. And package name should follow standard company structure e.g. com.company.project.module.
Classical Programming Convention for loop
for(int i=0; i<10; i++){
// your code
}
In such case we can pointless name for for, while loop as above.
Avoid name like _, d_, s_
Avoid using non ASCII characters
Never use characters from local languages like Hindi, German etc. English is a universal language for programming and stick with it.
Boolean Variable and Method Names
For Boolean varable always use name like isActive, isDeleted etc. Methods name should be like isAlive(), hasNext(), canExecute() adds lot of value.
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…