Page 314 - CA_Blue( J )_Class9
P. 314

MOST COMMON MISTAKES IN

                              PROGRAMMING





                      1.  Accessing non-static members from static methods: It is a very common mistake to try and access a
                         non-static member from a static method and it happens very often in the main() method.

                         Solution:  While creating a method always be mindful of the purpose and scope of the method. Always
                         remember that we can access an instance variable by an object of its class only and static methods can
                         only access static members of the class.

                      2.  Missing closing curly braces: Beginner programmers often forget to close the braces. It issues a syntax
                         error.
                         Solution: The easiest solution to this problem is to insert both the opening and the closing brace at the
                         same time and writing the code within these braces.

                      3.  Missing break in switch case construct: This is a major problem and can cause major trouble. This
                         error often escapes the programmer’s eyes because it never causes a compiler error.
                         Solution:  To avoid this error, perform a dry run in your mind while coding each case. This will help you
                         to get a solid grasp of the output and the working of the programming construct.

                      4.  Confusing assignment with comparison (= and ==): This can cause a compiler error and issue logical
                         and runtime errors based on the program.
                         Solution: Note that ‘=’ is an assignment operator and ‘==’ is a relational operator and they are different
                         from each other. Hence, the best way to avoid this issue is to get a clear grasp of the programming
                         concept and the difference between these operators. This will always keep you on the lookout for
                         these kinds of errors and help you avoid them.

                      5.  Using less restrictive access modifiers: This error can affect the working of a program and cause
                         serious accessibility problems.

                         Solution: Access specifiers are important to a program and a key concept in java programming. To
                         avoid these issues, you must be mindful of the usage of the access specifiers in your program and
                         retain a solid grasp of the concept.
                      6.  Forgetting to free up resources: This is an aspect that almost all the beginners tend to miss. Though it
                         is easy to miss, it can lead to extensive memory and resource usage.

                         Solution: This is a concept that programmers learn with time. But, you can pick up on it quickly if you
                         are mindful of the amount of resources you are using and freeing it up while finishing the program.
                      7.  Logic Errors: These are vital errors that can be very hard to spot. These errors affect the working of a
                         program and its outcome.
                         Solution: To avoid such errors, always check the working of your program and determine if there is a
                         flaw in the idea you had for the program.







                   312    Touchpad Computer Applications-IX
   309   310   311   312   313   314   315   316   317   318   319