What is the difference between Procedural Programming and OOP Programming ?

In Procedural Programming we use a list of instructions to tell the computer what to do and here we divide the program into small parts called functions. In PP, If you want a computer to do something, you should provide step-by-step instructions on how to do it and it follows top down apporach. It means Procedural Programming takes on applications by solving problems from the top of the code down to the bottom. The main issue in PP is that if a developer wants to edit a code he must edit every line of code that corresponds to the original change in the code.

Object-oriented Programming is a programming language that uses classes and objects to create models based on the real world environment. An object is a component of a program that knows how to perform certain actions and how to interact with other elements of the program and objects are the basic units in OOP. In OOP It is easy to edit and maintain the code. Also other developers can understand the program after development.

A method in OOP is like a procedure in PP and method is part of an object.In object-oriented programming, you organize your code by creating objects, and then you can give those objects properties and you can make them do certain things.

  • Object-oriented Programming uses methods and Procedural Programming uses procedures.
  • Object-oriented Programming uses objects where Procedural Programming uses records.
  • Object-oriented Programming uses classes where Procedural Programming uses modules
  • Object-oriented Programming uses messages where Procedural Programming uses procedure calls.
  • In PP, Most function uses Global data for sharing that can be accessed freely from function to function in the system and In OOP, data can not move easily from function to function,it can be kept public or private so we can control the access of data.
  • PP does not have any proper way for hiding data so it is less secure and OOP provides Data Hiding so provides more security.
  • PP follows Top Down approach and OOP follows Bottom Up approach.
  • In POP, Overloading is not possible and In OOP, overloading is possible in the form of Function Overloading and Operator Overloading.

I saw a simple example about PP & OOP when I searched  🙂

A simple way to compare both programming methods is to think of Object-oriented Programming as  learn to read picture book. As children see pictures of simple objects like a house or picture they know that throughout the book when they see a picture of the house it represents the word house. The children can then read through the book as words are substituted throughout the story with pictures.

In Object-oriented Programming the classes could represent the pictures in the learn to read books. A house could represent a class and anything the developer wants to have included to describe that house like the color, size, number of bathrooms etc.

In Procedural Programming the learn to read book would be words on the page without pictures to help guide the young learner through the book. If the story was changed in the beginning of the book it could disrupt or make the story later on in the book not make any sense. Although learning to read the book would make programming with Procedural Programming simple, it would make it difficult for other readers in the case of the book or programmers in the case of Procedural Programming to add to the story.



What is a servlet ?

  • Servlet is a technology that is used to create web application.
  • Servlet is an API that provides many interfaces and classes including documentations.
  • Java Servlets are programs that run on a web server and used for developing web applications.
    we can understand about servlet by this example. Let’s consider where we need to log on to a web site to access our e-mail account. We have to submit username and password for authentication. Then web site accept the login information and validates it using server side programs. (like servlets)
client -> server -> response -> client


  1. request
  2. response is generated at runtime.
  3. response is sent to the client.


OK let’s see what is JSP(java servlet pages)

Java Server Pages (JSP) is a technology for developing web pages that support dynamic content which helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>

Simply we can understand it by this…..


This is a simple jsp program. We save this as  filename.jsp
JSP is used for creating dynamic webpages. Dynamic webpages can have two types of contents – static & dynamic content. The static contents can have text-based formats such as HTML,  XML etc. and the dynamic contents are generated by JSP elements.

I know u have no clear idea about jsp yet 🙂 ok first let’s look about
jsp processing.

  • your browser sends an HTTP request to the web server.
  • The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine.
  • The JSP engine loads the JSP page from disk and converts it into a servlet content.(all template text is converted to println( ) statements and all JSP elements are converted to Java code that implements the corresponding dynamic behavior of the page.)
  • The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet engine.
  • The servlet engine loads the Servlet class and executes it. During execution, the servlet produces an output in HTML format, which the servlet engine passes to the web server inside an HTTP response.
  • The web server forwards the HTTP response to your browser in terms of static HTML content.
  • Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if it were a static page.


OK now we know some facts about jsp servlet. (actually nothing 😀 ) next part we will know something more………………..


  1. What are the correct statements about Cookies in PHP ?

a)A cookie is often used to identify a user.
b)A cookie is a small file that the server embeds on the user’s computer.
c)Each time the same computer requests a page with a browser, it
will send the cookie too.
d)With PHP, you can both create and retrieve cookie values.

