Search
  • WeCare

Technical Questions - 02



I have created this while doing MCA(Pune University), Year 2004... might be outdated, but thought to share this with you


#technicalquestions #year2004 #mca


335)what are the all Listeners in java and explain?

Ans) The Listeners in java are Action listeners , Adjustment listeners,Component Listeners Key listeners , mouse listeners , Text listeners , Window listeners ,item listeners.

336)What is meant by an adaptor class?

Ans) The adaptor class ; that can simplify the creation of event handlers in certain situations.

337)What are the types of mouse event listeners?

Ans) The types of mouse event listeners are Mouse listeners , mouseMotion listeners , mousewheel listerners.

338) what are the types of methods in mousse listeners ?

Ans) There are five methods –

MouseClicked () ,mouseEntered() , mouseExited () , mouse pressed (), mouseRelesed() .

Q 340) What is the difference between List and Choice?

Ans) List and Choice are both related to class. List class provides a compact, multichoice, scrolling selection list. Unlike the Choice object, which shows only the single selected item in the menu.

Q 342) What are the different types of Layouts?

Ans) Different types of Layouts are as under:-

Flow Layout (), Border Layout (), Grid Layout, Card Layout (), Grid Bag Layout ().

Q 343) What is meant by CardLayout?

Ans) The CardLayout class is a unique among other Layout managers in that it stores several different layouts. This can be useful for user interfaces with optional components that can be dynamically enabled.CardLayout provides these two constructors:

CardLayout ()

CardLayout (int horz, int vert)

Q 344) What is the difference between GridLayout and GridBagLayout?

Ans) GridLayout layouts component in a two dimensional grid. When you initiate GridLayout you define the number of rows and columns. Constructors supported by it are

GridLayout ()

GridBagLayout is useful that you can specify the relative placement of component by specifying there conditions. It is quite easy to use once you understand how it works.

GridBagLayout define one constructor which is shown:

GridBagLayout ()

Q 345) What is the difference between menuitem and checkboxmenu item?

Ans) Menuitem object represents something selected by user where as checkboxmenu item is a type of menuoption which will have a check mark next to them when they are selected.

Q 350) What is meant by Swing?

Ans) Swing is a set of classes that provides more powerful and flexible functionally that is possible and flexible functionality than is possible with standard AWT components.

Q 351) What is the difference between AWT and Swing?

Ans) AWT are heavy weight component but swing are light weight components

Component in swing have more capability than that of AWT.

Q 352) What is the difference between an applet and Japplet?

Ans) Japplet is rich with functionality that is not found in Applet.

Japplet supports various panes.

Applet that uses swing must be subclass of Applet.

Q 353) What are all components used in Swing?

Ans) Components used in Swing are as under:-

Q 354) What is meant by tab pans?

Ans) Tab Pans is a component that appears as a group of folder in a file cabinet. Each folder has a title.Tab pans are commonly used for setting configuration.

Q 355) What is the use of JTree?

Ans) Trees are implemented in swing by the JTree class.

A JTree object generates events when a node is expanded or collapsed.

Q 358) What is the use of JTable?

Ans) The JTable class is a subclass of JComponent that provides a basic table implementation. It implements the scrollable, java.awt.accessibility accessible.

Q 362) What is meant by java beans?

Ans) JavaBeans technology is the component architecture for the Java 2 Platform, Standard Edition (J2SE). Components (JavaBeans) are reusable software programs that you can develop and assemble easily to create sophisticated applications. JavaBeans technology is based on the JavaBeans specification.

Q 363)What is meant by manifest files?

Ans)The manifest is a special file that can contain information about the files packaged in a JAR file. By tailoring this "meta" information that the manifest contains, you enable the JAR file to be used for a variety of purposes

Q 364)What is Introspection?

Ans) Introspection is the process of analyzing a bean to determine its capabilities. This is an essential feature of the java beans.Without Introspection,the java Bean technology could not operate

Q 365)What are the steps involved to create a beans?

Ans)Step involved to create a beans are as follow.

1-Create a directory for the new Bean.

2-Create the java source files

3-Compile the source file

4-Create a manifest file

5-Generate a JAR file

6-Test

Q 366)Say any two properties in Beans?

Ans)

