Programming Rules
Tags: beginners, java, javascript, discuss
Published: 2021-06-13 12:30:39

Hello People, In this short read I'll be writing about some basic programming rules that must be followed while programming in Java, one must know these rules before starting to code in Java. I did some research and haven't found any particular article where I can see all these rules framed together. Also I think most of these programming rules should be followed while programming any language. These rules will help in making your code more readable.

## Let's begin...
![type-fast-gif.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1623586459644/WHQAMnWPI.gif)
### Rule-1
**Always write code from RHS to LHS** this one is little tricky this will be more clear from example.
So suppose you are making reference object of Scanner class.
```Java
Scanner sc = new Scanner(System.in);
```
If you started typing from Scanner sc -> this is LHS to RHS

Now if you start from Right Hand Side, that is starting from new Scanner(); it would be easy for you to decide what will be on the Left Hand Side because that is declaration part.
### Rule-2
**Deleting complete line** if you are a beginner or learning new language than you must follow this, while writing the line of code and there is some typing mistake then instead of correcting that mistake delete the complete line so when next time you will typing same thing then there will be less chances of you committing same mistake.
![back.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1623579651197/WPTv5YO4f.gif)
### Rule-3
**Semicolon** while programming in Java remember all operations in Java end with a semicolon.
```java
System.out.println("Hello World");
```
![semi.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1623582078210/iTRjNexLw.jpeg)
### Rule-4
**Class name declaration** while declaring a class the first letter of the class name must be in uppercase and no numeric value or special symbol should be used. If there are two words in class name then also first letter of each word should be in uppercase.
```java
class Student {
    //class body
}
```
```java
class ProjectManager {
    //class body
}
```
### Rule-5
**Method declaration** there are two styles to follow while declaring a method they are single word style or camel case(camelCase) style.
- camelCase style :- It is a combination of more than 2 words where first letter of first word must be in lowercase and remaining word first letter must be in uppercase. Remember there should be no space between words.
![camal.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1623580435630/52AfMNsab.png)
```java
void showData()
```
- Single word style :- If the method name consists single word then this style should be followed, in this style all the characters will be in lowercase.
```java
void get()
```
### Rule-6
**Variable declaration** while declaring a variable you should ignore using single character, you should either follow single word style or camelCase style.
```java
int percentage;
String studentName;
```
### Rule-7
**Constant declaration** while declaring a constant all characters must be in uppercase and use underscore(_) if there are multiple words.
```java
int MAX = 20; // value is not fixed
int MAX_AGE = 20; // value is not fixed
final int MAX_AGE = 20; // value is fixed
```
### Rule-8
**Package specification** while specifying a package then all the characters must be in lowercase except the first letter of the class specified by package. To read more about packages check my ***[last article](https://dev.to/ritvikdubey27/you-must-know-this-about-java-ii-1k21)***.
```java
import java.util.Date;
```
### Rule-9
**Access level declaration** while declaring access levels all the characters of the access levels should be in lowercase.
```java
private void get()
```
### Rule-10
**Object & reference object creation** 
```java
new Student();
```
This is an object in Java.

Object creation follows these steps:-
- Instantiation:- The new keyword is a Java operator that creates the object.
- Initialization:- The new operator is followed by a call to a constructor, which initializes the new object.
```java
Student st = new Student();
```
Here **st** is the reference object in Java.

It includes:-
- Declaration: A variable name with an object type. This variable is called reference object. 

**In Java we can access method outside class in 3 ways:-**
```java
class Student {
   void get() {

   }
   void show() {

   }
}
```
- Way-1 :- 
```java
new Student().get();
new Student().show();
```
- Way-2 :- 
```java
Student st = new Student();
st.get();
st.show();
```
- Way-3 :- 
```java
Student.get(); // if method is static
Student.show(); // if method is static
```
### Okay so that's enough for now follow my this journey to learn more about Java.
#### *Thank you for reading.*
#### *Please share your thoughts about it and correct me if I'm wrong.*
#### *I hope you liked it and found it helpful.*
#### ***Cover:- [Rajat Gour](https://twitter.com/rajatgour20)***
#### *Connect with me on [Twitter](https://twitter.com/ritvikdubey27?s=09) or [LinkedIn](https://www.linkedin.com/in/ritvik-dubey-3bbb22169)*
#### *My personal blog [blog.ritvikdubey.com](https://blog.ritvikdubey.com/)*