Good programming techniques in Java

Java has achieve such a large fan base and extraordinary popularity  because the language expand on a large basis and it is  easy and efficient approach to perform various programming tasks and aid the developers.By using these technique we can avoid error in Java program

 

1. Every program should start with a comment by describing the purpose of the program .

//Comments here( Text in this line only is considered as comment )

2. Use blank lines, space characters and tab characters in a program to improve program read capability.

3. You should always begins a class name with a capital letter.

class ClassName {
   // variables
   // methods
}

4. Normally in  java program when you read you examine  the identifiers start with the capital letter.

public class Test
{
	public static void main(String[] args)
	{
		int x = 100;
	}
}

5. To avoid the mistake between the braces whenever you type opening left brace,  { , in your program immediately type the closing right  brace,  }, then rearrange the cursor  between the brace to start typing the body.

public class Test
{
	

}

6. Make a space of the entire body of each class definition  one "level"  of division between left brace, { , and the right brace, }, that define the body of the class. This indicate the structure of the definition and helps make the class defintion easier to read.

public class Test
{
//body of class start
	public static void main(String[] args)
	{
		int x = 100;
	}
}

7. Set a practice to  make a space but tab stops may vary between editors .we recommend using either 1/4 inch tab stops or three space to form  level of  make a space.

8. Make a space of the complete body of each method definition one "level" of division between the left brace,{ , and the right brace,},  that define the body of the method . This make  the structure of the method  stand out and helps makes the method definition easier to  read.

// Proper program structure in java including proper format of left and right braces { } 

public class Hello
{   
   
    public static void main(String[] args)
    {
        System.out.println("Hello Java");  
    }
}

9. Some programmer choose to follow the closing right brace(}) of the body of a  procedure or class defintion with a single- line comment signify  that the method or class defintion for which the right brace abolish the description of the body.

10. Give  a space after each comma in an argument list (,) to make program more readable.

public class Hello
{   
   
    public static void main(String[] args)
    {
// space after comma in an argument list
        System.out.println("Hello Java");  
    }
}

11. Give a meaningful  variable name in your program it helps to self- documenting.

public class StudentDetails 
{ 
    public void StudentAge()  
    {   //local variable age 
        int age = 3; 
        age = age + 7; 
    } 
 }

12. In Java the variable name identifiers start with a lowercase first letter . As with class name every word in the name after the first word should begin with a capital first letter 

public class Test
{
	public static void main(String[] args)
	{
		int testScore = 20;
	}
}

13. Some of the programmers choose to declare each variable on a separate line . This format allows for easily  insert the  expressive comment next to each declaration.

14. Give  a space on either side of a binary operator. This makes the operator distinct and make the program more readable and clear.

15. Use the paranthese ( ) for more complicated arithmetics expression even when the parantheses  are not essential can make the arithemetic expression easier to read.

class Example{

 //Use of Parenthesis ( ) to make the  expression easier to read

 public static void main(String[] arguments) {
  System.out.println("This is just a example.");
 }

}

16.  Make the space for  the statement in the body of an If structure to make the body of the structure distinct and to improve the program readability.

17. Place only one statement per line in a program .This improve program readability.

18. A length statement may be extend over certain lines . If a single statement must be break across a lines, choose breaking points that make sense such as after a common in a comma-separate list, or after an operator in a long and extended expression .If a statement is split across two or more lines, make a space for all subsequent lines.

 

 

 

 

Keywords: