Sunteți pe pagina 1din 65

CS8651 – INTERNET PROGRAMMING – PART A

2 MARKS WITH ANSWERS

UNIT I – JAVA PROGRAMMING


1) What is meant by Object Oriented Programming?
OOP is a method of programming in which programs are organised as cooperative
collections of objects. Each object is an instance of a class and each class belong to a hierarchy.

2) What is a Class?
Class is a template for a set of objects that share a common structure and a common
behaviour.

3) What is an Object?
Object is an instance of a class. It has state,behaviour and identity. It is also called as an
instance of a class.

4) What is an Instance?
An instance has state, behaviour and identity. The structure and behaviour of
similar classes are defined in their common class. An instance is also called as an object.

5) What are the core OOP’s concepts?


Abstraction, Encapsulation, Inheritance and Polymorphism are the core OOP’s concepts.

6) What is meant by abstraction?


Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the
perspective of the viewer. Its the process of focussing on the essential characteristics of an
object. Abstraction is one of the fundamental elements of the object model.

7) What is meant by Encapsulation?


Encapsulation is the process of compartmentalising the elements of an abtraction that
defines the structure and behaviour. Encapsulation helps to separate the contractual interface of
an abstraction and implementation.

8) What are Encapsulation, Inheritance and Polymorphism?


Encapsulation is the mechanism that binds together code and data it manipulates and
keeps both safe from outside interference and misuse. Inheritance is the process by which one
object acquires the properties of another object. Polymorphism is the feature that allows one
interface to be used for general class actions.

9) What are methods and how are they defined?


 Methods are functions that operate on instances of classes in which they are defined.
Objects can communicate with each other using methods and can call methods in other
classes. Method definition has four parts.
 They are name of the method, type of object or primitive type the method returns, a list of
parameters and the body of the method. A method’s signature is a combination of the first

Prepared by L.Maria Michael Visuwasam Page 1


CS8651 – INTERNET PROGRAMMING – PART A

three parts mentioned above.

10) What are different types of access modifiers (Access specifiers)?


Access specifiers are keywords that determine the type of access to the member of a
class. These keywords are for allowing privileges to parts of a program such as functions and
variables. These are:

 public:Any thing declared as public can be accessed from anywhere.


 private:Any thing declared as private can’t be seen outside of its class.
 protected :Any thing declared as protected can be accessed by classes inthe
same package and subclasses in the other packages.
 default modifier :Can be accessed only to classes in thesame package.

11) What is an Object and how do you allocate memory to it?


Object is an instance of a class and it is a software unit that combines a structured set of
data with a set of operations for inspecting and manipulating that data. When an object is
created using new operator, memory is allocated to it.

12) Explain the usage of Java packages.

This is a way to organize files when a project consists of multiple modules. It also
helps resolve naming conflicts when different packages have classes with the same names.
Packages access level also allows you to protect data from being used by the non-authorized
classes.

13) What is method overloading and method overriding?


 Method overloading: When a method in a class having the same method name
with different arguments is said to be method overloading.
 Method overriding : When a method in a class having the same method name
with same arguments is said to be method overriding.

14) What gives java it’s “write once and run anywhere” nature?
All Java programs are compiled into class files that contain bytecodes. These byte
codes can be run in any platform and hence java is said to be platform independent.

15) What is a constructor? What is a destructor?


Constructor is an operation that creates an object and/or initialises its state. Destructor
is an operation that frees the state of an object and/or destroys the object itself. In Java, there is
no concept of destructors. Its taken care by the JVM.

16) What is the difference between constructor and method?


Constructor will be automatically invoked when an object is created whereas method

Prepared by L.Maria Michael Visuwasam Page 2


CS8651 – INTERNET PROGRAMMING – PART A

has to be called explicitly

17) What is Static member classes?

A static member class is a static member of a class. Like any other static method, a static
member class has access to all static methods of the parent, or top-level, class.

18) What is Garbage Collection and how to call it explicitly?


When an object is no longer referred to by any variable, java automatically reclaims
memory used by that object. This is known as garbage collection. System.gc() method may be
used to call it explicitly

19) In Java, How to make an object completely encapsulated?


All the instance variables should be declared as private and public getter and setter
methods should be provided for accessing the instance variables.

20) What is static variable and static method?


 static variable is a class variable which value remains constant for the entire class
 static method is the one which can be called with the class itself and can hold only the
static variables

21) What is a package?


A package is a collection of classes and interfaces that provides a high-level layer of
access protection and name space management.

22) What is the difference between this() and super()?


this() can be used to invoke a constructor of the same class whereas super() can
be used to invoke a super class constructor.

23) Explain working of Java Virtual Machine (JVM)?


JVM is an abstract computing machine like any other real computing machine which
first converts .java file into .class file by using Compiler (.class is nothing but byte code file.)
and Interpreter reads byte codes.

24)What are the kinds of java variables?


 Instance variables – are created when the objects are instantiated and therefore they are
associated with objects
 Class variables – are global to a class and belong to the entire set of the objects that class
creates.
 Local variables – are declared and used within methods

25) What is meant by Inheritance?


 Inheritance is a relationship among classes, wherein one class shares the structure or
behaviour defined in another class. This is called Single Inheritance.

Prepared by L.Maria Michael Visuwasam Page 3


CS8651 – INTERNET PROGRAMMING – PART A

 If a class shares the structure or behaviour from multiple classes, then it is called
Multiple Inheritance.
 Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from
one or more generalisedsuperclasses.

26) What is meant by Inheritance and what are its advantages?


Inheritance is the process of inheriting all the features from a class. The advantages of
inheritance are reusability of code and accessibility of variables and methods of the super class
by subclasses.

27) What is the difference between superclass and subclass?


A super class is a class that is inherited whereas sub class is a class that does the
inheriting.

28) Differentiate between a Class and an Object?

 The Object class is the highest-level class in the Java class hierarchy.
 The Class class is used to represent the classes and interfaces that are loaded by a Java
program. The Class class is used to obtain information about an object's design.
 A Class is only a definition or prototype of real life object. Whereas an object is an
instance or living representation of real life object.
 Every object belongs to a class and every class contains one or more related objects.

29) What is meant by Binding?


Binding denotes association of a name with a class

30) What is an Interface?


Interface is an outside view of a class or object which emphaizes its abstraction while
hiding its structure and secrets of its behaviour.

31) What is a base class?


Base class is the most generalised class in a class structure. Most applications have
such root classes. In Java, Object is the base class for all classes.

32) Define superclass and subclass?


Superclass is a class from which another class inherits. Subclass is a class that
inherits from one or more classes.

33) What is meant by Binding, Static binding, Dynamic binding?


Binding:Binding denotes association of a name with a class.
Static binding:Static binding is a binding in which the classassociation is made during
compile time. This is also called as Early binding.
Dynamic binding: Dynamic binding is a binding in which the class association is not
made until the object is created at execution time. It is also called as Late binding.

Prepared by L.Maria Michael Visuwasam Page 4


CS8651 – INTERNET PROGRAMMING – PART A

34)What is the difference between abstract class and interface?


a. All the methods declared inside an interface are abstract whereas abstract class must
have at least one abstract method and others may be concrete or abstract.
b. In abstract class, key word abstract must be used for the methods whereas interface
we need not use that keyword for the methods.
c. Abstract class must have subclasses whereas interface can’t have subclasses.

35)What is interface and its use?


Interface is similar to a class which may contain method’s signature only but not bodies
and it is a formal set of method and constant declarations that must be defined by the class that
implements it.
Interfaces are useful for:
a) Declaring methods that one or more classes are expected to implement
b) Capturing similarities between unrelated classes without forcing a class relationship.
c) Determining an object’s programming interface without revealing the actual body of
the class.

36) What modifiers may be used with top-level class?

public, abstract and final can be used for top-level class.

37) What is an exception?


An exception is an event, which occurs during the execution of a program that
disrupts the normal flow of the program's instructions.

38) What is error?

An Error indicates that a non-recoverable condition has occurred that should not be
caught. Error, a subclass of Throwable, is intended for drastic problems, such as
OutOfMemoryError, which would be reported by the JVM itself.

39) Which is superclass of Exception?


"Throwable", the parent class of all exception related classes.

40) What are the advantages of using exception handling?

Exception handling provides the following advantages over "traditional" error


management techniques:

 Separating Error Handling Code from "Regular" Code.


 Propagating Errors Up the Call Stack.
 Grouping Error Types and Error Differentiation.

Prepared by L.Maria Michael Visuwasam Page 5


CS8651 – INTERNET PROGRAMMING – PART A

41) What are the types of Exceptions in Java?


There are two types of exceptions in Java, unchecked exceptions and checked
exceptions.

Checked exceptions:A checked exception is some subclass of Exception (orException itself),


excluding class RuntimeException and its subclasses. Each method must either handle all
checked exceptions by supplying a catch clause or list each unhandled checked exception as a
thrown exception.

Unchecked exceptions:All Exceptions that extend the RuntimeExceptionclass are


unchecked exceptions. Class Error and its subclasses also are unchecked.

42) Why Errors are Not Checked?

A unchecked exception classes which are the error classes (Error and its subclasses) are
exempted from compile-time checking because they can occur at many points in the program and
recovery from them is difficult or impossible. A program declaring such exceptions would be
pointlessly.

43) How does a try statement determine which catch clause should be used to handle
anexception?
When an exception is thrown within the body of a try statement, the catch clauses of the
try statement are examined in the order in which they appear. The first catch clause that is
capable of handling the exception is executed. The remaining catch clauses are ignored.

44) What is the purpose of the finally clause of a try-catch-finally statement?

The finally clause is used to provide the capability to execute code no matter
whether or not an exception is thrown or caught.

45) What is the difference between checked and Unchecked Exceptions in Java?
All predefined exceptions in Java are either a checked exception or an unchecked
exception. Checked exceptions must be caught using try..catch () block or we should throw the
exception using throws clause. If you don’t, compilation of program will fail.

46) What is the difference between exception and error?

 The exception class defines mild error conditions that your program encounters.
 Exceptions can occur when trying to open the file, which does not exist, the network
connection is disrupted, operands being manipulated are out of prescribed ranges, the
class file you are interested in loading is missing.
 The error class defines serious error conditions that you should not attempt to recover
from. In most cases it is advisable to let the program terminate when such an error is
encountered.

Prepared by L.Maria Michael Visuwasam Page 6


CS8651 – INTERNET PROGRAMMING – PART A

47) What is the catch or declare rule for method declarations?


If a checked exception may be thrown within the body of a method, the method must
either catch the exception or declare it in its throws clause.

48) When is the finally clause of a try-catch-finally statement executed?


The finally clause of the try-catch-finally statement is always executed unless the
thread of execution terminates or an exception occurs within the execution of the finally
clause.

49)What if there is a break or return statement in try block followed by finally block?
If there is a return statement in the try block, the finally block executes right after
the return statement encountered, and before the return executes.

50)What are the different ways to handle exceptions?

There are two ways to handle exceptions:

 Wrapping the desired code in a try block followed by a catch block to catch the
exceptions.
 List the desired exceptions in the throws clause of the method and let the caller of the
method handle those exceptions.

51) How to create custom exceptions?


By extending the Exception class or one of its subclasses.

Example:

classMyException extends Exception { public MyException() { super(); }

publicMyException(String s) { super(s); }

52) Can we have the try block without catch block?


Yes, we can have the try block without catch block, but finally block should follow the
try block.

Note:It is not valid to use a try clause without either a catch clause or a finallyclause.

53) What is the difference between throw and throws clause?


 throw is used to throw an exception manually, where as throws is used in the case of

Prepared by L.Maria Michael Visuwasam Page 7


CS8651 – INTERNET PROGRAMMING – PART A

checked exceptions, to tell the compiler that we haven't handled the exception, so that
the exception will be handled by the calling function.

throw keyword throws keyword


1)throw is used to explicitly throw an throws is used to declare an exception.
exception.
2)checked exceptions can not be propagated checked exception can be propagated with
with throw only. throws.
3)throw is followed by an instance. throws is followed by class.
4)throw is used within the method. throws is used with the method signature.
5)You cannot throw multiple exception You can declare multiple exception e.g. public
void method()throws
IOException,SQLException.

54)What are the different ways to generate an Exception?


There are two different ways to generate an Exception.

1. Exceptions can be generated by the Java run-time system. Exceptions thrown by


Java relate to fundamental errors that violate the rules of the Java language or the
constraints of the Java execution environment.

2. Exceptions can be manually generated by your code. Manually


generated exceptions are typically used to report some error condition to the
caller of a method.

55)Where does Exception stand in the Java tree hierarchy?

· java.lang.Object
· java.lang.Throwable
· java.lang.Exception
· java.lang.Error

56) Explain the exception hierarchy in java.

The hierarchy is as follows: Throwable is a parent class off all Exception classes. They
are two types of Exceptions: Checked exceptions and UncheckedExceptions. Both type of
exceptions extends Exception class

57) Explain different way of using thread?


The thread could be implemented by using runnable interface or by inheriting from the
Thread class. The former is more advantageous, 'cause when you are going for multiple

Prepared by L.Maria Michael Visuwasam Page 8


CS8651 – INTERNET PROGRAMMING – PART A

