String Handling in Java


Generics


Swing layout management

Java IO Streams

Web Programming FAQ


Mention the benefits of JavaScript.

JavaScript is primarily a client-side language. Advantages of JavaScript are
Simple and versatile – can be used with other languages and in a huge variety of applications
Speed – code functions can be run immediately in client machine instead of having to contact the server and wait for an answer.
Reduces Server Load

What is a session? What is session management and why it is required?

Session is an interval of time during which a connection exists between a server and a client. The state of the client is maintained at the server during the session and since http is a stateless protocol the state information does not persist when the connection is terminated.

Session management also called as session tracking is a way to maintain state (data) of an user across multiple sessions. There are four techniques used in Session tracking:
Cookies
Hidden Form Field
URL Rewriting
HttpSession



Define RMI.

RMI is remote Method Invocation. RMI allows remote communication and is used to build distributed applications in Java. RMI allows a Java object residing in one machine to invoke a method which resides in another (Remote) machine.



What are stub and skeletons?

Stub is a Java object that resides on the client machine. Its function is to provide the same interface as the remote server. A skeleton is a Java object that resides on the server machine. It receives request performs serialization and invokes the appropriate code on the server.

What is the function of bind(), rebind() and lookup() methods?

bind() – register an object and name in RMI registry
     rebind() – modify the existing registered object.
lookup() – search for an object using name.



Define marshalling and unmarshalling.

Marshalling is the process of converting data or object into a byte stream. The reverse process of converting the byte stream into original data or object is called as unmarshalling. The conversion is achieved through serialization.



What is the use of 'param' variable in JSP?

‘param’ is one of the implicit objects in JSP. It maps the request parameter to a single value. Example
<jsp:param name=”first_name” value=”xyz”/>



What are the types of directives in JSP?

Types of directive tags
page directive – defines page dependent attributes example the scripting language used by the JSP
include directive – include file in the JSP during the translation page
taglib directive – allows to create user define tags that implement custom behavior



List any 4 taglib directives available in JSP and their use.

Tag library contains a set of user defined tags that implement custom behavior. The taglib directive declares that JSP page uses a set of custom tags, identifies the location of the library and provides a means of identifying the custom tags in the JSP page.



Differentiate Http and generic servlet

GenericServlet
HttpServlet
Abstract class
Abstract class
Direct subclass of servlet class
Direct subclass of GeneriServlet class
Defines a generic protocol independent servlet – It handles all types  of protocol  like http, smtp, ftp etc.
Defines a HTTP protocol specific servlet – It handles only http protocol.




What is namespaces in XML? Give an example.
What are Namespaces? Why is it useful? Explain with an example.
Justify the need for namespaces in XML.

In XML, element names are defined by the developer. This often results in a conflict when trying to use XML documents from different applications together. XML Namespace is used to avoid element name conflict in XML documents. It provide a means for document authors to unambiguously refer to elements with the same name (i.e., prevent collisions).

For example,
<subject>Geometry</subject>       and
<subject>Cardiology</subject>
use element subject to mark up data.
In the first case, the subject is something one studies in school, whereas in the second case, the subject is a field of medicine.
Namespaces can differentiate these two subject elements—for example:
<highschool:subject>Geometry</highschool:subject>               and
<medicalschool:subject>Cardiology</medicalschool:subject>



What is XML Parser?

An XML parser is a software library or package that provides interface for client applications to work with an XML document.
It is designed to read XML document and create a way for programs to use the XML
It validates the documents and checks if the document is well formed.



State the function of DTD.

Document Type Definition (DTD) is used to define the structure of an XML document. It contains a list of legal elements and defines the structure with the help of them. It can also be used to define special characters and character strings used in the document.



Explain the use of DTD for structuring the XML document.
What are the benefits of using XML Schema?
State the differences between XML Schema and DTD.
Compare DTD and XML schema.

