Informatics Notes (Class 11)

CBSE Class 11 Informatics Practices Chapter 7 Programming Guidelines

Written by cbselearners

Programming Guidelines

Programming Guidelines

Programming Guidelines


GUI Application Development Guidelines

GUI Programming adopts a simplified approach to programming. In GUI Programming, most of the components are predefined in a generic way to be adapted and incorporated according to the needs of the application.

Some guidelines for good GUI Programming are:

  1. Understand the need for the application before starting the development.
  2. Find out all possible inputs, which are required to produce the desired result/output.
  3. Avoid ambiguity and use appropriate input component.
  4. Provide appropriate labels for each input and output options.
  5. Use meaningful names for variable, controls etc. and follow naming conventions.
  6. Ensure clarity of expression so the user can easily understand it.
  7. Use comments and proper indentation.
  8. Insert blank lines and blank spaces where necessary to separate logical group of statements.
  9. Avoid using free formatting style.

Characteristic of a Good Program

  1. Effective and efficient
  2. User-friendly
  3. Self-documenting code
  4. Reliable
  5. Portable

Stages of Program Development Process

Program/application development is a step by step process. The effective and efficient software is developed only through a systematic approach.


Stages of the Application Development

Phase 1: Analysis: This phase contains the following steps:

  • Problem Specification: To understand the problem and set the objective.
  • Requirement Analysis: To find the technical, financial, and operational requirement for the new application.
  • Possible Input and Output for obtaining desired results.

Phase 2: Designing: In this phase, the detailed design of the following components is to be made:

  • Input Design
  • Output Design
  • Interface Designing (Forms)
  • Modular Components
  • Algorithms

Phase 3: Coding
Phase 4: Testing and Debugging:
Phase 5: Implementation
Phase 6: Documentation and Maintenance


Types of Errors

Compile Time Error- Occurs during compile time. When a program compiles it sources code is checked for rules of programming language. Its types are:-

  1. Syntax error: it occurs when a grammatical rule of Java is violated
  2. Semantic error: it occurs when a statement is not meaningful.
  3. Run Time Error: Occurs during the execution of the program.
  4. Logical Error: Occurs due to the wrong logic of a program.


Important Questions

Q. Excessive comments add time to the execution of your program. (True/False). Justify your answer.

Ans. No, Comments don’t add time to program execution. As comments are only for documentation purpose. They are nonexecutable statements.

Q. Differentiate between compile time and runtime errors.

Ans: a. Compile time errors occur due to the violation of grammatical rules of a programming language. Runtime errors occur during execution of the program.

Compile time errors are easy to correct as we get error message corresponding to that which give an idea to correct it. Runtime errors cause abnormal termination of the program.

Example of compile-time error: the Missing semicolon(;). Example of runtime error: Divide by zero error, Logarithm of a negative number.

Q. Which error is harder to locate and why?
Ans: Logical errors are harder to locate. Logical errors occur due to the error in the logic of a program. When a program is syntactically correct, even running properly but not giving the desired output, it means that it has a logical error.

One common example of the logical error is when we write a statement
(Eng+Math+Sci/3) instead of (Eng+Math+Sci)/3 to calculate the average of marks of 3 subjects.

Q. Explain the term ‘Exception Handling’.
Ans. A runtime error is called an exception, which causes abnormal termination of the program. To handle such type of errors/exception is called Exception handling.

In java exception handling is done by try{ } and catch { } block. Statements that can raise exception are put in try{ } block and its handling code is written in catch { } block.

Q. Define Syntax :
Ans. Syntax: the Formal set of rules defined for writing any statement in a language is known as syntax. Example- Every line in JAVA should be terminated by the semicolon(;).

Q. Define Portability.
Ans. Portability -Portability means an application should run on the different platform without doing any changes.

Q. Prettyprinting
Ans. Prettyprinting is the formatting of a program to make it more readable. These formatting conventions usually consist of changes in positioning, spacing, color, contrast, size and similar modifications intended to make the content easier to view, read and understand.

Q. The code given below will give an error on execution if the value entered in t2 is 0. Identify the type of the error and modify the code to handle such an error.
int a,b,c;
a= Intger.parseInt(t1.getText());
b= Intger.parseInt(t2.getText());
c= a / b;
Ans: The error is logical error. int a,b,c;
a= Intger.parseInt(t1.getText());
b= Intger.parseInt(t2.getText()); if(b!=0)
c= a / b;
else {
JOptionPane.showMessageDialog(null,”Denominator cann’t be zero”);
t2. setText(“ “);
t2.requestFocus( ) ;

Q. What are the characteristics of a good program?
Ans. The characteristics of a good program are:
The program should be efficient in terms of execution speed and effective memory utilization.
The code should be accurate. It should produce the correct result.
The program should user-friendly. It means meaningful names should be given to the variable, proper messages should be given, use of comments and indentation.
The program must be reliable that is it should be able to handle the situation when the wrong inputs are given.
The program should be portable so that it can run on different platforms without doing any changes.

Q. What is the use of comments and indentation?
Ans. Comments are nonexecutable statements and are used for internal documentation purpose. In Java comments are given either by // or /* ….*/ brackets.
/* This method calculates the sum of two numbers.*/
int Sum( int x, int y) // x,y are formal parameters
return (x+y);
Indentation makes a program readable and understandable. When you are writing a program you must remember that the opening braces should properly match with a closing brace. Spaces should be inserted between the operator and operands in an expression.

About the author


Leave a Comment