You are on page 1of 6

UNIT 4

PHP

1.What is Server-side programming?


Server-side scripting is a web server technology in which a user's request is
fulfilled by running a script directly on the web server to generate dynamic web pages. It is
usually used to provide interactive web sites that interface to databases or other data stores.
The primary advantage to server-side scripting is the ability to customize the response based
on the user's requirements, access rights, or queries into data stores.

2.What is session tracking? How it is implemented in Java Servlet?


A session is a group of activities that a user performs while accessing a particular
website. The process of keeping track of settings across the sessions is known as session
tracking.

Session tracking is implemented in servlet by using an HTTPSession interface


that keeps track of the sessions in the current servlet context.

Every user who logs on to a web site automaticaaly associates with an HTTP
session object. The servlet can use this object to store information about the user’s session.

3.Define cookies. //NOV/DEC 2011


Cookies are pieces of state information that a web server sends to clients to keep
track of client information. The server creates them and sends them to the client with HTTP
response headers as text strings.

4.Open source software?

Open source software refers to applications developed in which the user can access and
alter the "source" code itself. Some open source applications have restrictions on their
use and distribution, but many do not. Unlike public domain software, Open source
software does have copyrights.Examples of open source software include: LINUX,
Apache, Firefox, KOffice, Thunderbird, OpenOffice, KOffice, and SquirrelMail.

5. What are the disadvantages of open source code/software?

Open source code can be technically reliable, it also reduces the overhead costs of
production. Some of the disadvantages lie in the simple fact that open source software is not as
strenuously tested as other types of software. This can lead to problems later on like unusable
programs, and proliferation of malicious code in the form of viruses. While open source software is for
the most part safe to use, there are some programs out there that aren't.
6. What are benefits of open source software?

Open source software is free and allows you to take and add components to the software.
It can be freely used or edited by anyone.

7. What is Open Source Software?


Open source software allows for the coding of the software to be shared, viewed and
modified by others. It is freely available to the public, and is a great way for software to be

8. "Hello World" Script in PHP:

<html>
<head>
<title>Hello World</title>
<body>
<?php echo "Hello, World!";?>
</body>
</html>

9.PHP Variable Types



All variables in PHP are denoted with a leading dollar sign ($).
The value of a variable is the value of its most recent assignment.
Variables are assigned with the = operator, with the variable on the left-hand side and the
expression to be evaluated on the right.
Variables can, but do not need, to be declared before assignment.
Variables in PHP do not have intrinsic types - a variable does not know in advance whether it
will be used to store a number or a string of characters.
Variables used before they are assigned have default values.
PHP does a good job of automatically converting types from one to another when necessary.
PHP variables are Perl-like.

PHP has a total of eight data types which we use to construct our variables:
Integers: are whole numbers, without a decimal point, like 4195.

10. PHP Decision Making


The if, elseif ...else and switch statements are used to take decision based on the different
condition.
You can use conditional statements in your code to make your decisions. PHP supports
following threedecision making statements:
if...else statement - use this statement if you want to execute a set of code when a condition is
true and another if the condition is not true
elseif statement - is used with the if...else statement to execute a set of code if one of several
condition are true
switch statement - is used if you want to select one of many blocks of code to be executed,
use the Switch statement. The switch statement is used to avoid long blocks of if..elseif..else
code.

11. What are the different session tracking methods?

Cookies:
You can use HTTP cookies to store information. Cookies will be
stored at browser side.

URL rewriting:
With this method, the information is carried through url as
request parameters. In general added parameter will be sessionid,
userid.

HttpSession:
Using HttpSession, we can store information at server side. Http
Session provides methods to handle session related information.

Hidden form fields:


By using hidden form fields we can insert information in the webpages
and these information will be sent to the server. These fields are not
visible directly to the user, but can be viewed using view source
option from the browsers. The hidden form fields are as given below:

<input type='hidden' name='siteName' value='java2novice'/>

12. What is the purpose of garbage collection?

The garbage collection process is to identify the objects which are