Both DTD and XML schema provides the basic structure for defining a XML document. In addition XML schema also provides methods to define constraints on the data contained in the document. XML schema is considered to be richer and more powerful than DTD.

Drawback in DTD

DTDs are not flexible enough to meet today’s programming needs. For example, DTDs lack a way of indicating what specific type of data (e.g., numeric, text) an element can contain,
DTDs are not themselves XML documents, forcing developers to learn multiple grammars and developers to create multiple types of parsers.

Unlike DTDs, schemas do not use EBNF grammar. Instead, they use XML syntax and are actually XML documents that programs can manipulate. Like DTDs, schemas are used by validating parsers to validate documents.



Advantage of using Schemas over DTD
It is easier to describe document content
It is easier to define restrictions on data
It is easier to validate the correctness of data
It is easier to convert data between different data types



What is the function of XSLT?
What is the use of XSLT?
eXtensible Stylesheet Language Transformation (XSLT) is used to transform an XML document into other type of document like HTML. With XSLT we ca add / remove elements and attributes to or from an output file. We can also rearrange and sort elements, perform tests and make decisions about which element to hide, display etc.



What are the various transformation technologies?

XSL Transformations (XSLT) – is a technology for transforming XML documents into other documents – i.e., transforming the structure of the XML document data to another structure.

XSLT provides elements that define rules for transforming one XML document to produce a different XML document. Transforming an XML document using XSLT involves two tree structures – the source tree (XML document to transform) and the result tree (XML document to create).

To perform transformations, an XSLT processor is required. Popular XSLT processors include Microsoft’s MSXML and the Apache Software Foundation’s Xalan 2 (xml.apache.org).



What are presentation technologies of XML? Explain each one briefly.

Extensible Stylesheet Language (XSL) documents specify how programs are to render XML document data.  XSL is a group of three technologies—XSL-FO (XSL Formatting Objects), XPath (XML Path Language) and XSLT (XSL Transformations).

XSL-FO is a vocabulary for specifying formatting

XPath is a string-based language of expressions used by XML and many of its related technologies for effectively and efficiently locating structures and data (such as specific elements and attributes) in XML documents.

XSL Transformations (XSLT) – is a technology for transforming XML documents into other documents – i.e., transforming the structure of the XML document data to another structure.



What is Xpath?

Xpath is syntax for defining path of a XML document. Xpath uses a string-based language of expressions to navigate in XML documents. It is used for effectively and efficiently locating structures and data (such as specific elements and attributes) in XML documents



What is XSL and why is it used?

eXtensible Stylesheet Language (XSL) is used for expressing stylesheets in XML. An XSL is a file that describes how to display an XML document of a given type.




Java FAQ



What is Java Virtual Machine? State its purpose.        (Or)
Is Java platform independent? Justify.                          (Or)
How is a Java bytecode interpreted?                              (Or)
What is the need for bytecode generation?

A programming language is said to be platform independent if it can create an application program that can be executed on any platform. Java Virtual Machine (JVM) provides platform independence to Java.
When a Java program is compiled it generates a bytecode file. The JVM is available with all operating systems and can be installed in any host machine. It takes the bytecode file as an input, interprets it generates an output corresponding to the underlying platform (OS) of the host machine and then executes it. Hence Java is platform independent.




Differentiate static binding and dynamic binding.

Static binding
Dynamic binding
Also called early binding
Also called a slate binding
Binding happens at compile time
Binding happens at run time.
Actual object is not used for binding
Actual object used for binding


What is the use of ‘extends’ keyword?

‘extends’ keyword is used in inheritance in Java. It allows the public and protected variables and methods of the super class to be inherited by the subclass.
Example:
          class A
          {
          }
          class B extends A
{
}


What is static in Java?

Static is a keyword in Java used with variables, methods and block of code. Static belongs to the class and not the object. It has only one instance and is shared by all the objects of the class.
Static block of code in a class will be executed before the objects are created for the class. Static variables and methods can be accessed using the class name. Static methods can use / manipulate only static variables.