inheritance, the only interface can help.

58) What are the different states of a thread ?


The different thread states are ready, running, waiting and dead.

59) Why are there separate wait and sleep methods?


The static Thread.sleep(long) method maintains control of thread execution but delays
the next action until the sleep time expires. The wait method gives up control over thread
execution indefinitely so that other threads can run.

60)What is multithreading and what are the methods for inter-thread


communication and what is the class in which these methods are defined?

Multithreading is the mechanism in which more than one thread run independent of
each other within the process.
A program that contains multiple flows of control is known as a multithreaded program.
 wait (), notify () and notifyAll() methods can be used for inter-thread communication
and these methods are in Object class.
 wait() : When a thread executes a call to wait() method, it surrenders the object lock
and enters into a waiting state.
 notify() or notifyAll() : To remove a thread from the waiting state, some other thread
must make a call to notify() or notifyAll() method on the same object.

61)What is synchronization and why is it important?

With respect to multithreading, synchronization is the capability to control the access of


multiple threads to shared resources. Without synchronization, it is possible for one thread to
modify a shared object while another thread is in the process of using or updating that object's
value. This often leads to significant errors.

62) How does multithreading take place on a computer with a single CPU?
The Operating system's task scheduler allocates execution time to multiple tasks.
By quickly switching between executing tasks, it creates the impression that tasks
execute sequentially.

63) What do you mean by Threads in Java?


Threads
The basic unit of program execution is called thread. A process can have several threads
running concurrently, each performing a different job, such as waiting for events or performing a
time consuming job that the program doesn’t need to complete before going on. When a thread
has finished its job, the thread is suspended or destroyed.

64)What is Thread priority?


Java assigns to each thread a priority that determines how that thread should be treated

Prepared by L.Maria Michael Visuwasam Page 9


CS8651 – INTERNET PROGRAMMING – PART A

with respect to the others. Thread priorities are integers that specify the relative priority of one
thread to another.

65)What is the difference between process and thread?


Process is a program in execution whereas thread is a separate path of execution in a
program.
Process
 Process is an execution of program(heavy-weight process)
 A process can contain n no. of threads
 Context switching between process is more expensive
Thread
 Single execution sequence within a process(light weight process – thread)
 Context switching between threads is less expensive

66)What is Thread scheduling?


Execution of multiple threads on single CPU in some order is called scheduling. The
Java runtime environment supports a very simple, deterministic scheduling algorithm called
fixed-priority scheduling. This algorithm schedules threads on the basis of their priority
relative to other Runnable threads.

67) What happens when you invoke a thread's interrupt method while it is
sleepingor waiting?
When a task's interrupt() method is executed, the task enters the ready state. The next
time the task enters the running state, an InterruptedException is thrown.

68) How can we create a thread?


A thread can be created by extending Thread class or by implementing Runnable
interface. Then we need to override the method public void run().

69)How will you block a thread?


A thread can be blocked temporarily by using the following methods:
 sleep()
 suspend()
 wait()

70) What are three ways in which a thread can enter the waiting state?

A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O,
by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait()
method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

71) List the types of multithreading.


 Block multithreading

Prepared by L.Maria Michael Visuwasam Page 10


CS8651 – INTERNET PROGRAMMING – PART A

 Interleaved multithreading
 Simultaneous multithreading

72) Mention the thread priorities.


 Thread.MAX_PRIORITY – The maximum priority of any thread(an int value of 10)
 Thread.MIN_PRIORITY– The minimum priority of any thread(an int value of 1)
 Thread.NORM_PRIORITY– The normal priority of any thread(an int value of 5)

73)What are the methods available to get and set priorities?


setPriority() – to set the priority of a thread.
getPriority() – to get the priority of a thread.

74) How can we tell what state a thread is in ?


Prior to Java 5, isAlive() was commonly used to test a threads state. If isAlive()
returned false the thread was either new or terminated but there was simply no way to
differentiate between the two.

75)What is daemon thread and which method is used to create the daemon thread?
Daemon thread is a low priority thread which runs intermittently in the back ground
doing the garbage collection operation for the java runtime system. setDaemon method is used
to create a daemon thread.

76)What is the difference between yielding and sleeping?


When a task invokes its yield() method, it returns to the ready state. When a task invokes
its sleep() method, it returns to the waiting state.

77)What classes of exceptions may be thrown by a throw statement?


A throw statement may throw any expression that may be assigned to the Throwable
type.

78) A Thread is runnable, how does that work?


The Thread class' run method normally invokes the run method of the Runnable type it
is passed in its constructor. However, it is possible to override the thread's run method with your
own.

79) Can I implement my own start() method?


The Thread start() method is not marked final, but should not be overridden. This
method contains the code that creates a new executable thread and is veryspecialised. Your
threaded application should either pass a Runnable type to a new Thread, or extend Thread
and override the run() method.

Prepared by L.Maria Michael Visuwasam Page 11


CS8651 – INTERNET PROGRAMMING – PART A

80) Do I need to use synchronized on setValue(int)?

It depends whether the method affects method local variables, class static or instance
variables. If only method local variables are changed, the value is said to be confined by the
method and is not prone to threading issues.

81) What is thread priority?


Thread Priority is an integer value that identifies the relative order in which it should be
executed with respect to others. The thread priority values ranging from 1- 10 and the default
value is 5. But if a thread have higher priority doesn't means that it will execute first. The
thread scheduling depends on the OS.

82)What are the different ways in which a thread can enter into waiting state?
There are three ways for a thread to enter into waiting state. By invoking its sleep()
method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by
invoking an object's wait() method.

83) How would you implement a thread pool?


 The ThreadPool class is a generic implementation of a thread pool, which takes the
following input Size of the pool to be constructed and name of the class which
implements Runnable (which has a visible default constructor)
 Constructs a thread pool with active threads that are waiting for activation. once the
threads have finished processing they come back and wait once again in the pool.

84) What is a thread group?


A thread group is a data structure that controls the state of collection of thread as a
whole managed by the particular runtime environment.
85) What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it enters the waiting
or dead states or a higher priority task comes into existence. Under time slicing, a task executes
for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then
determines which task should execute next, based on priority and other factors.
86)What is difference between wait() and sleep() method?

Wait() Sleep()
1) The wait() method is defined in object The sleep() method is defined in Thread class.
class.

2) wait() method releases the lock. The sleep() method doesn’t release the lock.

Prepared by L.Maria Michael Visuwasam Page 12


CS8651 – INTERNET PROGRAMMING – PART A

87)What about the daemon threads?


The daemon threads are basically the low priority threads that provides the background
support to the user threads. It provides services to the user threads.
88)When should we interrupt a thread?
If any thread is in sleeping or waiting state (i.e. sleep() or wait() is invoked), calling
the interrupt() method on the thread, breaks out the sleeping or waiting state throwing
InterruptedException. If the thread is not in the sleeping or waiting state, calling the
interrupt() method performs normal behaviour and doesn't interrupt the thread but sets the
interrupt flag to true

89)What is synchronization?
Synchronization is the capabilility of control the access of multiple threads to any
shared resource.It is used:
 To prevent thread interference.
 To prevent consistency problem.

90)What is a string ?
A string represents a group of characters. A string means character array, but a string does
not means character array. A string represents an object of string class. String class is created in
java.lang package. String class is declared as final class. String class cannot extend another class.

91) Difference between equal() and == in java.


 ==” compares the references, so it gives unreliable results.
 equals() method compares the contents of string class objects. So we should equals
method for comparing two strings.
92)Difference between Strings and StringBuffer class.

STRING STRINGBUFFER
String class objects are immutable StringBuffer class objects are mutable.
String class overrides equals() and StringBuffer class doesn’t overrides
hashcode() methods of object class. equals() and hashcode() methods of object
class.
String class can be used as key in the StringBuffer class cannot be used as key in
HashMap or HashTable. the HashMap or HashTable.
It provides room for exact number of It provides room for 16 more characters.
characters.
There are no data manipulation methods in All the data manipulation methods are
the class. available in this class.

93)Why string objects are immutable ?


JVM will takes more time to reallocate memory for the same object than creating new
object. i.e, JVM will takes more time to modify contents of objects in strings. JVM will take less
time to create new string class object so string objects are always immutable.

Prepared by L.Maria Michael Visuwasam Page 13


CS8651 – INTERNET PROGRAMMING – PART A

94)What are the advantages of Strings?


There are several benefits of String because it’s immutable and final.
 String Pool is possible because String is immutable in java.
 It increases security because any hacker can’t change its value and it’s used for
storing sensitive information such as database username, password etc.
 Since String is immutable, it’s safe to use in multi-threading and we don’t need any
synchronization.
 SSStrings are used in java classloader and immutability provides security that correct
class is getting loaded by Classloader.

95)What is the difference between compareTo() method and equals() method ?


compareTo() method returns the int data type, where as equals() method returns the
Boolean data type.

96)What is the difference between creating String as new() and literal?


When you create String object using new() operator, it always create a new object
in heap memory. On the other hand, if you create object using String literal syntax e.g. "Java", it
may return an existing object from String pool (a cache of String object in Perm gen space,
which is now moved to heap space in recent Java release), if it's already exists. Otherwise it will
create a new string object and put in string pool for future re-use. In rest of this article, why it is
one of the most important thing you should remember about String in Java.

97)What is String literal and String Pool


String instances created inside double quotes e.g. "Java". These double quoted literal is
known as String literal and the cache which stored these String instances are known as as String
pool.

98)How to Compare two strings in Java?


There are four ways to compare strings:
1) String comparison using equals method
2) String comparison using equalsIgnoreCase method
3) String comparison using compareTo method
4) String comparison using compareToIgnoreCase method

Prepared by L.Maria Michael Visuwasam Page 14


CS8651 – INTERNET PROGRAMMING – PART A

99)How to replace characters or strings in Java?


There are four overloaded method to replace String in Java :
replace(char oldChar, char newChar)
replace(CharSequence target, CharSequence replacement)
replaceAll(String regex, String replacement)
replaceFirst(String regex, String replacement)

100)How to reverse String in Java with StringBuffer?


Reverse() method reverses the value of the StringBuffer object that invoked the method.
Syntax: public StringBufferreverse()
Eg.,
public class Test {

public static void main(String args[]) {


StringBuffer buffer = new StringBuffer("Game Plan");
buffer.reverse();
System.out.println(buffer);
}
}

101)How to reverse String in Java without StringBuffer?


classReverseString
{
publicstaticvoid main(String args[])
{
String original, reverse = "";
Scanner in = newScanner(System.in);

System.out.println("Enter a string to reverse");


original = in.nextLine();

int length = original.length();

for ( int i = length - 1 ; i >= 0 ; i-- )


reverse = reverse + original.charAt(i);

System.out.println("Reverse of entered string is: "+reverse);


}
}

102)How to search a word inside a string ?


public class SearchStringEmp{
public static void main(String[] args) {
String strOrig = "Hello readers";

Prepared by L.Maria Michael Visuwasam Page 15


CS8651 – INTERNET PROGRAMMING – PART A

intintIndex = strOrig.indexOf("Hello");
if(intIndex == - 1){
System.out.println("Hello not found");
}else{
System.out.println("Found Hello at index "
+ intIndex);
}
}
}

Output:
Found Hello at index 0

103)How to count the no. of words in java?


public class Sample
{
public static intcountWords(String str)
{
int count = 1;
for (int i=0;i<=str.length()-1;i++)
{
if (str.charAt(i) == ' ' &&str.charAt(i+1)!=' ')
{
count++;
}
}
return count;
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a sentence: ");
String sentence = in.next();
System.out.print("Your sentence has " + countWords(sentence) + " words.");
}
}

104)How to count the no. of vowels, blank spaces and digits in Java?
class Sample
{
public static void main(String args[])
{
String str;
int vowels = 0, digits = 0, blanks = 0;
charch;

Prepared by L.Maria Michael Visuwasam Page 16


CS8651 – INTERNET PROGRAMMING – PART A

Scanner in = new Scanner(System.in);


System.out.print("Enter a sentence: ");
String str = in.next();

for(int i = 0; i <str.length(); i ++)


{
ch = str.charAt(i);

if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' ||


ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
vowels ++;
else if(Character.isDigit(ch))
digits ++;
else if(Character.isWhitespace(ch))
blanks ++;
}

System.out.println("Vowels : " + vowels);


System.out.println("Digits : " + digits);
System.out.println("Blanks : " + blanks);
}
}

Output:
Enter a String : ABC DE 123
Vowels : 2
Digits : 3
Blanks : 2

UNIT II
WEB 2.0
1. Define Link building
 Link building is the process of increasing search engine rankings and traffic by generating
inbound links to a particular website.
2. Define Search engine optimization
Search Engine Optimization (SEO) is the process of designing and tuning your website to maximize your
findability and improve your rankings in organic (non-paid) search engine results.

3.What are content networks?


Content networks are websites or collections of websites that provide information in various forms (such
as articles, wikis, blogs, etc.). These provide another way of filtering the vast amounts of information on
the Internet, by allowing users to go to a trusted site that has already stored through many sources to find
the best content or has provided its own content.
4.What are user-generated content?
 User-generated content has been the key to success for many of today’s leading Web 2.0