2.  A cookie is created with the ____________ function.


3.  setcookie(name, value, expire, path, domain, secure, httponly);

Only the name parameter is required. All other parameters are optional.
Is this statement correct?


4. What are the correct statements ?

a) The setcookie() function must appear BEFORE the <html> tag.
b) The value of the cookie is automatically URLencoded when sending the          cookie, and automatically decoded when received
c) If want To modify a cookie, just set the cookie using the
setcookie() function.
d) To delete a cookie, use the setcookie() function with an expiration date in      the past.

5. The………………….function returns a string with backslashes in

front of the specified characters. 

a) Addcslashes()
b) addcslashes()
c) add_slash()
d) add_backslash()

6. Select the correct statement(s)

a) addcslashes() function returns a string with backslashes in front of the       specified characters.
b) addcslashes() function is not case sensitive.
$str = addcslashes(“Hello World!”,”W”);
output of this code is     Hello \World!

d) It returns the escaped string.

7. What are the correct statements about superglobals?

a) “superglobals” are always accessible, regardless of scope and we can
access them from any function, class or file without doing anything
b) $_SESSION , $_COOKIE, $_ENV, $_FILES are the superglobal variables.
c) $GLOBALS is a PHP super global variable which is used to access global
variables from anywhere in the PHP script.
d) $_POST is not a superglobal veriable. It is used to collect form data after
submitting an HTML form with method=”post”.

8. Which of the following among A,B and C can be used to include comments in PHP?

A:   /* */
B: #
C: //

a) A and B only     b) A and C only    c) B and C only   d) All A,B and C

9. What is/are the correct statement(s)? about variables.

a) A variable name cannot start with a number.
b) A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ ).
c) Variable names are case-sensitive ($age and $AGE are two different
d) A variable name must start with a letter or the underscore character.
e) A variable starts with the $ sign, followed by the name of the variable.


10. PHP is __________ scripting language.

a) sever-side
b) client-side
c) Middle-side
d) out-side  🙂

11. PHP scripts are executed on _________.

a) Client compuer
b) Server computer
c) Depends on PHP code
d) None

12. Which of the following delimiting method is known as

a) delimitted by single quotes.
b) delimitted by <<< identifier.
c) delimitted by single quotes.
d) All of above.

13. In PHP, which datatypes are treaded as arrays.

a) string
b) integer
c) float
d) booleans

14. What is the output of fllowing script would be.

function ad it () {
GLOBAL $var;
$var++ ;
echo “value is $var”;
addit ();

a) value is 15
b) value is $var
c) value is 1
d) value is 16

16. Variable scope on which a variable does not loose its value when the
       function exists and use that value if the function is called again is.

a) local
b) static
c) function parameter
d) none of above

17. The left association operator % is used in PHP for

a) percentage
b) division
c) bitwise AND
d) modulus

18. Which of the following functions require the allow-url-fopen must

a) include()
b) require()
c) both (a) and (b)
d) None

19. On failure of which statement the script execution stops displaying
       error/warning message?

a) include()
b) require()
c) both (a) and (b)
d) None of above

20. Trace the false statement

a)  Any code found within an included file will inherit the variable scope of
the location of its caller

b)  Because the included code will be embedded in a PHP execution block,
the PHP execution block, the PHP escape tags (<?php?>  aren’t
required on the file to be included.

c)  For the inclusion of remote files the allow-url-pope must be enabled ad
URL wrapper must be supported

d)  Including a file produces the same result as copying the data from the
file specified into the location in which thestatement appears.

21. correct statements?

a) str_replace() function replaces some characters with some other
characters in a string.
b) str_replace() function is case-sensitive.
c) str_ireplace() function use to perform a case-insensitive search.
d) syntax of this function is str_replace(find,replace,string,count). (count is
a variable that counts the number of replacements)




1.Answer; All(a,b,c,d).
2.Answer; a.
3.Answer; a.
4.Answer; All.
5.Answer; b.
6.Answer; a,c,d
7.Answer; a,b,c
8.Answer; d.
9.Answer; a,b,c,d,e.
10.Answer; a.
11.Answer; b.
12.Answer; b.
13.Answer; a.
14.Answer; d.
16.Answer; b.
17.Answer; d.
18. Answer; c.
19. Answer; b.
20. Answer; b.
21. Answer; a,b,c,d.