1-A Bean obtains all the benefits of java`s “write once,run anywhere”paradigm

2-Methods of a Bean that are exposed to an application builder tool can be controlled

Q 367)What are persistence?

Ans) Persistence is the ability to save a Bean to nonvolatile storage and retrieve it at a later time.

Q 368)What is use of bean info?

Ans)Bean info is interface which use to allows a designer to specify information about the properties,events and methods of a Bean

Q 369)what are the interfaces you used in beans?

Ans)AppletInitializer, Beaninfo, Customize, Visibility, PropertyChangeListener, PropertyEditor

Q 370) what are the classes you used in beans?

Ans) BeanDescriptor , Encoder, EventHandler ,EventsetDescriptor, IntrospectionException, Intospector

Q 372)What is user defined exception?

Ans) Exception which are handled as per the programmers need

Q 373)What do you know about garbage collector?

Ans) since objects are dynamically allocated using a new operator it might be wondering how such objects are destroyed and their memory released for later reallocation in some language such as C++ dynamically allocates the object must be manually released by use of delete operator. Java takes different approach handles deallocation automatically this technique that accomplish this is called garbage collector

Q 374)What is the difference between C++ and java?

Ans) C++ supports pointers concepts however java does not supports pointer.

Q 376) What is the use of servlets?

Ans) Servlets are small programs that execute on the server side of a web connection.

Servlet dynamically extends the functionality of a web server

Q 379)How will you initialize an Applet?

Ans) public void init ()

Q 380) What is JAR file?

Ans) JAR file stands for Java Archive files. A JAR files allows you to efficiently deploy a set of classes and their associated resources

381) What is synchronization?

Ans) It’s the mechanism that ensures that only one thread is accessing the resources at a time.

382) What is an I/O Filter?

Ans) It’s an object that reads from one stream and writes to another, usually altering the data in some way as it passed from one stream to another.

383) Can applet in different page communicate with each other?

Ans) Yes, by using getDocumentBase().

384) When we will use an Interface and Abstract class?

Ans) 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 are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship.

An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.

385) How to communicate 2 threads with each other?

Ans) By multithreading mechanism in which more than one thread run independent of each other within the process. wait(), notify(), notifyAll() methods are used.

386) What are types of servlet?

Ans) There are 2 types. a) HttpServlet b) GenericServlet.

387) Difference between HttpServlet and GenericServlet.

Ans) Http Servlet contains methods specific to HTTP protocol while Generic Servlet are useful when building non HTTP servlets such as those that implements FTP, POP3, telnet or any custom protocol.

388) Difference between doPost() and doGet() methods.

Ans) a) doGet() is used to get information, while doPost() is used for posting information.

b) doGet() requests cant send large amount of information (limited to 240-255 chars). doPost() requests passes all of its data, of unlimited length. (c) a doGet() requested is appended to the request URL in a query string and this allows the exchange visible to the client. doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.

389) What are methods in HTTPServlet?

Ans) Methods are: service(), doGet(), doHead(), doHead(), doPost(), doPut(), doDelete().

390) What is Cookie? Why is Cookie used?

Ans) Cookies are mechanism that a servlet uses to have a client hold a small amount of state information associated with the user.

Once a user issues a request & requests a response, the server has no memory of the transaction. Furthermore, when the same user makes another request, the server has no way to distinguish this user from any other. Hence for this purpose, cookies, which store user specific information on the web.

391) If my browser does not support Cookie, and my server sends a cookie instance, what will happen?

Ans) The web page may not get loaded properly and completely. Text fields may not get displayed.

392) Why do u use Session Tracking in HttpServlet?

Ans) HTTP is a stateless protocol. Each request is independent of the previous one. However, in some applications, it is necessary to save information so that information can be collected from several interactions between a browser and a server. Sessions provide such mechanism.

393) Can you use javaScript in Servlets?

Ans) Yes.

394) What is the capacity the doGet() can send to the server?

Ans) doGet() requests cant send large amount of information (limited to 240-255 chars).

395) What is servlet?

Ans) Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers, eg: a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.

396) What are types of servlets? Explain.

Ans) There are 2 types:

a) Http Servlet: contains methods specific to HTTP protocol.

b) Generic Servlet: useful when building non HTTP servlets such as those that implements FTP, POP3, telnet or any custom protocol.

Q 402)What is corresponding layout for card in swing?

Ans) You can use same card layout in swings also. there is no other layout in swings

Q 403)What is light weight component?

Ans) The pixels of components are transparent.They totally made in java hence platform independent.

Q 404)What is bean?Where it can be used?

Ans) Bean is software component that has been desing to be in variety of differnt environment.A

bean may be or may not be visible to end user.It can perform a simple a function and also can

perform complex function.It can be used in

1)spelling checker application

2) Forecasting the performance of stock portfolio

3)To decode stream of multimedia information in real time system

Q 405)What is the difference between Java class and bean?

Ans) A class with no restriction on accesors , mutators or constructor can be considered as a plain Java class. Java Bean is a spl java class with accessors(getters) and mutators(setters) for the instance variables present.Moreover, it can only have a defalut constructor.

Q 406)What is mapping mechanism used by Java to identify IDL language?

 
 Ans) The Java distributed programming community has up till now been forced to choose
between two different mechanisms for distributed programming, Java Remote Method
Invocation (RMI) and OMG IDL.
The RMI style of distributed programming has proven extremely popular because it is
easy to use and avoids the need for Java programmers to learn a separate interface
definition language. However, RMI lacks interoperability with other languages and it is
not currently supported over standard protocols.
 

Q 407)Difference between Application and Java applet?

Ans) Application is program that runs on your computer, under the os of that computer. It is similar to program written in C or C++.

Applet is application designed to be transmitted over the internet and executed by java –compatible web browser. It is actually a tiny java program,dynamically downloaded across the network,just like an image,sound files.

Q 408)What is serializable interface?

Ans) Serilizable interface object can be saved and restored by the serialization facilities. It does not defines any members. It is simply used to indicate that a class may be serialized.

Q 409)What is difference between CGI and Servelet?

Ans) Servlet share the single database connection across multiple request. CGI can not share the single database connection across multiple request.

Servlets can be run on different server on platform without modification. Modification requires in CGI are based on technology.

Q411)Why java is not fully object oriented?

Ans) Java is fully object oriented.

Q413)What is the root class for all Java classes?

Ans) object

Q417)Why we use OOP concepts?What is its advantage?

Ans) OOPs concepts can simulate with real world. Also

Object oriented theorists identify three fundamental aspects of an object oriented language:

  1. User Defined Data Types, i.e. classes

  2. Inheritance

  3. Polymorphism

  4. Encapsulation

Advantages:-

1) Reusability

2) Data Hiding

3) Data Binding

Q418)What is the differences between C++ and Java

Ans) Java's had all three of these at least since it's first public release. Although C++ fanatics like to argue about operator overloading and multiple inheritance, features Java does not have, these have proven to be more useful in theory than in practice.

Furthermore, Java is fully object oriented. Unlike C++, there are no functions hanging around in global space to do everything you forgot to do inside a class. Everything in Java is either an object, a class, or part of one. Java takes object oriented programming much more seriously than does C++.

Q 419)What is exact difference between unicast and multi unicast?

Ans) A unicast packet is one machine is talking to only one other machine. All TCP connections are unicast, since they can only have one destination host for each source host. UDP packets are almost always unicast too, though they can be sent to the broadcast address so that they reach every single machine in some cases. A multicast packet is from one machine to one or more. The difference between a multicast packet and a broadcast packet is that hosts receiving multicast packets can be on different lans, and that each multicast data-stream is only transmitted between networks once, not once per machine on the remote network. Rather than each machine connecting to a video server, the multicast data is streamed per-network, and multiple machines just listen-in on the multicast data once it's on the network.

Q421) What is the exact difference in between unicast and multicast object? Can u explain in detail?

Ans) In unicast we can convert only one wrapper class object in to another wrapper class object., where as if u consider an object of Object class we can convert it in to any other wrapper class object. This is considered as multicasting.

Q423) In a Container there are 5 components. I want to display the all the components, how will you that one?

Q426) Tell me latest versions in JAVA related areas?

Ans) JRE 5.0

JDK 1.5

J2EE 1.4

J2ME 2.2

Q427. What is meant by class loader? How many types are there? When will you use them?

Ans) They provide security and network mobility to Java programs. JVM has two types of class loaders

1.Primordial class loader to load the java API classes when u execute java programs. It contain trusted classes

2.Class loader objects-an application can create many class loaders at runtime for loading the classes of the application

Q429) What is meant by cookies? Explain

Ans) Cookies is a message stored as text file sent from web server to web browse. The browser sends back the message to the server each time the browser send the request for the page. The server reads the information present in the cookie and presents the user with customized web pages.

Q431) How OOPS concept is achieved in JAVA?

Ans) Java defines data as objects with methods that support the objects. Java is object oriented and provides abstraction, encapsulation, inheritance, and polymorphism. Even the most basic program has class. Any code that u write is in class.

Q432) Features for using JAVA

Ans) JAVA is simple, object-oriented, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded and dynamic language’

Q434) public static void main Explain

Ans) Public: because JVM calls it

Static: main is called before any object is created

Void: return nothing

Main: name of the function

Q435) What are command line arguments?

Ans)These are parameters passed at command prompt. Program to be executed by specifying name of the program at operating system level. The program is then interpreted as an OS command. No CPU wastage.

Q436) Explain about three-tier model

Ans) Client tier: responsible for presentation of data, controlling user interface

Application-Server tier: business rules are implemented

Data server: responsible for data storage

Advantages: dynamic load balancing, clear separation of user interfwace, simple to use wrapping technique

Q437) Difference between String & StringBuffer

Ans) The String class supports operations on string of characters. This class supports immutable strings (constants).

The String Buffer class is used for manipulation of strings. It unlike a string can be modified.

Q438) Wrapper class. Is String a wrapper class?

Ans) Primitive data types behave like objects. Wrapper classes also provide methods for converting string to various data types and also type specific methods.e.g. Integer x[]=new Integer(10);

String is a wrapper class as it creates a String object that contains the text between double quotes.

Q439) What are restrictions for static method? Purpose of the file class

Ans) Can not be called on any object; Can be called before any object gets created; Can access static members directly; Should be called as ClassName.FunctionName()

File class is used to access file and directory objects. It uses file name conventions of the host OS.

Q440) Default modifier in Interface

Ans) Modifier can be public or not used. When no access specifier is included then default access results, and the interface is only available to other members of the package in which it is declared. When public, it can be used by any other code.

Q441. Can abstract be declared as final?

Ans)No, abstract can not be declared as final. It is illegal to declare a class as

both abstract and final because an abstract class is incomplete by itself and relies upon its subclass to provide complete implementation and final class can not have subclasses.

Q442)Can we declare variables inside a method as Final Variables?

Ans)Yes, we can declare variables inside a method as Final Variables. The following program demonstrates it.

class DemoFinal

{

void method()

{

final int CONSTANT=1;

System.out.println("Final Variable value is "+CONSTANT);

}

public static void main(String args[])

{

DemoFinal ob=new DemoFinal();

ob.method();

}

}

Output of the program:

Final Variable value is 1

Q443)What is Package concept and use of package?

Ans)Packages are container for classes that are used to keep the class name compartmentalized.

We use a unique name for each class to avoid name collisions. Without some way to manage the name space, we could run out of convenient, descriptive names for individual classes. We also need some way to be assured that the name we choose is unique and not collide with class name chosen by any other programmer. Java provides a mechanism for partitioning the class namespace into more manageable chunks. This mechanism is the package. We can define classes inside a package, which can’t be access by code outside that package.

Private No Modifier Protected Public

Same class Yes Yes Yes Yes

Same package No Yes Yes Yes

Subclass

Same package No Yes Yes Yes

Non-Subclass

Different No No Yes Yes

Package

Subclass

Different No No No Yes

Package

Non-Subclass

Q445) Difference between Applet and Application.

Ans) An application is a program that runs on a computer, under the operating system of that computer. While an applet is an application designed to be transmitted over the Internet and executed by a Java compatible web browser.

Applet impose certain limitations and restrictions in their design.

· Applets do not use the main() method for initiating the execution of the code. Applet when loaded automatically call certain methods of applet class to start and execute the application code.

· Unlike stand alone application, applet can not be run independently.They are run from inside a web page using a special feature known as HTML tag.

· Applets can not read from or write to the file in the local computer,.

· Applets can not communicate with other server on the network.

· Applets can not run any program from the local computer.

· Applets are restricted from using libraries from other languages such as C or C++.

Q446) Life cycle of the Applet.

Ans)When an applet begins, the AWT calls the following methods in this sequence:

1.init()

2.start()

3.paint()

When an applet is terminated, the following sequence of method calls take place:

1.stop()

2.destroy()

init()

The init() method is the first method to be called. Initializing of variable is done inside this method.This method is called only once during the run time of an applet.

start()

This method is called after init().It is also called to restart an applet after it has been stoped.

paint()

This method is called each time an applet’s output must be redrawn.

stop()

This method is called a web browser leaves the HTML document containing the applet –when it goes to another page.

destroy()

This method is called when the environment determines that the applet need to be removed completely from memory. The stop() method is always called before destroy().

Q447) Can applet have constructors?

Ans) No, Applet can not have applet.

Q449) Explain superclass and subclass.

Ans) Using inheritance, a general class can be created that defines traits common to a set of related items. This class can be inherited by other,more specific classes, each adding those thing that are unique to it.A class that is inherited is called superclass. The class that does the inheriting is called subclass. A subclass is a specialize version of a superclass. It inherit all of the instance variables and methods defined by the superclass and adds its own, unique elements.

Q450)What is AppletStub?

Ans)AppletStub is an interface defined by java.applet. it provide the mens by which an applet and the browser(or applet viewer) communicate.

Q451) Explain Stream Tokenizer.

Ans) Stream Tokenizer is java’s I/O class which is used to look for pattern in an input stream. It break up the input stream into tokens that are delimited by sets of characters.

Constructor:

Stream Tokenizer(Reader intsteam)

Here intsteam must be some form of Reader.

Method:

void eolIsSignificant( boolean eolFlag)

If eolFlag is true, the end of line characters are written as tokens. If eolFlag is false, the end of line characters are ignored.

void wordChars(int start,int end)

Use to specify the range of characters that can be used in words. start and end above specify range of valid characters

Void whitespaceChars(int start,int end)

Use to specify the whitespace characters. start and end above specify range of valid whitespace characters.

nextToken() is use to obtain the next token from the input stream.It returns the type of the token.

StreamTokenizer defines four int constants:

TT_EOF , TT_EOL , TT_NUMBER and TT_WORD

Q452) What is difference between two types of threads?

Ans) The two types of threads are main thread and child thread. Main thread begins running immediately, when a java program starts up. It is the thread from which other child threads will be spawned. Main thread must be the last thread to finish execution it perform various shutdown actions. It is created automatically when a java program is started.

Q453) Checked and Unchecked Exception.

Ans)Unchecked Exceptions are exceptions that need not be included in any method’s throws list. They are automatically available. The compiler does not checked to see if a method handles or throws these exception.

e.g. ArithmeticException, ArrayIndexOutOfBoundException, IllegalArgumentException etc.

Checked Exception are exceptions that must be included in a method’s throws list if that method can generate one of these exceptions and those not handle it itself.

e.g. ClassNotFoundException, IllegalAccessException, InterruptedException etc.

Q454)Use of throws Exception.

Ans)If a method is capable of causing an exception that it does not handle, it must specify this behavior so that callers of the method can guard themselves against that exception. We do this by including a throws clause in the method’s declaration. A throws clause lists the type of exceptions that a method might throw.

Q455)What is finally in exception handling Vector class?

Ans)when exceptions are thrown, exception in a method take an abrupt, non linear path that alters the normal flow through the method.Depending on how the method is coded, it is even possible for an exception to cause the method to return prematurely. This could be a problem in some method.The final keyword is design to address this contingency.

Q457)Two types of multi-tasking

Ans)The two types of multi-tasking are: Process based and Thread based

Process based multitasking is the feature that allows a computer to run two or more programs concurrently.In process based multitasking, a program is the smallest unit of code that can be dispatch by the scheduler.

In a thread based multitasking, the thread is the smallest unit of dispatchable code.

This means that a single program can perform two or more task simultaneously.

Q458)Two ways to create the thread.

Ans)Java defines two ways in which a thread can be created

(i) By implementing the Runnable interface.

(ii) By extending the thread class.

Q459) Synchronization

Ans) when two or more threads need access to a shared resource,they need some way to ensure that the resources will be used by only one thread at a time. The process by which this is achieved is called synchronization.

We can synchronization our code in either of two ways.

(i) Using Synchronization Method.

(iii) Using Synchronization Statement.

Q460) I/O Filter.

Ans) Filtered streams are simply wrappers around underlying input or output stream that transparently provide some extended level of functionality. These stream are typically access by methods that are excepting a generic stream, which is a superclass of the filtered stream.The filtered byte streams are FilterInputStream and FilterOutputStream.

Their constructors are given below:

FilterInputStream(InputStream is)

FilterOutputStream(OutputStream os)

461) What is synchronization?

Ans)It’s the mechanism that ensures that only one thread is accessing the resources at a time.

462) What is an I/O Filter?

Ans) It’s an object that reads from one stream and writes to another, usually altering the data in some way as it passed from one stream to another.

463) Can applet in different page communicate with each other?

Ans) Yes, by using getDocumentBase().

464) When we will use an Interface and Abstract class?

Ans) 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 are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship.

An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.

465) How to communicate 2 threads with each other?

Ans) By multithreading mechanism in which more than one thread run independent of each other within the process. wait(), notify(), notifyAll() methods are used.

466) What are types of servlet?

Ans) There are 2 types. a) HttpServlet b) GenericServlet.

467) Difference between HttpServlet and GenericServlet.

Ans) Http Servlet contains methods specific to HTTP protocol while Generic Servlet are useful when building non HTTP servlets such as those that implements FTP, POP3, telnet or any custom protocol.

468) Difference between doPost() and doGet() methods.

Ans) a) doGet() is used to get information, while doPost() is used for posting information.

b) doGet() requests cant send large amount of information (limited to 240-255 chars). doPost() requests passes all of its data, of unlimited length. (c) a doGet() requested is appended to the request URL in a query string and this allows the exchange visible to the client. doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.

469) What are methods in HTTPServlet?

Ans) Methods are: service(), doGet(), doHead(), doHead(), doPost(), doPut(), doDelete().

470) What is Cookie? Why is Cookie used?

Ans) Cookies are mechanism that a servlet uses to have a client hold a small amount of state information associated with the user.

Once a user issues a request & requests a response, the server has no memory of the transaction. Furthermore, when the same user makes another request, the server has no way to distinguish this user from any other. Hence for this purpose, cookies, which store user specific information on the web.

471) If my browser does not support Cookie, and my server sends a cookie instance, what will happen?

Ans) The web page may not get loaded properly and completely. Text fields may not get displayed.

472) Why do u use Session Tracking in HttpServlet?

Ans) HTTP is a stateless protocol. Each request is independent of the previous one. However, in some applications, it is necessary to save information so that information can be collected from several interactions between a browser and a server. Sessions provide such mechanism.

473) Can you use javaScript in Servlets?

Ans)Yes.

474) What is the capacity the doGet() can send to the server?

Ans) doGet() requests cant send large amount of information (limited to 240-255 chars).

475) What is servlet?

Ans) Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers, eg: a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.

476) What are types of servlets? Explain.

Ans) There are 2 types:

a) Http Servlet: contains methods specific to HTTP protocol.

b) Generic Servlet: useful when building non HTTP servlets such as those that implements FTP, POP3, telnet or any custom protocol.

Q 481) What is the diffrence between two type of servlet ?

Ans) There are two type of servlets that are extended from two servlet class -GenricServlet

Class and HttpServlet Class.

HttpServlet Class contains method specifying to the http protocol GenricServlet

GenricServlet Class is useful when building non-http servlets such as those that implements

FTP,POP3,Telnet or any custom protocol.

Q 482) What is type of method for sending reqest from HTTP server ?

Ans) There are two types of method which are

1) doGet( )

2)doPost( )

doGet( ) is called for GET reqest and doPost for POST reqest .

Q 483) What are the exception throw by servlet ? why ?

Ans) servletException ,unavailableException this two exception aer throw by servlets.

First exception throw by servlet beacuse servlet error occured.

Second exception throw by servlet beacuse servlet not available.

Q484) What is the life cycle of ?

Ans) Fallowing is the life cycle of servlet

1)Create and initialize the servlet .

2)Handle zero or more service calls from clients.

3)Destroy the servlet and then garbge collect it .

Q485) What is meant by cookies ?

Ans) A cookie is a simple mechanisum used to store and retrive user specific information

on web.

Q486) What is HTTP session ?

Ans) An HTTP session associates each reqest recived by the server with the client that

issued it.

Q487) What is the diffrence between GET and POST method ?

Ans) GET method is used to reqest a resourse from the server .

POST method is used for passing user input to the server.

GET method information store in URL .

POST method informaton store in body of reqest .

Q488) How you can run a servlet program ?

Ans) There are many ways in which to run a servlet some web server such as Sun's Java Web

Server and NetScape Enterprise Server , Natively Support Servlets .

by using servlet runner utility that ship's with JSDK'S /bin directory and launched from the command line .

Q489) How to communicate between an applet and servlet ?

Ans) For communication applet uses GET method which send reqest .

For communication servlet uses POST method which send result of proccess GET call.

Q490)What is servlet to servlet communication ?

Ans) In servlet to servlet communication request of one servlet forward to anthoer servlet

using forward( ) and include( ) is used to include content genereated by anthoer servlet

this is done RequestDispacher object .

Q491) What is session tracking ?

Ans) HTTP is stateless protocol each reqest is idependent of the previous but some appliction

requriment to maintain state information so that information can be collected from several

interaction between a browser and server session provide such mechanisum called as session

tracking .

Q492) What are the security issues in servlets ?

Ans) Servlets can not do operation which are dangerous to server system .

So only trusted servlet are permited so they must be from local machine not from

remote machine

Q493) What is HTTP tunneling ?

Ans) Protocol tunneling is the process of encapsulating one protocol wthin another protocol

that operates on the same layer .

Q495) What is servlet chaining ?

Ans) Servlet chaining is the process of passing the output of one servlet to the input of another .

Q 496) What is URL rewriting ?

Ans) It is a method for managing state on the web .Rewritten URL pass state information

between client and server by embeding information in the URL of all hyperlink within

a HTML document.

Q499) What is servlet API used for connecting datebase ?

Ans) JDBC is an API used for connecting database in servlet .

Q500) In servlets ,we are having a web page that is invoking servlets ? user name and password which checks in the database ? Suppose the second page also if we want to verify the same infomation weather it will connects to the database or it will be used previous

information ?

Ans) It is uses previous information

Q501) What are virtual functions?

Ans)A virtual function is function that is decleared as virtual in a base class and redefined by a derived class.To declare a function as virtual,it’s declaration is preceded by the keyword “virtual”.A virtual function defines a general class of actions.The redefined virtual function implements a specific method.

Q507) What is meant by servlet? What are the parameters of the service method?

Ans) Servlets are small programs that executes on a server side of a web connection.Just as applet dynamically extend the functionality of a web browser,servlets dynamically extend the functionality of a web server.

Void service(ServletRequest req,ServletResponse res)throws ServletException,IOException

Called to process a request from a client.The request from the client read from req.Response to the client can be written to res.An exception is generated if a servlet for IO problem occurs.

Q508) What is meant by session? Tell me something about HTTP Session class.

Ans)A session is a persistent network connection between two hosts(usually a client and a server)that facilitates the exchange of information.When the connection is closed,the session is over.However ,we are not interested in this type of session.Rather,let’s focus on another type of session known as HTTP session or a virtual session.This type of session involves virtual connection between the client and server rather than a physical one.Let’s first examine what is mean by “virtual connection.”

As we attempt to understand an HTTP session

Q509) How do you envoke a servlet?What is a different between DoPost and doGet

methods?

Ans) 1)The server loads the servlet when it is first requested by a client or ,if configured to do so,at server startup

2) The server creates one or more instances of the servlet class.

3)The server constructs a ServerConfig object that provides initialization information to the servlet.

4)The server calls the servlet’s init method ,if the server has created multiple servlet instances(step 2)the init method is called one time for each instance.

5)The server constructs a ServletRequest or HttpServletRequest object from the data included in the client’s request.It also constructs a ServletResponse or HttpServletResponse.object that provides methods for customizing the server’s response.

6)The server calls the servlets service().When concurrent request arrive,multiple service methods can run in separate threads.

7)The service() processes the client request by evaluating the servletRequest or HttpRequest.Object and response using the ServletResponse or HttpServletResponse object.

8)If the server receive another request another request for this servlet ,the process begins again at step 5

9)When instructed to unload the servlet,perhaps by the server administrator or programmatically by the servlet itself,the server calls the servlet’s destroyed()method.

The doGet method is used to create a simple HTML form.When the user clicks submit button ,the form data is posted to the servlet and handled by the doPost method.The difference between them doPost method simply constructs an HTML document that displays the data that was submitted and returns it to the client.

Q510)What is a difference between the HTTP servlet and Generic servlet?

Ans) Every servlet that you write will either extend the class Generic Servlet or HTTP Servlet or implement the servlet interface.The HTTP servlet class contains methods specific to the HTTP protocol.The Generic Servlet class is useful when building non-HTTP servlets such as those that implement FTP,POP3,Telnet,or any custom protocol.

Q511) Explain their methods?Tell me their parameter names also have you used threads in servlet.

Ans) Generic servlet class

void destroy():- call when the servlet is unloaded.

String getServletInfo():- returns a string described in servlet.

ServletContext getServletContext() :-returns the context for the servlet.

Void log(String s)

Void log(String s,Throwable e)

Here ,s is the string to be appended to the log,and e is an exception that is occurred.

Int readLine(byte[] buffer,int offset,int size)throwsIOException

Here,buffer is the array into which size byte are placed starting at offset.The method returns the actual no.of bytes read or –1 if an end-of-stream condition is encountered.

HTTP servlet class

The HTTP servlet class extends generic servlet.It is commonly used when developing servlet that receive an process HTTP request.

Void doDelete(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException.

Performs an HTTP DELETE.

Void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException

Performs an HTTP GET.

Q513) Explain servlet life cycle?

Ans) Each servlet has the same life cycle:

· A server loads and initializes the servlet

· The servlet handles zero or more client requests

· The server removes the servlet (some servers do this step only when they shut down)

Q514) Why do you go for servlet rather than CGI?

Ans) Servlets are an effective replacement for CGI scripts. They provide a way to generate dynamic documents that is both easier to write and faster to run. Servlets also address the problem of doing server-side programming with platform-specific APIs: they are developed with the Java Servlet API, a standard Java extension.

Q516) How many interfaces used in RMI?

Ans)There are three new interfaces in RMI listed below

a)Leasing

b)Transactions

c)Distributed Events.

Q520) What is meant by RMI?

Ans) • is available on any platform with JDK software compliant

technologies

• made of powerful open interfaces, readily available to developers

• shipping today and fully functional

• contains features like object pass by value

Q521). What is meant by RMI?

Ans. In the early years of programming, the most of programming was done for stand alone PC. But as the time passes programmers started thinking about distributed programming. RMI- Remote Method Invocation is the technology for distributed methods.

Java Remote Method Invocation (RIM) is the Java language’s native mechanism for performing simple, powerful networking. RMI allows you to write distributed objects in Java enabling objects to communicate in memory, across Java Virtual Machines (JVM), and across physical devices. RMI is defined as the action of invoking a method of remote interface on a remote object. RMI's purpose is to make the objects in separate JVM to look like local objects.

Q523). What does a stub mean?

Ans. The stub is the client side object that represents or acts as a proxy for the remote object. The stub has the same interface or list of methods, as the remote object, but when the client calls a stub method, the stub forwards the request via the RMI infrastructure to the remote object, which actually executes it.

The following lists the sequence of tasks performed by the stub in detail:

  • Indicates a connection with the remote virtual machine containing the remote object.

  • Marshals the parameters to the remote virtual machine.

  • Waits for the result of the method invocation.

  • Unmarshals reads the return value or exception returned.

  • Returns the value to the caller.

The stub hides the serialization of method parameters and the network level communication in order to present a simple invocation mechanism to the caller.

Q524). What does a skeleton mean?

Ans. On the server side, the skeleton object takes care of all the details of remoteness so that the actual remote object doesn’t need to worry about them. In other words, you can pretty much code a remote object the same way as if it were local – the skeleton insulates the remote object from RMI infrastructure.

The following lists the sequence of tasks performed by the skeleton in detail:

  • Unmarshals the parameters for the remote method.

  • Invokes the method on the actual remote object implementation.

  • Marshals the result to the caller.

Skeletons are responsible for receiving calls over the network (perhaps from a stub) and delegating the call to the remote object implementation.

Q525). What is meant by serialization and deserialization?

Ans. Serialization is the conversion

Q527). What is the use of TL?

Ans. The Transport layer makes the stream-based network connections over TCP/IP between the JVMs, and is responsible for setting and managing those connections. Even if two JVMs are running on the same physical computer, they connect through their host computer’s TCP/IP network protocol stack.

RMI uses a wire level protocol called JRMP (Java Remote Method Protocol) on the top of TCP/IP.

Q528). What is RMI Registry?

Ans. For a client and server to start talking, they need some way to connect. Acquiring this connection is known as bootstrapping. RMI provides an entity know as the RMI Registry for bootstrapping. When you want to make an object remotely accessible, you register it with the registry. You give the registry a name for the object during this registration. From then on the Registry will route all incoming requests for that name to your object. You can think of the RMI Registry as a giant hashtable that maps name to objects.

The RMI Registry accomplishes this task by sitting at a well-known network port and listening for incoming connections. When remote client wants to access an object registered with a particular registry, the client issues a request over the network to the registry. The Registry reads the request, looks up the name of the remote object requested, and returns the stub for that remote object to the client.

Q529). What is rmic?

Ans. The stubs and skeletons provide a screen to block networking issues and make it appear as if thing are happening locally. Both stubs and skeletons must implement custom remote object’s interfaces. Because of this, no two stubs or skeletons are the same, and they must be generated a new for each remote object class that u create. Fortunately, Sun ships atoll to perform this generation for you. The name of the tool is rmic, the RMI compiler. It takes as input your remote object implementation, and it creates a stub, skeleton for that remote object. The stub mimics each method exposed by the remote object, copying the method signatures exactly, so clients can call that stub locally as if the remote object itself were there.

Q530). How will you pass parameters in RIM?

Ans. When a remote object is passed from the server to the client, the client receives a stub. Using the stub, it can manipulate the server object by invoking remote methods.

The object, however, stays on the server.

Whenever the object that is not a remote object needs to be transported from one Java virtual machine to another, the Java virtual machine makes a copy and sends that copy across the network connection. This technique is very different from parameter passing in local method.

When you pass objects in local method or return them as a method results, only object references are passed. However, object references are memory addresses of objects in local Java virtual machine. This information is meaningless to a different Java virtual machine.

It is not difficult to imagine how a copy of object is done by RMI. The oblivious answer is serialization. RMI uses serialization mechanism to send the objects across the network.

Passing the remote objects from server to client is simple.

The client receives a stub object then saves it in an object variable whose type is the same as the remote interface. The client can now access the actual object on the server through the variable.

Q531). What are the steps involved in RIM?

Ans. RMI has typically following steps:

1) Write a remote interface.

2) Write its implementation

3) Write a server

4) Write Client.

Q532). What is meant by bind (), rebind (), unbind () and look up methods?

Ans. Bind

public static void bind(String name, Remote object)

This method binds the remote object to a string name. If the same name is already present it throws the exception AlreadyBoundException.

Rebind

public static void rebind(String name, Remote object)

Rebinds the specified name if it is already in use to a new remote object.

Unbind

public static void unbind(String name)

Removes the binding with specified name.

List

public static String[] list(String name)

Returns the array of name bound to the registry.

Lookup

public static Remote lookup(String name)

Returns the reference, a stub for the remote object associated with specific name.

Q539). What is the difference between RMI and Corba?

Ans. RMI and CORBA are very similar technologies with slightly different goals.

CORBA is a robust distributed object standard that allows for language inter-operability. RMI, on the other hand, was built for very simple distributed object communication in Java. While RMI does not contain CORBA’s cross-language support, it is well suited for pure Java development due to Java specific features such as distributed garbage collection.

Although RMI and CORBA are similar in nature, they have historically been incompatible technologies. When you program code with Java RMI, you need to write your code to the RMI application. Similarly, when you program code with CORBA, you need to write your code to he CORBA application. This is terrible for code reuse. If you write code in either in RMI or CORBA, you’ll need to re write major pieces of your code if you want to switch networking technologies.

When you receive an object using Java RMI, you can simply cast it into the desired object using a Java cast. This is possible because RMI automatically downloads the appropriate stub for the object you’re dealing with. CORBA, however, does not have a mechanism for automatic stub downloading.

RMI gives you an automatic way of cleaning up objects over the network with a distributed garbage collector. CORBA on the other hand has no such mechanism, because not every language that CORBA maps to even has the concept of asynchronous garbace collection.

Q 541 : RMI vs CORBA

Ans: Comparing RMI and CORBA doesn't reveal an optimum solution - one is not "better" than the other. The properties of these two technologies lend themselves to different situations. A comparison of RMI and CORBA helps to highlight individual strengths and weaknesses, but the applicability of one technology over the other depends largely on the purposes for which it is to be used, the experience of the developers who will design, implement and maintain the distributed system, and whether non-Java systems are intended to access the system now or in the future.

RMI pros and cons

Remote method invocation has significant features that CORBA doesn't possess - most notably the ability to send new objects (code and data) across a network, and for foreign virtual machines to seamlessly handle the new objects (Reilly, D). Remote method invocation has been available since JDK 1.02, and so many developers are familiar with the way this technology works, and organizations may already have systems using RMI. Its chief limitation, however, is that it is limited to Java Virtual Machines, and cannot interface with other languages.

Remote method invocation

Pros

Cons

Portable across many platforms

Tied only to platforms with Java support

Can introduce new code to foreign JVMs

Security threats with remote code execution, and limitations on functionality enforced by security restrictions

Java developers may already have experience with RMI (available since JDK1.02)

Learning curve for developers that have no RMI experience is comparable with CORBA

Existing systems may already use RMI - the cost and time to convert to a new technology may be prohibitive

Can only operate with Java systems - no support for legacy systems written in C++, Ada, Fortran, Cobol, and others (including future languages).

CORBA pros and cons

CORBA is gaining strong support from developers, because of its ease of use, functionality, and portability across language and platform (Reilly, D). CORBA is particularly important in large organizations, where many systems must interact with each other, and legacy systems can't yet be retired. CORBA provides the connection between one language and platform and another - its only limitation is that a language must have a CORBA implementation written for it. CORBA also appears to have a performance increase over RMI, which makes it an attractive option for systems that are accessed by users who require real-time interaction (Morgan, 1997).

Common Object Request Broker Architecture

Pros

Cons

Services can be written in many different languages, executed on many different platforms, and accessed by any language with an interface definition language (IDL) mapping.

Describing services require the use of an interface definition language (IDL) which must be learned. Implementing or using services require an IDL mapping to your required language - writing one for a language that isn't supported would take a large amount of work.

With IDL, the interface is clearly separated from implementation, and developers can create different implementations based on the same interface.

IDL to language mapping tools create code stubs based on the interface - some tools may not integrate new changes with existing code.

CORBA supports primitive data types, and a wide range of data structures, as parameters

CORBA does not support the transfer of objects, or code.

CORBA is ideally suited to use with legacy systems, and to ensure that applications written now will be accessible in the future.

The future is uncertain - if CORBA fails to achieve sufficient adoption by industry, then CORBA implementations become the legacy systems.

CORBA is an easy way to link objects and systems together

Some training is still required, and CORBA specifications are still in a state of flux.

CORBA systems may offer greater performance

Not all classes of applications need real-time performance, and speed may be traded off against ease of use for pure Java systems.

Q 542 : How can you download stubs from remote object?

Ans :

1. . Define the remote interface.

    import java.rmi.*;
    
    public interface RObject extends Remote {
        void aMethod() throws RemoteException;
    }

2. Define the remote object implementation.

    import java.rmi.*;
    import java.rmi.server.UnicastRemoteObject;
    
    public class RObjectImpl extends UnicastRemoteObject implements RObject {
        public RObjectImpl() throws RemoteException {
            super();
        }
        // All remote methods must throw RemoteException
        public void aMethod() throws RemoteException {
        }
    }

3. Compile the remote object implementation.

    > javac RObject.java RObjectImpl.java

4. Generate the skeletons and stubs.

    > rmic RObjectImpl
 

5. Create an instance of the remote object and bind it to the RMI registry.

    try {
        RObject robj = new RObjectImpl();
        Naming.rebind("//localhost/RObjectServer", robj);
    } catch (MalformedURLException e) {
    } catch (UnknownHostException e) {
    } catch (RemoteException e) {
    }

Q 543 : How will you pass parameters in RMI ? why you serialize?

Ans : Arguments to remote methods must be primitive, serializable, or implement Remote. This example demonstrates the declaration and use of all three parameter types.

1. Define the remote interface.

    import java.rmi.*;
    
    public interface RObject extends Remote {
        // This parameter is primitive.
        void primitiveArg(int num) throws RemoteException;
    
        // This parameter implements Serializable.
        void byValueArg(Integer num) throws RemoteException;
    
        // This parameter implements Remote.
        void byRefArg(ArgObject arg) throws RemoteException;
    }
    
    public interface ArgObject extends Remote {
        int aMethod() throws RemoteException;
    }

2. Define the remote object implementation.

    import java.rmi.*;
    import java.rmi.server.UnicastRemoteObject;
    
    public class RObjectImpl extends UnicastRemoteObject implements RObject {
        public RObjectImpl() throws RemoteException {
            super();
        }
        public void primitiveArg(int num) throws RemoteException {
        }
        public void byValueArg(Integer num) throws RemoteException {
        }
        public void byRefArg(ArgObject arg) throws RemoteException {
        }
    }

3. Compile the remote object implementation.

    > javac RObject.java RObjectImpl.java

4. Generate the skeletons and stubs.

    > rmic RObjectImpl
 

5. Create an instance of the remote object and bind it to the RMI registry.

    try {
        RObject robj = new RObjectImpl();
        Naming.rebind("//localhost/RObjectServer", robj);
    } catch (MalformedURLException e) {
    } catch (UnknownHostException e) {
    } catch (RemoteException e) {
    }

6. Look up the remote object and pass the parameters.

    try {
        // Look up the remote object
        RObject robj = (RObject) Naming.lookup("//localhost/RObjectServer");
    
        // Pass a primitive value as argument
        robj.primitiveArg(1998);
    
        // Pass a serializable object as argument
        robj.byValueArg(new Integer(9)