Friday 19 August 2016

Tips on bug free coding  

Everybody have error and bugs in there code even the most hardcore coder can make silliest of errors .This does not means that he is not a good programmer it's just sometimes you not pay as much attention in the code rather you pay attention to the algorithm. These are some tips which can prevent you from making silly errors in your program . It applies to all the languages .
 1.Identation - Identation means giving  spaces between the margin and the lines . Given below is a example of identation
 public class 102java 
  {
      public static void main(String args[])
       {
           for(int i = 0 ;  i < 5 ; i++)
                {
                  System.out.println("102java");
           
                }
       }
  }
Like in the above code I have given spaces so that I can read which method is inside which class . This looks professional and quite systematic it will make easy for others to read your code . So identation is very important .
2. Writing Comment- commenting in between lines tells any other person reading your program that what is the program about . It is good if you make a habit of commenting. When you commit changes in someone  else program you should comment what changes you've made. Let's modify the above program to see how and where should we comment 
public class 102java 
{
   public static void main(String args[])
    {
       for(int i = 0 ; i<5;i++)
             {
                System.out.println("102java"); // printing 102java 5 times
             }
    }
}
3. Close the brace when you open it - This point is quite self explanatory . Close the brace immediately after opening it and then write the code between it. This will prevent the brace error which I had mentioned in my last post .
4. Java is case sensitive - Beware many people do these case sensitive mistakes and then are unable to find it . There is a simple trick I use which mostly prevents this mistake to happen . There are some set of rules which are defined of how are methods classes written in standard Java libraries .
  1. All classes start with capital letters 
  2. In the case of methods the first letter of first word is small and afterwards it is small for example getMoreData,setName.
  3. Don't make variable name capitals try to keep it all small as you may have to use it again and again which can cause error.
 4. You should make constants all capitals           and declare them on the top.

  5. Algorithm - You should first make an   algorithm of the program before writing the code as then you will know how the code will work and will prevent some logical errors . I will be telling you how to make algorithms in my future post .

Finally if you follow the above steps you will definitely be able to create a zero-bug program . Never mind if there are bugs as
no one is perfect .

reached end of  file while parsing

 This error is very common.It is shown because you have missed a brace either in the end or last like the code block given below

 public class 102java 
   {
        public static void main(String  args[])
           {
             System.out.println("102java");
   }
Thus will give error on compilation as there is a brace missing 

Mainclassnotfound

I will be posting common  Java problems
Which people make usually .

Welcome guys this is my first post I am rohan I have gatheredy expertise in Java

Main class not found 

you may have got this error when you are running your program You get the error 
Main class not found this is mainly due to you are doing let the class be test.Java
Then :-
Javac test.java
Java test
you may be adding .Java in the end line 2 
which is wrong because after compiling the test.Java file is converted into test.class therefore when you attempt to run your Java file do not use .Java extension instead use .class extension else you will see the
Main class not found error .
Pls comment and share if you found this useful and comment eny error so I can share the solution with all persons