companies, such as Amazon, eBay and Monster.

Prepared by L.Maria Michael Visuwasam Page 17


CS8651 – INTERNET PROGRAMMING – PART A

 The community adds value to these sites, which, in many cases, are almost entirely built on user-
generated content. For example, eBay (an online auction site) relies on the community to buy and
sell auction items, and Monster (a job search engine) connects job seekers with employers and
recruiters.
5.Define blogging.
 Blogs are websites consisting of entries listed in reverse chronological order.
 The term “blog” evolved from weblog, a regularly updated list of interesting websites.
 Blogs can also now incorporate media, such as music or videos.

What are the components of Blogs?


 Reader Comments create an interactive experience, allowing readers to react to blog entries.
 Permalinks provide blog readers with a way of linking to specific blog entries.
 Trackbacks tell bloggers who is linking to their posts.
 blogroll is a list of the blogger’s favorite blogs.

Define Social networking.


Social networking sites, which allow users to keep track of their existing interpersonal relationships
and form new ones, are experiencing extraordinary growth in Web 2.0.
 Friendster was an early leader in social networking in 2002. Friendster experienced a boom in
popularity that quickly overwhelmed its servers
 MySpace is the most popular social networking site. Hitwise reported it as the top website in
May 2007 based on market share (beating Google by 1.5%).
 Facebook the “preferred network among college students. Because Facebook was closed to
non-students, students felt safer than on MySpace, and Facebook became nearly a social
necessity for students seeking to connect with peers.”
 Linkedinis a business-oriented social networking service. Founded in December 2002 and
launched on May 5, 2003, it is mainly used for professional networking.

Difference between Web1.0 and Web2.0

Define RIA
 Rich Internet applications (RIA) are Web-based applications that have some characteristics of
graphical desktop applications.
 Built with powerful development tools, RIAs can run faster and be more engaging.

Prepared by L.Maria Michael Visuwasam Page 18


CS8651 – INTERNET PROGRAMMING – PART A

 They can offer users a better visual experience and more interactivity than traditional browser
applications that use only HTML and HTTP.
Why RIA?
 Users are dissatisfied with the capabilities and performance of simple HTML-based Web
applications like process complexity, data complexity and feedback complexity
 Need for desktop type interactions.
 Bringing interactivity & intuitiveness into web applications
 Adds complexity to design, develop, deploy and debug

What are the characteristics of RIA?


 Direct interaction
 Partial-page updating
 Better feedback
 Consistency of look and feel
 Offline use
 Performance impact

What are the benefits of RIA?


 Features that WOW the users
 Lots of processing can be off-loaded to the client.
 Adoption spreads rapidly and dramatically.
 Improved responsiveness
 Platform independence
 Businesses have more reach to their offerings through rich web applications.
 Deployment costs are minimal

Name some RIAs.


 AJAX
 Dojo
 Flex
 Silverlight

What are collaboration tools?


Collaboration is a process defined by the recursive interaction of knowledge and mutual learning between
two or more people who are working together, in an intellectual endeavor, toward a common goal which
is typically creative in nature. The tools that are used to achieve the same are called collaboration tools.

Prepared by L.Maria Michael Visuwasam Page 19


CS8651 – INTERNET PROGRAMMING – PART A

Difference between internet and intranet.


INTERNET AND INTRANET
S.NO CHARACTERISTICS INTERNET INTRANET

1. Definition Internet is a world-wide / Intranet is system in which


global system of multiple PCs are connected to
interconnected computer each other.
networks.

2. Accessibility Internet has wider access PCs in intranet are not available
and provides a better to the world outside the intranet.
access to websites to
large population
3. Network Traffic Unlimited Limited
4. No. of Users Unlimited Limited
5. Information source Unlimited source of Specific group purpose
information information

Define internet .
Network is an interconnection of systems to share data and information. Internet is network of
network or collection of heterogeneous networks.

2. What is the use of IP addresses and ports?


It is very difficult to remember the IP address of each and every node. It order to avoid this
problem domain names are used. Example googl.com, rediff.com etc.

Ports
Ports are used in receiving and sending data to another server or client.
Example for port numbers
Protocol Port Protocol Purpose
Echo 7 TCP/UDP Echo is a test protocol used to verify that 2 machines
1. are able to connect by having one echo back the Application Layer Transport Layer (TCP,
UDP) Internet layer (IP) Physical path(Ethernet, FDDI etc) other’s input.

Prepared by L.Maria Michael Visuwasam Page 20


CS8651 – INTERNET PROGRAMMING – PART A

Discard 9 TCP/UDP Discard is a less useful test protocol in which all data
2. received by the server is ignored.
FTP 21
SMTP 25
HTTP 80
POP3 110
NTP 119 Usenet News transfer is more formally known as the Network News Transfer Protocol
RMI Registry 1099 This is the registry service for Java Remote Objects.

3. Mention the different internet address class and it’s range.


Internet addresses are assigned to different organizations by the Internet Assigned Numbers
Authority (IANA).
ISP – Internet Service Providers gives a block addresses.
Class C address block specifies the first 3 bytes of address, for example 199.1.32. This allows
room for 254 individual addresses from 199.1.32.1 to 199.1.32.254
Class B address specified only the first 2 bytes of the addresses .
There are also Class D and E addresses are used for IP multicast group.

4. Define Firewall.
The hardware and software that sits between the Internet and the local network, checking all the
data that comes and goes out is called “firewalls”. The security is provided using SSL(Secure
Socket Layer) in internet.

5. Define Proxy Servers


Proxy servers are related to firewalls prevents hosts on a network from making direct
connections to the outside world, a proxy server can act as a go-between. Thus a machine that is
prevented from connecting to the external network by a firewall would make a request for a web
page from the local proxy server instead of requesting the web page directly from the remote
web server.

6. What is the use of HTTP protocol?


HTTP is a standard protocol that defines how a web client talks to a server and how data is
transferred from the server back to the client.
HTTP relies heavily on two other standards.
MIME (Multipurpose Internet Mail Extensions), HTML

7. What is the use of MIME?(Multipurpose Internet Mail Extension)


MIME is a way to encode different kinds of data, such as sound and text, to be transmitted over a
7-bit ASCII connection. It also lets the recipient know what kind of data has been sent, so that it
can be displayed properly. MIME was originally designed to facilitate multimedia email and to
provide an encoding that could get binary data past the most train –damaged mail transfer
programs.
MIME is an open standard for sending multipart, multimedia data through Internet email. MIME
was originally intended for email, it has become a widely used technique to describe a file’s
contents so that client software can tell the difference between different kinds of data.

Prepared by L.Maria Michael Visuwasam Page 21


CS8651 – INTERNET PROGRAMMING – PART A

8. Define URL & URN.


URL
Uniform Recourse Locator is a way to unambiguously identify the location of a resource on the
Interned. URI Uniform Resource Identifier is a string of characters in a particular syntax that
identifies a resource. The resource identified may be a file on a server, but it may also be an
email address, a news message, b book, a person’s name, an Internet host.
Syntax
Scheme: scheme-specific-part
Scheme types
data – base 64 encoded data included directly in a link
file – A file on a local disk
FTP – An FTP server
gopher – a Gopher server
mailto – an email address
news – A Usenet newsgroup
Telnet – A connection to a Telnet based service (only used in Remote Login System)
urn – Uniform Resource Name

9. Explain about URN


There are 2 types of URLs.
URL – Unform Resource Locaters (is a pointer to a particular resource on the Internet at a
particular location.)
URNs – Uniform Resource Name (is a name for a particular resource but without reference to a
particular location)
Syntax
urn:namespace:resource-name
namespace - is the name of a collection of certain kinds of resources maintained by some
authority.
resource-name – is the name of a resource within that collection.

10. What is meant by relative URL?


URLs that are not complete but inherit pieces from their parent are called relative URL.
In contrast, a completely specified URL is called an absolute URL address.

11. Explain about SGML – Standard Generalized Markup Language


• HTML is an instance of SGML.
• SGML was invented beginning in the mid-1970s by Charles Goldfarb at IBM
• SGML is now an International Standards Organization (ISO) standard, specifically ISO
8879:1986.
• SGML allows the user to create various user defined tags easily without any rules.
EXAMPLE 1 – FOR PRODUCT DETAILS
<PRODUCT MANUFACTURER=”ABC COMPANY”> -Assumed as record name
<NAME> KEY BOARD </NAME>
<TYPE> KEY BOARD </TYPE>
<PRICE> 1500 </PRICE>

Prepared by L.Maria Michael Visuwasam Page 22


CS8651 – INTERNET PROGRAMMING – PART A

</PRODUCT

12. Explain about XML – eXtensible Markup Language


• Similar to SGML
• Allows the user to create any number of user defined tags.
• The value of an attribute may be enclosed in double of single quotes like this:
• <H1 ALIGN=CENTER> THIS IS CENTERED H1 HEADING </H1>
• STYLES can be introduced for XML program like CSS using XLS file(XML Style Sheet
program)
• Here XML styles are saved with an extension of .xls (XML style sheet)
• Using .xls files various styles can be given to the data which is inside the XML program.

13. List the steps functions of HTTP protocol.


Standard protocol for communication between web browsers and web servers.
HTTP specifies how a client and server establish a connection, how the client requests data from
the server, how the server responds to that request, and finally how the connection is closed.
HTTP 1.0 is the currently accepted version of the protocol. It uses MIME to encode data. The
basic protocol defines a sequence of 4 steps for each request from a client to the server.
Making the connection
Making a request
Receiving the response
Closing the connection

14. What is domain & mention different types of domains


Domain is a place where information is available.
DOMAIN NAME EXTENSION
.edu – Servers that provide Educational services
.gov – About the government of a country.
.mil – Servers that provide military information.
.org – Provide information about the organizations in the world.
.com – Servers providing commercial services on the Internet.

HTML
15. Write the format of HTML program
<HTML>
<HEAD>
<TITLE>This is the Title </TITLE>
</HEAD>
<BODY>
…. Type the body of the program
</BODY>
</HTML>
Note: All the tags in HTML program are optional, however the file should be saved in .html
extension.

16. Mention some text formatting tags

Prepared by L.Maria Michael Visuwasam Page 23


CS8651 – INTERNET PROGRAMMING – PART A

<p></p> - is used for introducing various paragraphs.


<br> - this tag is used for giving an empty blank line.
HEADING TAGS - <h1></h1> ..<h6></h6> is used to introduce various headings.
<h1> is the biggest and h6 is the smallest heading tag.
<HR> TAG – is used to draw lines and horizontal rules.
<B>,<I>,<U> for bold, italic and underline respectively.

17. Explain about list tag.