What is a StringBuffer? How does it differ from String class?
StringBuffer is a peer class of String that provides much of the functionality of Strings. StringBuffer have characters and substrings inserted in the middle or appended to the end. StringBuffer is mutable whereas String class is immutable. StringBuffer is fast and consumes less memory when compared to String class.


What is the use of super keyword?
How is super used in constructors?
‘super’ is a keyword in Java used to access the super class variables and constructors.
Example
import java.io.*;

class A
{
          int x;
          A(int i)
          {
                   x = i;
          }
}       
class B extends A
{
          int y;
          B(int i, int j)
{
                   super(i);                // calls the super class constructor
                    y = j;
          }
          void fnDisplay()
          {       


// Accesses the super class variable
          System.out.println("x = "+ super.x);
          System.out.println("y = " + y);
          }
}
class pgm1
{
          public static void main(String as[])
          {
                   B obj = new B(5, 6);
          obj.fnDisplay();
          }
}


Differentiate constructors and methods.

Constructor
Method
Special member function of class
Member function of a class
Same name as class name
Any name can be used
Always public.
May be public, private or protected.
No return values
May or may not have return values.
Automatically invoked when objects are created.
Have to be explicitly invoked using the object of a class
Mainly used to initialize the variables of a class
Performs a specific task

Syntax – constructor

<Class name> (<Argument list>)
{
}

Syntax – method
<Return type> <Method name> (<Argument list>)
{
}



What is an interface? How is it defined?

Interface in Java is a mechanism to achieve abstraction. An interface is declared using the keyword interface. It has only method declarations without body. A class can implement the interface using the keyword ‘implements’. Each method of the interface has to be defined in the class.
Interface cannot be instantiated. Multiple inheritance in Java can be partially implemented using interface.

Syntax:
interface <interface name>
          {
                   // Method declarations
          }



What is an abstract class? List its characteristics.

A class that is declared with ‘abstract’ keyword is known as abstract class. It cannot be instantiated. They are used to declare common characteristics of subclass. An abstract class can include methods that contain no implementation. If an abstract class is inherited, then the derived class must provide the implementations for all the methods of the abstract class. 


How do you create and initialize arrays in Java?

An array is a set of related elements of same datatype which share a common name and are stored in contiguous memory locations. Each value is identified by its index.
Syntax for declaration
          <data type> [] <array name> = new <datatype>[array size];
 Declaration and initialization
          <data type> [] <array name> = {value1, value2, ….};



What is exception handling?

An exception is an abnormal condition that arises during run time and disrupts the normal flow of the program. Java provides a mechanism called exception handling for handling such situations. Its implemented using keywords try, catch, throw, throws and finally.



What is event delegation model?

Event handling in Java involves source and listener. A source is an awt component like button, checkbox, list, etc. which may generate several types of events. A listener is an object which may register to receive an event. When an event occurs, the event source invokes the appropriate method defined by the listener and provides an event object as its argument.
To implement the event delegation Model
Implement the appropriate interface in the listener so that it will receive the type of event desired.
Implement code to register and unregister (if necessary) the listener as a recipient for the event notifications.





What is inner class and anonymous inner class?

A class declared inside another class is known as inner class. The inner class can access all the members of the outer class including its private members.
An anonymous inner class is a type of inner class that has no name and can be instantiated only once. It is declared inside the method and terminated by a semicolon.

Example – Inner class
 Class A
{
          Class B        // inner class
          {
          }
}


Example – Anonymous Inner class – MouseAdapter

public class AnonymousInnerClassDemo extends Applet
{
public void init()
{
addMouseListener (new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
showStatus("Mouse Pressed");
}
});
}
}




Differentiate between choice and list objects.

Choice
List
Type of AWT control
Type of AWT control
Pull down menu.
Pull down menu
Choice is displayed in compact form. Only one item is visible.
Multiline display. Multiple items may be visible.
Allows selection of one item only
Multiple selections possible.