no longer referenced or needed by a program so that their resources can be
reclaimed and reused. These identified objects will be discarded

13. What are the types of ResultSet?

The type of a ResultSet object determines the level of its functionality in


two areas: the ways in which the cursor can be manipulated, and how concurrent
changes made to the underlying data source are reflected by the ResultSet object.
The sensitivity of a ResultSet object is determined by one of three different
ResultSet types:

TYPE_FORWARD_ONLY:
The result set cannot be scrolled; its cursor moves forward only, from
before the first row to after the last row. The rows contained in the
result set depend on how the underlying database generates the results.
That is, it contains the rows that satisfy the query at either the time
the query is executed or as the rows are retrieved.

TYPE_SCROLL_INSENSITIVE:
The result can be scrolled; its cursor can move both forward and backward
relative to the current position, and it can move to an absolute position.
The result set is insensitive to changes made to the underlying data source
while it is open. It contains the rows that satisfy the query at either the
time the query is executed or as the rows are retrieved.

TYPE_SCROLL_SENSITIVE:
The result can be scrolled; its cursor can move both forward and backward
relative to the current position, and it can move to an absolute position.
The result set reflects changes made to the underlying data source while
the result set remains open.

The default ResultSet type is TYPE_FORWARD_ONLY.

14. What is difference between wait and sleep methods in java?

sleep():
It is a static method on Thread class. It makes the current thread into the
"Not Runnable" state for specified amount of time. During this time, the thread
keeps the lock (monitors) it has acquired.

wait():
It is a method on Object class. It makes the current thread into the "Not Runnable"
state. Wait is called on a object, not a thread. Before calling wait() method, the
object should be synchronized, means the object should be inside synchronized block.
The call to wait() releases the acquired lock.

15. What is servlet context?

The servlet context is an interface which helps to communicate with


other servlets. It contains information about the Web application and container. It is kind of
application environment. Using the context, a servlet can obtain URL references to resources,
and store attributes that other servlets in the context can use.

16. What happens if one of the members in a class does not implement Serializable interface?

When you try to serialize an object which implements Serializable interface, incase if the
object includes a reference of an non serializable object then NotSerializableException will be
thrown.
17. What is race condition?

A race condition is a situation in which two or more threads or processes are reading or
writing some shared data, and the final result depends on the timing of how the threads are
scheduled. Race conditions can lead to unpredictable results and subtle program bugs. A thread
can prevent this from happening by locking an object. When an object is locked by one thread
and another thread tries to call a synchronized method on the same object, the second thread will
block until the object is unlocked.

18 How can you convert Map to List?

We know that Map contains key-value pairs, whereas a list contains only objects. Since
Entry class contains both key-value pair, Entry class will helps us to convert from Map
(HashMap) to List (ArrayList). By using Map.entrySet() you will get Set object, which intern
you can use it to convert to list object.
public static void main(String a[]){
Map<String, String> wordMap = new HashMap<String, String>();
Set<Entry<String, String>> set = wordMap.entrySet();
List<Entry<String, String>> list = new ArrayList<Entry<String,
String>>(set);
}

19. What is System.out in Java?

Here out is an instance of PrintStream. It is a static member variable in System class. This
is called standard output stream, connected to console.

20. What is difference between ServletOuptputStream and PrintWriter?

ServletOutputStream: ServletResponse.getOutputStream() returns a ServletOutputStream


suitable for writing binary data in the response. The servlet
container does not encode the binary data, it sends the raw data
as it is.

PrintWriter: ServletResponse.getWriter() returns PrintWriter object which sends


character text to the client. The PrintWriter uses the character
encoding returned by getCharacterEncoding(). If the response's
character encoding has not been specified then it does default
character encoding.
16 MARKS:

1. List and explain some Web applications


2. Explain in detail about cookies and cookies Technology
3. Explain in detail about session tracking
4. Expalin about open source environment
5. List and Explain some Open source Software in detail
6. Illustrate about PHP in detail.

You might also like