TYPES OF LISTS
Unordered lists
Ordered lists
UNORDERED LISTS
It starts with <ul> and ends with </ul>
Attributes of Unordered lists
TYPE:
TYPE = FILLROUND or TYPE = SQUARE
EXAMPLE
<UL TYPE = FILLGROUND>
<LI> CSE </LI>
<LI> IT </LI>
</UL>
ORDERED LISTS (NUMBERING>
TYPE: Controls the numbering scheme to be used
TYPE = “1” will give counting numbers (1,2,…>
“A” will give A,B,C..
“a” will give a,b,c
“I” starts with Capital roman letters I,II,II…
“I” starts with small case roman letters
START: Alters the numbering sequence, can be set to any numeric value
VALUE: Change the numbering sequence in the middle of an ordered list
EXAMPLE
<OL TYPE = “1” START = 5>
<LI> CSE </LI>
<LI> IT </LI>
</OL>
OUTPUT
5 CSE
6 IT

18. Explain the attributes of table tag with an example


A table is a two dimensional matrix, consisting of rows and columns. All table related tags are
included between <TABLE></TABLE> tags.
<TABLE>
<TH> Heading </TH>
<TR> Row elements </TR>
<TD> Table data values </TD>

Prepared by L.Maria Michael Visuwasam Page 24


CS8651 – INTERNET PROGRAMMING – PART A

</TABLE>

ATTRIBUTES OF TABLE TAG


ALIGN Horizontal alignment is controlled by the ALIGN attribute. It can be set to LEFT,
CENTER, or RIGHT VALIGN Controls the vertical alignment of cell contents. It accepts the
values TOP, MIDDLE or BOTTOM WIDTH Sets the WIDTH of a specific number of pixels or
to a percentage of the available screen width.
BORDER: Controls the border to be placed around the table.
CELLPADING This attribute controls the distance between the data in a cell and the boundaries
of the cell
CELLSPACING Controls the spacing between adjacent cells
COLSPAN Used to spilt the single cell to one or more columns
ROWSPAN Used to spilt the single cell to one or more rows.
ALIGN: ALIGN = TOP, MIDDLE,BOTTOM
BORDER: Specifies the size of the border to place around the image.
WIDTH: Specifies the width of the image in pixels.
HEIGHT: Specifies the height of the image in pixels
HSPACE: Indicates the amount of space to the left and right of the image
VSPACE: Indicates the amount of apace to the top and bottom of the image

Example
<TABLE BORDER = 3 WIDTH = 100 HEIGHT = 200>
<TR>
<TH> Roll Number </TH>
<TH> Age </TH>
<TR>
<TR><TD> 1 </TD><TD 35 </TD></TR>
</TABLE>
.
19. What do you mean by column spanning and row spanning?
Row spanning is used to merge (combine) two or more rows.
Column spanning is used to merge (combine) two or more columns.

20. Mention the different types of links


HTML allows linking to other HTML documents as well as images. There are 3 attributes that
can be introduced in BODY tag.
LINK – Changes the default color of a Hyperlink to whatever color is specified with this tag.
ALINK – Changes the default color of a hyperlink that is activated to whatever color is specified
with this tag.
VLINK – Changes the default color of a hyperlink that is already visited to whatever color is
specified with this tag.
NOTE: User can specify the color name of a hyperlink or an equivalent hexadecimal number.
EXTERNAL LINKS
SYNTAX
<A HREF = “location name”> Hyper Text Message </A>

Prepared by L.Maria Michael Visuwasam Page 25


CS8651 – INTERNET PROGRAMMING – PART A

21. Explain image maps with its syntax


When a hyperlink is created on an image, clicking on any part of the image will lead to opening
of the document specified in the <A HREF TAG>. Linked regions of an image map are called
hot regions and each hot region is associated with
a filename.html.

Syntax
<MAP NAME = “map name”>
ATTRIBUTES OF IMAGE MAPS
COORDS: Each of the above shapes takes different coordinates as parameters.
Rectangle – 4 coordinates (x1,y2,x3,y2)
POLYGON: 3 or more coordinates.
HREF – Takes the name of the .html file that s linked to the particular area on the
image.
<MAP NAME = “fish.jpg”>
<AREA SHAPE = “rect” COORDS = “52,65,122,89” HREF = “sct.html”>
</MAP>

22. Explain about HTML form tag with its attributes.


HTML form provides several mechanisms to collect information from people viewing your site.
The syntax of the form is
<FORM METHOD = “POST” ACTION = “/cgi-bin/formail”>
• The METHOD attribute indicates the way the web server will organize and send you the form
output.
• Use METHOD = “post” in a form that causes changes to server data, for example when
updating a database.
• The ACTION attribute in the FORM tag is the path to this script; in this case, it is a common
script which emails form data to an address. Most Internet Service Providers will have a script
like this on their site.

23. Mention the various form elements.


Various elements or controls can be created in FORM using <INPUT> tag. They are 1. Label 2.
Text box 3. Text Area 4.Radio button 5. Check box 6. List box 7. Command button 8. Scroll bars

24. What is the use of frames in html give the syntax of frames
Frames are used to call many html files at the same time. This can be done using
<FRAMESET></FRAMESET> tags.
ATTRIBUTES OF FRAMES
ROWS – This attribute is used to divide the screen into multiple rows. It can be set equal to a list
of values. Depending on the required size of each row. The values can
• A number of pixels
• Expressed as a percentage of the screen resolution
• The symbol *, which indicates the remaining space.
COLS – This attribute is used to divide the screen into multiple columns.
EXAMPLE
<FRAMESET ROWS = “30%,*”> => Divides the screen into 2 rows,

Prepared by L.Maria Michael Visuwasam Page 26


CS8651 – INTERNET PROGRAMMING – PART A

• occupying the remaining space


<FRAMESET COLS = “50%,50%”> => Divides the first row into 2 equal
columns
<FRAME SRC = “file1.html”>
<FRAME SRC = “file2.html”>
<FRAMESET COLS = “50%,50%”> => Divides the second
row into 2 equal columns
<FRAME SRC = file3.html”>
<FRAME SRC = file4.html”>
</FRAMESET>
</FRAMESET>

25. What is the difference between node and host?


A node is any addressable device connected to a network whereas the host is a more specific
descriptor that refers to a networked general-purpose computer rather than a single purpose
device (such as a printer).

26. Define protocol.


A protocol is a formal set of rules that must be followed in order to communicate.

27. Define port.


A port is a logical channel to an application running on a host. ie., The applications running on
the host machines are uniquely identified by port numbers.

28. What do you mean by well-known ports?


Port numbers can range from 1 to 65535, however ports 1 to 1023 are reserved. These reserved
ports are referred to as we1l-known ports because the Internet Assigned Numbers Authority
publicly documents the applications that use them.

29. What is meant by Name Resolution?


Name Resolution is the process of mapping a hostname to its corresponding IP Address. One
way to translate a hostname to an IP address is to look it up in a simple text file. The second way
is the domain name service, which is a distributed database containing all registered hostnames
on the Internet and their IP addresses.

30. Define URI, URL, URN.


• URI (Uniform Resource Identifier): It identifies an object on the Internet.
• URL (Uniform Resource Locator): It is a specification for identifying an object such as a file,
newsgroup, CGI program or e-mail address by indicating the exact location on the internet.
• URN (Uniform Resource Name): It is a method for referencing an object without declaring the
full path to the object.

31. What are the components of HTTP URL?


The components are host, an optional port, path, filename, section and query string.

32. Define URL encoding.

Prepared by L.Maria Michael Visuwasam Page 27


CS8651 – INTERNET PROGRAMMING – PART A

URL encoding involves replacing all unsafe and nonprintable characters with a percent sign (%)
followed by two hexadecimal digits corresponding to the character\'s ASCII value.

33. What are the issues of next generation IP?


The issues to be considered in IP next generation are
o Addresses Space Growth
o Support large Global networks
o A clear way of transition from the existing IP to new IP next generation

34. List the goals of SGML.


• To manage the flow of millions of pages.
• For structuring information exchange
• For modeling inter-document linkages
• For managing information flows between departments and weapons systems

35. What is the role of server?


The server
• Manages application tasks
• Handles storage
• Handles security
• Provides scalability
• Handles accounting and distribution

36. What are the necessities of using HTML forms?


1. Gathering user information
2. Conducting Surveys
3. Interactive services

37. What are the sequences of steps for each HTTP request from a client to the server?
1. Making the connection
2. Making a request
3. The response
4. Closing the connection

38. List the predefined MIME content types.


1. Text
2. Multipart
3. Message
4. Image
5. Audio
6. Video
7. Model
8. Application

39. Define HTML.


It is a simple page description language, which enables document creation for the web.

Prepared by L.Maria Michael Visuwasam Page 28


CS8651 – INTERNET PROGRAMMING – PART A

40. What is meant by loop back address?


A zone that enables the server to direct traffic to itself. The host number is almost always
127.0.0.1.

41. Explain about HTTP Connection.


It is a communication channel between web browser and web server. It begins on the client side
with the browser sending a request to the web server for a document.
Request Header Fields are
1. From
2. Reference
3. If_modified_since
4. Pragma
5. User Agent

42. What do mean by search engine?


It is a program or web page that enables you to search an Internet site for a specific keywords or
words.

43. How do search engine work?


When you enter a keyword, the search engine examines its online database and presents to you a
listing of sites that, in theory , match your search criteria.

44. What are the ways by which a server and a browser do communicate?
GET & POST method

45. What is HTML?


HyperText Markup Language. This is a file format, based on SGML, for hypertext documents on
the Internet. It is very simple and allows for the embedding of images, sounds, video streams,
form fields and simple text formatting. References to other objects are embedded using URLs.
HTML is a plain text file with commands <markup tags> to tell the Web browsers how to display
the file.

46. How do you change the color of background or text in HTML?


Include the element \"bgcolor\" with a color code in your body tag:
<BODY BGCOLOR=\"#ffffff\" TEXT=\"#000000\" LINK=\"#cc0000\"
VLINK=\"#000066\" ALINK=\"#ffff00\">

47. How do you use a picture as the background in HTML?


Include the element \"background\" with the name of the graphics file:
<BODY BACKGROUND=\"gumby.gif\" BGCOLOR=\"#ffffff\" TEXT=\"#000000\"
LINK=\"#cc0000\" VLINK=\"#000066\" ALINK=\"#ffff00\">

48. How do you add music to a web page?


<A HREF=\"http://www.snowhawk.com/sounds/hvnearth.mid\">Heaven on Earth</A>

Prepared by L.Maria Michael Visuwasam Page 29


CS8651 – INTERNET PROGRAMMING – PART A

49. How do you align text next to a graphic in HTML?


<IMG SRC=\"wflower.jpg\" WIDTH=\"25\" HEIGHT=\"25\" ALIGN=\"top\" BORDER=\"0\"
ALT=\"wildflower photo\"> Photo of wildflowers in Texas</A>

50. How do you make a graphic a link?


<AHREF=\"http://www.snowhawk.com/wildlife.html\"><IMG SRC=\"leopard.jpg\"
WIDTH=\"25\" HEIGHT=\"25\" ALIGN=\"top\" BORDER=\"0\" ALT=\"link to
wildlife\"></A>

51. How do you make a new paragraph in HTML?


Inserting the <P> tag at the beginning of your paragraph will drop the text down two lines. (If
you insert the <BR> tag, it will drop your text down one line.)

52. How do you make headings and text larger or smaller?


There are 6 sizes to the heading tags:
This is using the <H1> tag
This is using the <H2> tag
This is using the <H3> tag
This is using the <H4> tag
This is using the <H5> tag
This is using the <H6> tag

53. How do you make text show as bold?


Placing the <B>tag before the text will make everything bold, until you close the tag with</B>
(Or using <STRONG>tags</STRONG > will do the same.)

54. How do I make text show in italics?


Placing the <I>tag before the text will make everything in italics, until you close the tag with</I>
(Using <EM>emphasis tags</EM > will do the same.)

55. How would you make all text on a page green and a little larger than normal, but make
all headings yellow?
Put the following at the beginning of the Web page:
<BODY TEXT=”green”><BASEFONT SIZE=4>
Then make each heading look like this:
<H1><FONT COLOR=”Yellow”>Heading goes here </FONT></H1>

56. Write the HTML to create the following ordered list.


X. Xylophone
Y. Yak
Z. Zebra
<OL TYPE =”A” START = “24”>
<LI> Xylophone
<LI>YAK
<LI>Zebra
</OL>

Prepared by L.Maria Michael Visuwasam Page 30


CS8651 – INTERNET PROGRAMMING – PART A

The following alternative will also do the same things.


<OL TYPE =”A”<LI VALUE =”24”>Xylophone<LI>Yak<LI>Zebra</OL>

57. How would you insert a single word and put a square bullet in front of it?
<UL TYPE=”Square”><LI>Supercalifragilisticexpealidocious</UL>

58. How would you insert an image file named elephant.jpg at the very top of a Web page?
Copy the image file into the same directory folder as the HTML text file and type <IMG SRC>
immediately after the <BODY> tag in the HTML text file

59. How would you give a Web page a black background and make all text, including links,
bright green?
Put the following at the beginning of the Web page:
<BODY BGCOLOR=”black”>
The following would do the same thing”
<BODY BGCOLOR =”#000000”
TEXT=”#00FF00” LINK=”00FF00” VLINK=”#000000”>

60. How would you make an image file named texture.jpg appear as a background tile?
<BODY BACKGROUND=”texture.jpg”
TEXT=”White” LINK=”red” VLINK=”blue” ALINK=”black”>

61. How would you wrap text around the right side of an image, leaving 40 pixels of space
between the image and the text?
<IMG SRC=”myimage.gif” HSPACE=40 VSPACE=40 ALIGN=”left”>Text goes here

62. How could you insert exactly 80 pixels of blank space between two paragraphs of text?
Create a small image that is all one color, and save it as nothing.gif with that color set to be
transparent. Then put the following tag between the two paragraphs of text:
<IMG SRC=”nothing.gif” WIDTH=1 HEIGHT=80>
63. How would you write the HTML to draw a rule 20 pixels wide?
<HR WIDTH=20>

64. If you have a circular button that links to another page, how do you prevent a rectangle
from appearing around it?
Use the BORDER=0 attribute, like this:
<A HREF=”another_page.htm”><IMG SRC=”circle.gif” BORDER=0></A>

65. What is meant by Stateless Connection?


When a web server receives a HTTP request from a web browser it evaluates the request and
returns the requested document, if it exists, and then breaks the HTTP connection.This document
is preceded by the response header, which has details about how to display thedocument that will
be sent by the server. Each time a request is made to the server, it is as ifthere was no prior
connection and each request can yield only a single document. This isknown as Stateless
Connection.

Prepared by L.Maria Michael Visuwasam Page 31


CS8651 – INTERNET PROGRAMMING – PART A

CSS

1) What is CSS?
CSS stands for Cascading Style Sheet. It is a popular styling language which is used with HTML
to design websites.

2) What is the origin of CSS?


SGML (Standard Generalized Markup Language) is the origin of CSS.

3) What are the different variations of CSS?


Following are the different variations of CSS:
o CSS1
o CSS2
o CSS2.1
o CSS3
o CSS4

4) How can you integrate CSS on a web page?


There are three methods to integrate CSS on web pages.
1. Inline method
2. Embedded/Internal method
3. Linked/Imported/External method

5) What are the advantages of CSS?


o Bandwidth
o Site-wide consistency
o Page reformatting
o Accessibility
o Content separated from presentation

6) What are the limitations of CSS?


o Ascending by selectors is not possible
o Limitations of vertical control
o No expressions
o No column declaration
o Pseudo-class not controlled by dynamic behavior
o Rules, styles, targeting specific text not possible

7) What are the CSS frameworks?


CSS frameworks are the preplanned libraries which makes easy and more standard compliant
web page styling.
8) Why background and color are the separate properties if they should always be set
together?
There are two reasons behind this:

Prepared by L.Maria Michael Visuwasam Page 32


CS8651 – INTERNET PROGRAMMING – PART A

o It enhances the legibility of style sheets. The background property is a complex property
in CSS and if it is combined with color, the complexity will further increases.
o Color is an inherited property while background is not. So this can make confusion
further.

9) What is Embedded Style Sheet?


An Embedded style sheet is a CSS style specification method used with HTML. You can embed
the entire style sheet in an HTML document by using the STYLE element.

10) What are the advantages of Embedded Style Sheets?


o You can create classes for use on multiple tag types in the document.
o You can use selector and grouping methods to apply styles in complex situations.
o No extra download is required to import the information.

11) What is CSS selector?


It is a string that identifies the elements to which a particular declaration will apply. It is also
referred as a link between the HTML document and the style sheet. It is equivalent of HTML
elements.

12) What is ruleset?


Ruleset is used to identify that selectors can be attached with other selectors. It has two parts:
o Selector
o Declaration

13) What is the difference between class selectors and id selectors?


An overall block is given to class selector while id selectors take only a single element differing
from other elements.

14) What are the advantages of External Style Sheets?


o You can create classes for reusing it in many documents.
o By using it, you can control the styles of multiple documents from one file.
o In complex situations, you can use selectors and grouping methods to apply styles.

15) What is the difference between inline, embedded and external style sheets?
Inline: Inline Style Sheet is used to style only a small piece of code.
Embedded: Embedded style sheets are put between the <head>...</head> tags.
External: This is used to apply the style to all the pages within your website by changing just
one style sheet.

16) What is the CSS Box model and what are its elements?
The CSS box model is used to define the design and layout of elements of CSS.
The elements are:
o Margin
o Border
o Padding
o Content

Prepared by L.Maria Michael Visuwasam Page 33


CS8651 – INTERNET PROGRAMMING – PART A

20) What is the float property of CSS?


The CSS float property is used to move the image to the right or left along with the texts to be
wrapped around it. It doesn't change the property of the elements used before it.

UNIT III
JAVASCRIPT
1) What is JavaScript?
JavaScript is a scripting language. It is different from Java language. It is object-based,
lightweight and cross platform. It is widely used for client side validation. More details...
2) What is the difference between JavaScript and jscript?
Netscape provided the JavaScript language. Microsoft changed the name and called it JScript to
avoid the trademark issue.In other words, you can say JScript is same as JavaScript, but it is
provided by Microsoft.

3) How to write a hello world example of JavaScript?


A simple example of JavaScript hello world is given below. You need to place it inside the body
tag of html.
<script type="text/javascript">
document.write("JavaScript Hello World!");
</script>
4) How to use external JavaScript file?
Assume that js file name is message.js, place the following script tag inside the head tag.
<script type="text/javascript" src="message.js"></script>
5) Is JavaScript case sensitive language?
Yes.
6) What is BOM?
BOM stands for Browser Object Model. It provides interaction with the browser. The default
object of browser is window.
Browser Object Model
7) What is DOM? What is the use of document object?
DOM stands for Document Object Model. A document object represent the html document. It
can be used to access and change the content of html.
Document Object Model
8) What is the use of window object?
The window object is automatically created by the browser that represents a window of a
browser.
It is used to display the popup dialog box such as alert dialog box, confirm dialog box, input
dialog box etc.
9) What is the use of history object?
The history object of browser can be used to switch to history pages such as back and forward
from current page or another page. There are three methods of history object.
history.back()
history.forward()
history.go(number): number may be positive for forward, negative for backward.

Prepared by L.Maria Michael Visuwasam Page 34


CS8651 – INTERNET PROGRAMMING – PART A

10) How to write comment in JavaScript?


There are two types of comments in JavaScript.
Single Line Comment: It is represented by // (double forward slash)
Multi Line Comment: It is represented by slash with asterisk symbol as /* write comment here */

11) How to create function in JavaScript?


To create function in JavaScript, follow the following syntax.
functionfunction_name(){
//function body
}
12) What are the JavaScript data types?
There are two types of data types in JavaScript:
Primitive Data Types
Non-primitive Data Types

13) What is the difference between == and ===?


The == operator checks equality only whereas === checks equality and data type i.e. value must
be of same type.

14) How to write html code dynamically using JavaScript?


The innerHTML property is used to write the HTML code using JavaScript dynamically. Let's
see a simple example:
document.getElementById('mylocation').innerHTML="<h2>This is heading using
JavaScript</h2>";
15) How to write normal text code using JavaScript dynamically?
The innerText property is used to write the simple text using JavaScript dynamically. Let's see a
simple example:
document.getElementById('mylocation').innerText="This is text using JavaScript";
16) How to create objects in JavaScript?
There are 3 ways to create object in JavaScript.
By object literal
By creating instance of Object
By Object Constructor
Let's see a simple code to create object using object literal.
emp={id:102,name:"Rahul Kumar",salary:50000}

17) How to create array in JavaScript?


There are 3 ways to create array in JavaScript.
By array literal
By creating instance of Array
By using an Array constructor
Let's see a simple code to create array using object literal.
varemp=["Shyam","Vimal","Ratan"];

18) What is regular expression?

Prepared by L.Maria Michael Visuwasam Page 35


CS8651 – INTERNET PROGRAMMING – PART A

A regular expression is an object that describes a pattern of characters.

Regular expressions are used to perform pattern-matching and "search-and-replace" functions on


text.
Syntax:
/pattern/modifiers;
Eg.,
varpatt = /velammal/i

19) What is the output of 10+20+"30" in JavaScript?


3030 because 10+20 will be 30. If there is numeric value before and after +, it is treated is binary
+ (arithmetic operator).

20) What is the output of "10"+20+30 in JavaScript?


102030 because after a string all the + will be treated as string concatenation operator (not binary
+).
SERVLETS
1.What is the Servlet?
A servlet is a Java programming language class that is used to extend the capabilities of servers
that host applications accessed by means of a request- response programming model.

2.What are the uses of Servlet?


Typical uses for HTTP Servlets include:

 Processing and/or storing data submitted by an HTML form.


 Providing dynamic content, e.g. returning the results of a database query to the client.
 A Servlet can handle multiple request concurrently and be used to develop high
performance system
 Managing state information on top of the stateless HTTP, e.g. for an online shopping cart
system which manages shopping carts for many concurrent customers and maps every
request to the right customer.

3.What are the advantages of Servlet over CGI?


Servlets have several advantages over CGI:

 A Servlet does not run in a separate process. This removes the overhead of creating a new
process for each request.
 A Servlet stays in memory between requests. A CGI program (and probably also an
extensive runtime system or interpreter) needs to be loaded and started for each CGI
request.
 There is only a single instance which answers all requests concurrently. This saves
memory and allows a Servlet to easily manage persistent data.

Prepared by L.Maria Michael Visuwasam Page 36


CS8651 – INTERNET PROGRAMMING – PART A

 Several web.xml conveniences


 A handful of removed restrictions
 Some edge case clarifications

4. What are the phases of the servlet life cycle?


The life cycle of a servlet consists of the following phases:

 Servlet class loading


 Servlet instantiation
 Initialization (call the init method)
 Request handling (call the service method)
 Removal from service (call the destroy method)

The life cycle of a servlet is controlled by the container in which the servlet has been
deployed.

5. What is Web Container?


Web container (also known as a Servlet container) is the component of a web server that
interacts with Java servlets. A web container is responsible for managing the lifecycle of
servlets, mapping a URL to a particular servlet and ensuring that the URL requester has the
correct access rights.

6.How the servlet is loaded?


A servlet can be loaded when:

Prepared by L.Maria Michael Visuwasam Page 37


CS8651 – INTERNET PROGRAMMING – PART A

 First request is made.


 Server starts up (auto-load).
 There is only a single instance which answers all requests concurrently. This saves
memory and allows a Servlet to easily manage persistent data.
 Administrator manually loads.

7.How a Servlet is unloaded?


A servlet is unloaded when:

 Server shuts down.


 Administrator manually unloads.

8.What is Servlet interface?


The central abstraction in the Servlet API is the Servlet interface. All servlets implement this
interface, either directly or , more commonly by extending a class that implements it.

Note: Most Servlets, however, extend one of the standard implementations of that interface,
namely javax.servlet.GenericServlet andjavax.servlet.http.HttpServlet.

9.What is the GenericServlet class?


GenericServlet is an abstract class that implements the Servlet interface and the ServletConfig
interface. In addition to the methods declared in these two interfaces, this class also provides
simple versions of the lifecycle methods init and destroy, and implements the log method
declared in the ServletContext interface.
Note: This class is known as generic servlet, since it is not specific to any protocol.

10.What's the difference between GenericServlet and HttpServlet?


GenericServlet HttpServlet
The GenericServlet is an abstract class that is An abstract class that simplifies writing HTTP
extended by HttpServlet to servlets. It extends the GenericServlet base

Prepared by L.Maria Michael Visuwasam Page 38


CS8651 – INTERNET PROGRAMMING – PART A

class and provides an framework for handling


provide HTTP protocol-specific methods.
the HTTP protocol.
The GenericServlet does not include protocol-
The HttpServlet subclass passes generic
specific methods for handling request
service method requests to the relevant
parameters, cookies, sessions and setting
doGet() or doPost() method.
response headers.
HttpServlet only supports HTTP an HTTPS
GenericServlet is not specific to any protocol.
protocol.

11.What are the types of protocols supported by HttpServlet ?


It extends the GenericServlet base class and provides a framework for handling the HTTP
protocol. So, HttpServlet only supports HTTP and HTTPS protocol.

12.What is the difference between doGet() and doPost()?


# doGet() doPost()
In doPost(), on the other hand will (typically)
In doGet() the parameters are appended to
send the information through a socket back to
1 the URL and sent along with header
the webserver and it won't show up in the URL
information.
bar.
You can send much more information to the
The amount of information you can send server this way - and it's not restricted to
2 back using a GET is restricted as URLs can textual data either. It is possible to send files
only be 1024 characters. and even binary data such as serialized Java
objects!
doGet() is a request for information; it does doPost() provides information (such as placing
3 not (or should not) change anything on the an order for merchandise) that the server is
server. (doGet() should be idempotent) expected to remember
4 Parameters are not encrypted Parameters are encrypted
doPost() is generally used to update or post
doGet() is faster if we set the response
some information to the server.doPost is slower
5 content length since the same connection is
compared to doGet since doPost does not write
used. Thus increasing the performance
the content length
This method does not need to be idempotent.
doGet() should be idempotent. i.e. doget
Operations requested through POST can have
6 should be able to be repeated safely many
side effects for which the user can be held
times
accountable.
doGet() should be safe without any side
7 This method does not need to be either safe
effects for which user is held responsible

Prepared by L.Maria Michael Visuwasam Page 39


CS8651 – INTERNET PROGRAMMING – PART A

8 It allows bookmarks. It disallows bookmarks.

13.When to use doGet() and when doPost()?


Always prefer to use GET (As because GET is faster than POST), except mentioned in the
following reason:

 If data is sensitive
 Data is greater than 1024 characters
 If your application don't need bookmarks.

14.How do I support both GET and POST from the same Servlet?
The easy way is, just support POST, then have your doGet method call your doPost method:

public void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException
{
doPost(request, response);
}

15.How the typical servlet code look like ?

16.What is a servlet context object?


A servlet context object contains the information about the Web application of which the servlet
is a part. It also provides access to the resources common to all the servlets in the application.
Each Web application in a container has a single servlet context associated with it.

Prepared by L.Maria Michael Visuwasam Page 40


CS8651 – INTERNET PROGRAMMING – PART A

17.What are the differences between the ServletConfig interface and the ServletContext
interface?
ServletConfig ServletContext
The ServletConfig interface is implemented by
the servlet container in order to pass
A ServletContext defines a set of methods that a
configuration information to a servlet. The server
servlet uses to communicate with its servlet
passes an object that implements the
container.
ServletConfig interface to the servlet's init()
method.
There is one ServletContext for the entire
There is one ServletConfig parameter per servlet.
webapp and all the servlets in a webapp share it.
The param-value pairs for ServletConfig object The param-value pairs for ServletContext object
are specified in the <init-param> within the are specified in the <context-param> tags in the
<servlet> tags in the web.xml file web.xml file.

18.What is the directory structure of a WAR file?

19.What is a deployment descriptor?


A deployment descriptor is an XML document with an .xml extension. It defines a component's
deployment settings. It declares transaction attributes and security authorization for an enterprise
bean. The information provided by a deployment descriptor is declarative and therefore it can be
modified without changing the source code of a bean.
The JavaEE server reads the deployment descriptor at run time and acts upon the component
accordingly.

20.What is session?

Prepared by L.Maria Michael Visuwasam Page 41


CS8651 – INTERNET PROGRAMMING – PART A

A session refers to all the requests that a single client might make to a server in the course of
viewing any pages associated with a given application. Sessions are specific to both the
individual user and the application. As a result, every user of an application has a separate
session and has access to a separate set of session variables.

21.What is Session Tracking?


Session tracking is a mechanism that servlets use to maintain state about a series of requests from
the same user (that is, requests originating from the same browser) across some period of time.

22.What is the need of Session Tracking in web application?


HTTP is a stateless protocol i.e., every request is treated as new request. For web applications to
be more realistic they have to retain information across multiple requests. Such information
which is part of the application is reffered as "state". To keep track of this state we need session
tracking.

Typical example: Putting things one at a time into a shopping cart, then checking out--each page
request must somehow be associated with previous requests.

23.What are the types of Session Tracking ?


Sessions need to work with all web browsers and take into account the users security
preferences. Therefore there are a variety of ways to send and receive the identifier:

 URL rewriting : URL rewriting is a method of session tracking in which some extra data
(session ID) is appended at the end of each URL. This extra data identifies the session.
The server can associate this session identifier with the data it has stored about that
session. This method is used with browsers that do not support cookies or where the user
has disabled the cookies.

 Hidden Form Fields : Similar to URL rewriting. The server embeds new hidden fields in
every dynamically generated form page for the client. When the client submits the form
to the server the hidden fields identify the client.

Prepared by L.Maria Michael Visuwasam Page 42


CS8651 – INTERNET PROGRAMMING – PART A

 Cookies : Cookie is a small amount of information sent by a servlet to a Web browser.


Saved by the browser, and later sent back to the server in subsequent requests. A cookie
has a name, a single value, and optional attributes. A cookie's value can uniquely identify
a client.

 Secure Socket Layer (SSL) Sessions : Web browsers that support Secure Socket Layer
communication can use SSL's support via HTTPS for generating a unique session key as
part of the encrypted conversation.

24.How do I use cookies to store session state on the client?


In a servlet, the HttpServletResponse and HttpServletRequest objects passed to method
HttpServlet.service() can be used to create cookies on the client and use cookie information
transmitted during client requests. JSPs can also use cookies, in scriptlet code or, preferably,
from within custom tag code.

 To set a cookie on the client, use the addCookie() method in class HttpServletResponse.
Multiple cookies may be set for the same request, and a single cookie name may have
multiple values.
 To get all of the cookies associated with a single HTTP request, use the getCookies()
method of class HttpServletRequest

25.What are some advantages of storing session state in cookies?

 Cookies are usually persistent, so for low-security sites, user data that needs to be stored
long-term (such as a user ID, historical information, etc.) can be maintained easily with
no server interaction.
 For small- and medium-sized session data, the entire session data (instead of just the
session ID) can be kept in the cookie.

26.What are some disadvantages of storing session state in cookies?

 Cookies are controlled by programming a low-level API, which is more difficult to


implement than some other approaches.
 All data for a session are kept on the client. Corruption, expiration or purging of cookie
files can all result in incomplete, inconsistent, or missing information.
 Cookies may not be available for many reasons: the user may have disabled them, the
browser version may not support them, the browser may be behind a firewall that filters
cookies, and so on. Servlets and JSP pages that rely exclusively on cookies for client-side

Prepared by L.Maria Michael Visuwasam Page 43


CS8651 – INTERNET PROGRAMMING – PART A

session state will not operate properly for all clients. Using cookies, and then switching to
an alternate client-side session state strategy in cases where cookies aren't available,
complicates development and maintenance.
 Browser instances share cookies, so users cannot have multiple simultaneous sessions.
 Cookie-based solutions work only for HTTP clients. This is because cookies are a feature
of the HTTP protocol. Notice that the while package javax.servlet.http supports session
management (via class HttpSession), packagejavax.servlet has no such support.

27.What is URL rewriting?


URL rewriting is a method of session tracking in which some extra data is appended at the end of
each URL. This extra data identifies the session. The server can associate this session identifier
with the data it has stored about that session.
Every URL on the page must be encoded using method HttpServletResponse.encodeURL().
Each time a URL is output, the servlet passes the URL to encodeURL(), which encodes session
ID in the URL if the browser isn't accepting cookies, or if the session tracking is turned off.
E.g., http://abc/path/index.jsp;jsessionid=123465hfhs

Advantages

 URL rewriting works just about everywhere, especially when cookies are turned off.
 Multiple simultaneous sessions are possible for a single user. Session information is local
to each browser instance, since it's stored in URLs in each page being displayed. This
scheme isn't foolproof, though, since users can start a new browser instance using a URL
for an active session, and confuse the server by interacting with the same session through
two instances.
 Entirely static pages cannot be used with URL rewriting, since every link must be
dynamically written with the session state. It is possible to combine static and dynamic
content, using (for example) templating or server-side includes. This limitation is also a
barrier to integrating legacy web pages with newer, servlet-based pages.

DisAdvantages

 Every URL on a page which needs the session information must be rewritten each time a
page is served. Not only is this expensive computationally, but it can greatly increase
communication overhead.
 URL rewriting limits the client's interaction with the server to HTTP GETs, which can
result in awkward restrictions on the page.
 URL rewriting does not work well with JSP technology.

Prepared by L.Maria Michael Visuwasam Page 44


CS8651 – INTERNET PROGRAMMING – PART A

 If a client workstation crashes, all of the URLs (and therefore all of the data for that
session) are lost.

28.How can an existing session be invalidated?


An existing session can be invalidated in the following two ways:

 Setting timeout in the deployment descriptor: This can be done by specifying timeout
between the <session-timeout>tags as follows:

<session-config>
<session-timeout>10</session-timeout>
</session-config>
This will set the time for session timeout to be ten minutes.

 Setting timeout programmatically: This will set the timeout for a specific session. The
syntax for setting the timeout programmatically is as follows:

public void setMaxInactiveInterval(int interval)


The setMaxInactiveInterval() method sets the maximum time in seconds before a session
becomes invalid.
Note :Setting the inactive period as negative(-1), makes the container stop tracking
session, i.e, session never expires.

29. How can the session in Servlet can be destroyed?


An existing session can be destroyed in the following two ways:

 Programatically : Using session.invalidate() method, which makes the container abonden


the session on which the method is called.
 When the server itself is shutdown.

30. What are the functions of the Servlet container?


The functions of the Servlet container are as follows:

 Lifecycle management : It manages the life and death of a servlet, such as class loading,
instantiation, initialization, service, and making servlet instances eligible for garbage
collection.
 Communication support : It handles the communication between the servlet and the
Web server.
 Multithreading support : It automatically creates a new thread for every servlet request
received. When the Servlet service() method completes, the thread dies.

Prepared by L.Maria Michael Visuwasam Page 45


CS8651 – INTERNET PROGRAMMING – PART A

 Declarative security : It manages the security inside the XML deployment descriptor
file.
 JSP support : The container is responsible for converting JSPs to servlets and for
maintaining them.

JAVASERVER PAGES
1. Define Java Server Pages?
It can be defined as one instantiation of a class of related technologies that facilitate separate
development of a website’s presentation and logic. The key contribution of these technologies is
to embed program code related to presentation within a document.
2. What is a Scriplet?
A Scriplet is a fragment of java code that is embedded within the JSP document.
3. What are the drawbacks of two-step approach in JSP over direct interpretation?
1.Debugging
2.Delay during the first time a JSP document is requested.
4. Define a Web Application
To implement larger tasks, a large collection of resources such as Servlets,JSP documents,
Utility and Support Java Classes, Static HTML documents, Style Sheets, JavaScript files, Images
are needed that work together in order to provide what appears to an end user to be a single
software application.. Such a collection of resources is known as a web application.
5. Write the steps for installing a Web Application?
1.Create a directory under the webapps subdirectory.
2.Place the JSP document in the new subdirectory.
3.Deploy the application to the sever.
6. What is meant by deploying the application to the server?
During the installation of a web application, after loading the JSP document in the subdirectory,
the server have to be notified that a new web application is available. This step is known as
deploying the application to the server.
7. Define a Deployment Descriptor?
The value to be displayed in the Display Name field is one of the pieces of information that can
be associated with a web application through an XML document called a deployment descriptor.
8. Specify the use of the deployment descriptor element “login-config”?
It defines how the container should request user-name and password information when a user
attempts to access a protected resource.
9. How a URL pattern is interpreted?
When the server receives a request for a URL,it first selects the web application that will handle
this request. It chooses the application that has the longest context path matching a prefix of the
path portion of the URL.
10. Name the three types of information available in a valid JSP document?
1.JSP markup
2.Expression Language(EL)expressions
3.Template data
11. What are the two contexts by which an EL expression can be invoked?
1.Within template data
2.Within certain attribute values in JSP markup

Prepared by L.Maria Michael Visuwasam Page 46


CS8651 – INTERNET PROGRAMMING – PART A

12. What are the Literals that can be used in a EL?


1.The Booleans-True and False
2.Decimal,Integer and Floating point
3.Reserved word-Null
13. Name the reserved words in EL?
1.and
2.div
3.empty
4.eq
5.false
6.ge
7.gt
8.not
9.null
14. What is the function of EL implicit objects pageScope and requestScope?
pageScope-Values accessible via calls to page.getAttribute() requestScope- Values accessible via
calls to requestpage.getAttribute()
15. Name the two types of directives available for use in a JSP document?
1.Page-The page directive(directive. page element) has a variety of attributes that may be set.
2.Include-The include directive(directive. include element) imports text from another file into the
JSP document at the point at which the directive appears.
16. What is known as a Translation Unit?
A top-level JSP document plus all of the segments it includes either directly or indirectly through
include directives in segments is known as a translation unit, because the translator effectively
assembles all of the text from these files into a single JSP document which is then translated.
17. What are the three categories of JSP element types?
1.Scripting
2.Directive
3.Action
18. Explain the JSP action element?
It is an element that is translated into javaservlet code that performs some action. These elements
provide standard actions ie, the actions that are required by the JSP specification to be provided
by any JSP-compliant container. The JSP tag library mechanism allows additional action
elements to be used within a JSP document, which provide custom actions.
19. Give some JSTL Core actions and their functions.
 set-Assign a value to a scoped variable
 remove-Destroy a Scoped variable
 url-Create a URL with query string
 forEach-Iterate over a collection of items
20. Define a Scoped variable.
It is a non implicit EL variable, that is an attribute of one of the page ,request ,session,or
application objects. The object containing the attribute is called the scope of the variable and
hence the name scoped variable

UNIT IV
XML & PHP

Prepared by L.Maria Michael Visuwasam Page 47


CS8651 – INTERNET PROGRAMMING – PART A

1. What are the three major aspects to extend the enterprise from a constrained
network
to broad reach of web?
1. Business-to-Consumer (B2C) Connection.
2. Business-to-Employee (B2E) Connection.
3. Business-to-Business (B2B) Connection.

2. What are the three key design elements that by omission contribute XML’s success?
1. No display is assumed.
2. There is no built-in data typing.
3. No transport is assumed.XML specification makes no aassumption about how XML
is transported across the Internet.

3. XML History
XML is a meta language defined by world wide web consortium (W3C) and
standardized in 1998.XML has given rise to numerous vertical industry vocabularies in
support of B2B e-commerce, horizontal vocabularies that provide service to a wide range
of industries and XML protocols that have used XML’s simple power of combination to
open up new possibilities for doing distributed computing.

4. What are the different revolution in which XML is playing a major role?
a)Data revolution
b)Architectural revolution
c)Software revolution

5. What are the advantages of xml? [NOV/DEC 2013]


a.xml files are human readable.
b.Widespread industry support exists for xml due to its inexpensiveness and convenience in
usage.
c.It provides a way of creating domain specific vocabulary.
d.It allows data interchange between different computers.
e.It provides user selected view of data.

Define Valid XML Documents


• A "Valid" XML document also conforms to a DTD.
• A "Valid" XML document is a "Well Formed" XML document, which also conforms to the rules
of a Document Type Definition (DTD).

7.What is W3c (World Wide Web)Consortium?


W3c is responsible for the development of web specifications that describe
communication protocols and technologies for the web .XML was defined by w3c to
ensure that structured data is uniform and independent of vendors
of applications.W3c has laid down certain rules that meet to be followed by the all xml
applications.Some of these rules are:
a.XML must be directly usable over the internet.
b.XMl must support the wide variety of applications. c.XML must be SGML.

Prepared by L.Maria Michael Visuwasam Page 48


CS8651 – INTERNET PROGRAMMING – PART A

d.XML documents must be human legible and clear.


e.XML design must be formal and concise.

What is XML?
XML is a set of rules for structuring, storing and transferring information. This language is used
to describe the data which will be passed from one computer application to another. XML tells a
computer what the actual data is, not what it should look like.
2. What is the main disadvantage of HTML?
The main disadvantage was that it was not designed to share information between computers,
and so XML was developed to overcome this limitation.
3. What are the uses of XML?
· Connecting databases to the Web; Exchanging data automatically between different computer
applications;
· Moving the processing from a Web server to the local PC;
· Using the same information in many different ways;
· Changing the presentation of information automatically for different viewing devices.
4. What is the emergence of XML?
· XLINK - a standard designed to hyperlink between XML documents;
· XML Query - a language used to query XML documents;
· XSL - a style sheet language for XML;
· Resource Description Framework (RDF) - a standard for metadata. This will be similar to
library cards and should make searching the Web much faster
5. What are the major XML news formats?
The major XMLNews formats are XMLNews-Story and XMLNews-Meta,
6. What are markup and text in an XML document?
XML documents mix markup and text together into a single file: the markup describes the
structure of the document, while the text is the documents content
7. Write the rules of XML declaration
· The XML declaration is case sensitive: it may not begin with “<?XML” or any other variant;
· If the XML declaration appears at all, it must be the very first thing in the XML document: not
even white space or comments may appear before it; and
· It is legal for a transfer protocol like HTTP to override the encoding value that you put in the
XML declaration, so you cannot guarantee that the document will actually use the encoding
provided in the XML declaration.
8. Write the rules of XML element
Elements may not overlap: an end tag must always have the same name as the most recent
unmatched start tag. The following example is not well-formed XML, because “</person>”
appears when the most recent unmatched start tag was “<function>”:
b. <!-- WRONG! -->
c. <function><person>President</function> Habibe</person>
9. Write on Attributes
XML start tags also provide a place to specify attributes. An attribute specifies a single property
for an element, using a name/value pair. One very well known example of an attribute is href in
HTML:
<a href=\"http://www.yahoo.com/\">Yahoo!</a>
10. What are the revolutions of XML?

Prepared by L.Maria Michael Visuwasam Page 49


CS8651 – INTERNET PROGRAMMING – PART A

1. Data Revolution
2. Architectural Revolution
3. Software Revolution
Write on Tags and elements?
XML tags begin with the less-than character (“<”) and end with the greater-than character (“>”).
You use tags to mark the start and end of elements, which are the logical units of information in
an XML document, an element consists of a start tag, possibly followed by text and other
complete elements, followed by an end tag.
16. What are attribute name and attribute value?
Every attribute assignment consists of two parts: the attribute name (for example, href), and
the attribute value (for example, http://www.yahoo.com/). There are a few rules to remember
about XML attributes:
1. Attribute names in XML (unlike HTML) are case sensitive: HREF and href refer to two
different
XML attributes.
2. You may not provide two values for the same attribute in the same start tag. The following
example is not well-formed because the b attribute is specified twice:
17. What are the uses of XML?
XML is used in many aspects of web development, often to simplify data storage and sharing.
18. What are the various features of XML?
· Security
· Portability
· Scalability
· Reliability
19. Different between XML and HTML
1. XML is not a replacement for HTML.
2. XML and HTML were designed with different goals:
3. XML was designed to transport and store data, with focus on what data is.
1. HTML was designed to display data, with focus on how data looks.
2. HTML is about displaying information, while XML is about carrying information.
20. What are the three waves for XML development?
· Vertical Industry Vocabularies
· Horizontal Industry Applications
· Protocols
21. List out the advantages of XML.
· XML files are human - readable
· Widespread industry support
· Relational Databases
· XML support technologies
· More meaningful searches
· Development of flexible web applications
· Data integration from disparate sources
· Local computation and manipulation of data
· Multiple views of the data
· Granular updates
22. List out the XML structure.

Prepared by L.Maria Michael Visuwasam Page 50


CS8651 – INTERNET PROGRAMMING – PART A

· Physical structure
· Logical structure
23. What is physical structure?
The physical structure consists of the contents used in an XML document. It holds the actual data
to be represented in an XML document. This actual data storage can be called as Entities. These
entities are identified by a unique name and may be part of the XML document or external to the
document.
An entity is declared in the XML declaration part and referenced in the document element. Once
declared in the DTD, an entity can be used anywhere.
24. List out the Physical structure.
· Parsed Entity
· Unparsed Entity
· Entity Reference
· Predefines Entities
· Internal and External Entities
· XML Syntax
· Attributes
25. What is XML declaration?
It identifies the version of the XML specification to which the document conforms.
Example:
<?xml version=”1.0”?>
An XML declaration can also include an
· Encoding Declaration
· Stand-alone Document Declaration

HTML- it was designed as language to present hyperlinked, formatted information in a web


browser. It is indented for consumption by humans
XML – it has the capability to represent metadata, provide validation, support extensibility by
user, even basic needs of business. It is indented for consumption by both machine and humans.

26. What is Encoding?


· The encoding declaration decides the encoding scheme. The encoding schemes available are
UTF-8 and EUC-JP.· The coding schemes map to different character formats or languages.

27. What is standalone declaration?


· The stand-alone document declaration identifies whether any markup declarations exits that are
external to the document.This declaration can take in values of yes or no.

28. Define Document Type Declaration


Defines the legal building blocks of an XML document. It defines the document structure with a
list of legal elements and attributes.
A DTD can be declared inline inside an XML document, or as an external reference.
The document type declaration consists of the markup codes or the DTD according to which the
XML document has to be written.
The document type declaration can also point to an external file that contains the DTD. The
document type declaration follows the XML declaration.

Prepared by L.Maria Michael Visuwasam Page 51


CS8651 – INTERNET PROGRAMMING – PART A

Example:
<?xml version=”1.0”?>
<!DOCTYPE lib SYSTEM “lib.dtd”>

Why we Use a DTD?


With a DTD, each of the XML files can carry a description of its own format. With a DTD,
independent groups of people can agree to use a standard DTD for interchanging data. The
application can use a standard DTD to verify that the data received from the outside world is
valid.

Define XML Schema.


XML Schema is an XML-based alternative to DTDs. An XML Schema describes the structure of
an XML document. The XML Schema language is also referred to as XML Schema Definition
(XSD).

29. List out the various logical structure of an XML document.


The various logical structures of an XML document are:
· Elements
· Attributes
· Entities

30. Define Elements


Element are the primary means for describing data in XML. The rules for composing elements
are
· Flexible
· Allowing different combinations of text content, attributes and other elements.

What is DOM? What are the different levels of DOM?

DOM is a W3C supported standard programming interface(API)that provides a platform and


neutral interface to allow developers to programatically access and modify content and structure
of tree structured documents such as HTML or XML.

The different levels of DOM are:


(a) DOM Level 0
(b) DOM Level 1
(c) DOM Level 2
(d) DOM Level 3

List out the reasons for not using attributes to store data.
1.Attributes cannot contain multiple values,while elements can have multiple
subelements.
2.Attributes are not easily expandable to account for future changes.
3.Attributes are more difficult than elements to manipulate with programs.
4.Attributes values are not easy to check against a document type definition.

Prepared by L.Maria Michael Visuwasam Page 52


CS8651 – INTERNET PROGRAMMING – PART A

What are entities? Give Example.


Entities are used to create substitution strings within a xml document
Example:
Xml and data evaluation can be defined with short string using entity declaration in DTD.
<!ENTITYxdr “XML AND DATA REVOLUTION”>

What are all the xml language basics?


• Elements
• Attributes
• Entities

What are the Element Naming Rules used in XML?


Names can contain letters, numbers and other characters.
Names must not begin with number or punctuation.
Names must not start with the string "xml" in any upper or lowercase form.
Names must not contain spaces

What are the advantages of schema over DTD?

 It provides more control over the type of data that can be assigned to elements and as
compared to DTD.
 DTD dose not enable you to define your own customized datatypes. But schema
definition enables you to create your own datatypes.
 It also allows to specify restrictions on data.
 The syntax for defining DTD is different from the syntax used for creating an xml
document .But the syntax for defining XSD is the same as the syntax of an xml
document.

What are the datatypes in an xml schema?

1.Primitive
2.Derived
3.Atomic
4.List
5.Union

What are the drawbacks of CSS?

The browser decides how to dispaly elements that the stylesheetdoes'nt describe.
As browser implements CSS,some implementations may not always be consistent.

Write any two differences between XSLT and CSS?

XSLT CSS
1. Simple to use,and is suitable for simple 1. It is complex to use.

Prepared by L.Maria Michael Visuwasam Page 53


CS8651 – INTERNET PROGRAMMING – PART A

document.

2. Cannot reorder,add,delete because it is 2.Can reorder, add, delete perform operations


elements. on elements aware of the structure of an XML
document.

6. What are the different XSLT elements?

1. Stylesheet
2. Value-of
3. For-each
4. Sort
5. Text

What all are the presentation technologies? [NOV/DEC 2011]


CSS - cascading syle sheets
XSL - provides users with ability to describe how xml data & document are to be formated.
Xforms - it is a GUI toolkit for creating user interfaces & delivering the results in XML.
Xhtml - it is used yo replace HTML with more flexable approach to display webcontent.
VoiceXML - it is an emerging standard for speech enabled application.

What is DTD? How is it different from Schema?


DTD stands for Document Type Definition
DTD is a description of the structure & the elements and attributes that define a class of XML
document.
DTD can be declared both internally in a XML document and as an external reference.

What is XML? How it is different from HTML?


Xml is the text based make up language that stores the data in a structured format using
meaningful tags. It allows computers to store and exchange data in a format that can be
interpreted by any other computer with different hardware or software specification.
XML HTML
Extensible Markup Language Hyper Text Markup Language
Several Languages are derived from XML HTML can be derived from XML
XML uses indefinite, user defined, meaningful HTML uses a fixed set of tags, which can be
set of tags which can be used to include XML used to specify the appearance of the web page.

Prepared by L.Maria Michael Visuwasam Page 54


CS8651 – INTERNET PROGRAMMING – PART A

data in the web page.


No restriction to use elements There is restriction to use elements.

What is XSLT?
 XSLT stands for XSL Transformations
 XSLT is the most important part of XSL
 XSLT transforms an XML document into another XML document
 XSLT uses XPath to navigate in XML documents
 XSLT is a W3C Recommendation

What is XSL Programming?


XSL (XML Stylesheet) Programming is the Next Generation of the CSS (Cascading Style Sheet
Programming). In CSS, users can use certain style tags which the browsers can understand and
are predefined by W3 consortium. XSL takes ths to one step ahead and users can define any tags
in the XML file. XML sheets can help in showing the same data in different formats.

What is RSS?
 Really Simple Syndication (RSS) is a lightweight XML format designed for sharing headlines
and other Web content
 RSS defines an XML grammar (a set of HTML-like tags) for sharing news.Each story is
defined by an tag, which contains a headline TITLE, URL, and DESCRIPTION

PHP

1. What is PHP?
PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers
to create dynamic content that interacts with databases. PHP is basically used for developing
web based software applications

2. What is the use of "echo" in php?


It is used to print a data in the webpage, Example: <?php echo 'Car insurance'; ?> , The
following code print the text in the webpage

3. Differences between GET and POST methods ?


We can send 1024 bytes using GET method but POST method can transfer large amount of
data and POST is the secure method than GET method .

4. How to declare an array in php?


Eg :var $arr = array('apple', 'grape', 'lemon');

5. What is the use of 'print' in php?


This is not actually a real function, It is a language construct. So you can use without
parentheses with its argument list.
Example print('PHP Interview questions');
print 'Job Interview ');

Prepared by L.Maria Michael Visuwasam Page 55


CS8651 – INTERNET PROGRAMMING – PART A

6. What is use of in_array() function in php ?


in_array used to checks if a value exists in an array

7. What is use of count() function in php ?


count() is used to count all elements in an array, or something in an object

8. What is the difference between Session and Cookie?


The main difference between sessions and cookies is that sessions are stored on the server,
and cookies are stored on the user’s computers in the text file format. Cookies can not hold
multiple variables,But Session can hold multiple variables.We can set expiry for a cookie,The
session only remains active as long as the browser is open.Users do not have access to the
data you stored in Session,Since it is stored in the server.Session is mainly used for
login/logout purpose while cookies using for user activity tracking

9. How to set cookies in PHP?


Setcookie("sample", "ram", time()+3600);

10. How to Retrieve a Cookie Value?


eg : echo $_COOKIE["user"];

11. How to create a session? How to set a value in session ? How to Remove data from a
session?
Create session : session_start();
Set value into session : $_SESSION['USER_ID']=1;
Remove data from a session : unset($_SESSION['USER_ID'];

12. what types of loops exist in php?


for,while,do while and foreach (NB: You should learn its usage)

13. How to create a mysql connection?


mysql_connect(servername,username,password);

14. How to select a database?


mysql_select_db($db_name);
15. How to execute ansql query? How to fetch its result ?
$my_qry = mysql_query("SELECT * FROM `users` WHERE `u_id`='1'; ");
$result = mysql_fetch_array($my_qry);
echo $result['First_name'];

16. Write a program using while loop


$my_qry = mysql_query("SELECT * FROM `users` WHERE `u_id`='1'; ");
while($result = mysql_fetch_array($my_qry))
{
echo $result['First_name'.]."<br/>";
}

Prepared by L.Maria Michael Visuwasam Page 56


CS8651 – INTERNET PROGRAMMING – PART A

17. How we can retrieve the data in the result set of MySQL using PHP?
o 1. mysql_fetch_row
o 2. mysql_fetch_array
o 3. mysql_fetch_object
o 4. mysql_fetch_assoc

18. What is the difference between explode() and split() functions?


Split function splits string into array by regular expression. Explode splits a string into array
by string.

19. How to strip whitespace (or other characters) from the beginning and end of a string
?
The trim() function removes whitespaces or other predefined characters from both sides of a
string.

20. What is the use of header() function in php ?


The header() function sends a raw HTTP header to a client browser.Remember that this
function must be called before sending the actual out put.For example, You do not print any
HTML element before using this function.

21. How to redirect a page in php?


The following code can be used for it, header("Location:index.php");

22. How stop the execution of a phpscrip ?


exit() function is used to stop the execution of a page

23. How to set a page as a home page in a php based site ?


index.php is the default name of the home page in php based sites

24. How to find the length of a string?


strlen() function used to find the length of a string

25. what is the use of rand() in php?


It is used to generate random numbers.If called without the arguments it returns a pseudo-
random integer between 0 and getrandmax(). If you want a random number between 6 and 12
(inclusive), for example, use rand(6, 12).This function does not generate cryptographically
safe values, and should not be used for cryptographic uses. If you want a cryptographically
secure value, consider using openssl_random_pseudo_bytes() instead.

26. what is the use of isset() in php?


This function is used to determine if a variable is set and is not NULL

27. What is the difference between mysql_fetch_array() and mysql_fetch_assoc() ?


mysql_fetch_assoc function Fetch a result row as an associative array,
Whilemysql_fetch_array() fetches an associative array, a numeric array, or both

Prepared by L.Maria Michael Visuwasam Page 57


CS8651 – INTERNET PROGRAMMING – PART A

28. What is mean by an associative array?


Associative arrays are arrays that use string keys is called associative arrays.

29. What is the importance of "method" attribute in a html form?


"method" attribute determines how to send the form-data into the server.There are two
methods, get and post. The default method is get.This sends the form information by
appending it on the URL.Information sent from a form with the POSTmethod is invisible to
others and has no limits on the amount of information to send.

30. What is the importance of "action" attribute in a html form?


The action attribute determines where to send the form-data in the form submission.

31. How do you define a constant?


Using define() directive, like define ("MYCONSTANT",150)

32. How send email using php?


To send email using PHP, you use the mail() function.This mail() function accepts 5
parameters as follows (the last 2 are optional). You need webserver, you can't send email
from localhost. eg : mail($to,$subject,$message,$headers);

33. How to find current date and time?


The date() function provides you with a means of retrieving the current date and time,
applying the format integer parameters indicated in your script to the timestamp provided or
the current local time if no timestamp is given. In simplified terms, passing a time parameter
is optional - if you don't, the current timestamp will be used.

34. Difference between mysql_connect and mysql_pconnect?


There is a good page in the php manual on the subject, in short mysql_pconnect() makes a
persistent connection to the database which means a SQL link that do not close when the
execution of your script ends. mysql_connect()provides only for the databasenewconnection
while using mysql_pconnect , the function would first try to find a (persistent) link that's
already open with the same host, username and password. If one is found, an identifier for it
will be returned instead of opening a new connection... the connection to the SQL server will
not be closed when the execution of the script ends. Instead, the link will remain open for
future use.

35. What is the use of "ksort" in php?


It is used for sort an array by key in reverse order.

36. What is the difference between $var and $$var?


They are both variables. But $var is a variable with a fixed name. $$var is a variable who's
name is stored in $var. For example, if $var contains "message", $$var is the same as
$message.

Prepared by L.Maria Michael Visuwasam Page 58


CS8651 – INTERNET PROGRAMMING – PART A

37. What are the differences between mysql_fetch_array(), mysql_fetch_object(),


mysql_fetch_row()?
o Mysql_fetch_array Fetch a result row as an associative array, a numeric array, or
both.
o mysql_fetch_object( resource result ) Returns an object with properties that
correspond to the fetched row and moves the internal data pointer ahead. Returns an object
with properties that correspond to the fetched row, or FALSE if there are no more rows
o mysql_fetch_row() fetches one row of data from the result associated with the
specified result identifier. The row is returned as an array. Each result column is stored in an
array offset, starting at offset 0.
o
38. How to find the position of the first occurrence of a substring in a string
strpos() is used to find the position of the first occurrence of a substring in a string

UNIT V
AJAX
Define AJAX.
AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating
better, faster, and more interactive web applications with the help of XML, HTML, CSS, and
Java Script.
 Ajax uses XHTML for content, CSS for presentation, along with Document Object
Model and JavaScript for dynamic content display.
 Conventional web applications transmit information to and from the sever using
synchronous requests. It means you fill out a form, hit submit, and get directed to a new
page with new information from the server.
Define XMLHttpRequest.
JavaScript object that performs asynchronous interaction with the server.
XMLHttpRequest (XHR) is an API that can be used by JavaScript, JScript, VBScript, and other
web browser scripting languages to transfer and manipulate XML data to and from a webserver
using HTTP, establishing an independent connection channel between a webpage's Client-Side
and Server-Side.
Name some XMLHttpRequest methods.

 abort()

Cancels the current request.

 getAllResponseHeaders()

Returns the complete set of HTTP headers as a string.

 getResponseHeader( headerName )

Returns the value of the specified HTTP header.

Prepared by L.Maria Michael Visuwasam Page 59


CS8651 – INTERNET PROGRAMMING – PART A

 open( method, URL )

open( method, URL, async )


open( method, URL, async, userName )
open( method, URL, async, userName, password )

 send( content )

Name some XMLHttpRequest Properties

 onreadystatechange

An event handler for an event that fires at every state change.

 readyState

The readyState property defines the current state of the XMLHttpRequest object.
How to create an XMLHttpRequest object?
variable=new XMLHttpRequest();

Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:
variable=new ActiveXObject("Microsoft.XMLHTTP");

How AJAX works?

AJAX allows you to send and receive data asynchronously without reloading the web page. So it
is fast.AJAX allows you to send only important information to the server not the entire page. So
only valuable data from the client side is routed to the server side. It makes your application
interactive and faster.
What areSynchronous& Asynchronous Model?

Synchronous (Classic Web-Application Model)

A synchronous request blocks the client until operation completes i.e. browser is not
unresponsive. In such case, javascript engine of the browser is blocked.

Asynchronous (AJAX Web-Application Model)

An asynchronous request doesn’t block the client i.e. browser is responsive. At that time, user
can perform another operations also. In such case, javascript engine of the browser is not
blocked.
Draw the client-server architecture of AJAX.

Prepared by L.Maria Michael Visuwasam Page 60


CS8651 – INTERNET PROGRAMMING – PART A

What are the approaches for making a Web service request?

 Call Web services by using the HTTP POST verb.


 Call Web services by using the HTTP GET verb.

Name some callback functions in AJAX.


Methods Description

ajaxComplete( callback ) Attach a function to be executed whenever an AJAX request


completes.
ajaxStart( callback ) Attach a function to be executed whenever an AJAX request begins
and there is none already active.
ajaxError( callback ) Attach a function to be executed whenever an AJAX request fails.

ajaxSend( callback ) Attach a function to be executed before an AJAX request is sent.

ajaxStop( callback ) Attach a function to be executed whenever all AJAX requests have
ended
ajaxSuccess( callback ) Attach a function to be executed whenever an AJAX request
completes successfully

WEBSERVICES

Prepared by L.Maria Michael Visuwasam Page 61


CS8651 – INTERNET PROGRAMMING – PART A

1. Define Web services


A Web service (also Web Service, Web service) is defined by the W3C as a software system
designed to support interoperable machine-to-machine .Web Services is the umbrella term of
group of loosely related Web-based resources and components that may be used by other Web.

2. List out the characteristic of Web services.


 XML based everywhere
 Message-based
 Programming language independent
 Could be dynamically located
 Could be dynamically assembled or aggregated
 Accessed over the internet
 Loosely coupled
 Based on industry standards
 Are platform neutral
 Are accessible in a standard way
 Are accessible in an interoperable way
 Use simple and ubiquitous plumbing
 Are relatively cheap
 Simplify enterprise integration

3. What are the uses of Web services?


 Interoperable – Connect across heterogeneous networks using ubiquitous web-based
standards
 Economical – Recycle components, no installation and tight integration of software
 Automatic – No human intervention required even for highly complex transactions
 Accessible – Legacy assets & internal apps are exposed and accessible on the web.
 Available – Services on any device, anywhere, anytime
 Scalable – No limits on scope of applications and amount of heterogeneous
applications

4. What are the three roles of Web service? The three role of web service are
 Client
 Service
 Broker.

5. Define client
A client is any computer that accesses functions from one or more other computing nodes on the
network. Typical clients include desktop computers, Web browsers, Java applets, and mobile
devices. A client process makes a request for a computing service and receives results for that
request.

6. Define Service

Prepared by L.Maria Michael Visuwasam Page 62


CS8651 – INTERNET PROGRAMMING – PART A

A service is a computing process that receives and responds to requests and returns a set of
results.

7. Define Broker
A broker is essentially a service metadata portal for registering and discovering services. Any
network client can search the portal for an appropriate service.

8. What are the standard protocols used in web service?


The standard protocols used in web service
 WSDL
 UDDL
9. What are the risks in Web Services?
 Maturity: Different implementation may not work together.
 Security: SOAP messages on port 80 bypass firewalls. So networkadministrator has to
implement necessary security to prevent attacks.
 Transaction: Transaction must be specified outside the web servicesframework such as
.NET or J2EE.
 Configuration Management: Change management is not addressed.

10. List out the advantage of Web services technology?


 Decide on the service it wants to provide
 Pick a registry for uploading it‘s information
 Decide how to list its service at the registry
 Define explicitly how users can connect to its service

11. What are the major aspects of Web service technologies?


 A service provider provides an interface for software that can carry out a specified set of
tasks.
 A service requester discovers and invokes a software service to provide business solution.
 A repository or broker manages and publishes the service. Service providers publish their
services with the broker, and requests access those services by creating bindings to the
service provider.

12. What is SOAP?


SOAP, to put it simply, allows Java objects and COM objects to talk to each other in a
distributed, decentralized, Web-based environment. More generally, SOAP allows objects (or
code) of any kind -- on any platform, in any language -- to cross-communicate. At present, SOAP
has been implemented in over 60 languages on over 20 platforms.
 SOAP stands for Simple Object Access Protocol
 SOAP is a communication protocol
 SOAP is for communication between applications
 SOAP is a format for sending messages
 SOAP communicates via Internet

13. Write on SOAP msg format

Prepared by L.Maria Michael Visuwasam Page 63


CS8651 – INTERNET PROGRAMMING – PART A

SOAP does all this in the context of a standardized message format. The primary part of this
message has a MIME type of \"text/xml\" and contains the SOAP envelope. This envelope is an
XML document. The envelope contains a header (optional) and a body (mandatory). The body
part of the envelope is always intended for the final recipient of the message, while the header
entries may target the nodes that perform intermediate processing. Attachments, binary or
otherwise, may be appended to the body.

14. What are the building blocks of SOAP?


A SOAP message is an ordinary XML document containing the following elements:
 An Envelope element that identifies the XML document as a SOAP message
 A Header element that contains header information
 A Body element that contains call and response information
 A Fault element containing errors and status information

15. How are input parameters is handled?


Input parameters are handled in the following ways:
 If a SOAP method requires an input parameter, and this parameter is not included in the
SOAP request, no value is passed to the called stored procedure. The default action
defined in the stored procedure occurs.
 If a SOAP method requires an input parameter, and this parameter is included in the
request but no value is assigned to it, the parameter is passed to the stored procedure with
an empty string as its value. Note that it is not NULL.
 If a SOAP operation requires an input parameter and if you want to send a NULL value
for this parameter, you must set an xsi:nil attribute to \"true\" in the SOAP request

16. What is SOAP header element?


The optional SOAP Header element contains application specific information (like
authentication, payment, etc) about the SOAP message. If the Header element is present, it must
be the first child element of the Envelope element.

17. Define SOAP body Element?


SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the
message. Immediate child elements of the SOAP Body element may be namespace-qualified.
SOAP defines one element inside the Body element in the default namespace
(\"http://www.w3.org/2001/12/soap-envelope\"). This is the SOAP Fault element, which is used
to indicate error messages. List out the Sub element of SOAP fault
 Faultcode
 Faultstring
 Faultactor

18. Define the important syntax rules.


A SOAP message MUST be encoded using XML
A SOAP message MUST use the SOAP Envelope namespace
A SOAP message MUST use the SOAP Encoding namespace
A SOAP message must NOT contain a DTD reference
A SOAP message must NOT contain XML Processing Instructions

Prepared by L.Maria Michael Visuwasam Page 64


CS8651 – INTERNET PROGRAMMING – PART A

19. Define SOAP Envelop Element.


SOAP Envelope element is the root element of a SOAP message. It defines the XML document
as a SOAP message.

20. Define WSDL


WSDL stands for Web Services Description Language. WSDL is a document written in XML.
The document describes a Web service. It specifies the location of the service and the operations
(or methods) the service exposes.

21. What are the major elements used in WSDL?


The major elements used in WSDL are
 PortType
 Message
 Types
 Binding

22. Define the structure of WSDL


<definitions>
<types> definition of types........ </types>
<message> definition of a message.... </message>
<portType> definition of a port....... </portType>
<binding> definition of a binding.... </binding>
</definitions>

Prepared by L.Maria Michael Visuwasam Page 65

S-ar putea să vă placă și