NEWS & UPDATES >> BCA BCSP064 Synopsis & Project Work Started for DEC 2017, IGNOU MCA MCSP060 Synopsis Work Started for DEC 2017, CONTACT 4 IGNOU Mini Project
Showing posts with label JAVA-JSP-Applet. Show all posts
Showing posts with label JAVA-JSP-Applet. Show all posts

IGNOU BCA MCA - PROJECT VIVA Question Answer for JAVA - JSP Part XIV

IGNOU BCA MCA - PROJECT VIVA Question Answer for JAVA - JSP

JAVA - JSP Selected Question Answer - PART XIV

DATABASE CONNECTION WITH JAVA & MY SQL


116. Data base connection code example in java with my sql
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

// Notice, do not import com.mysql.jdbc.*
// or you will have problems!

public class LoadDriver {
    public static void main(String[] args) {
        try {
            // The newInstance() call is a work around for some
            // broken Java implementations

            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (Exception ex) {
            // handle the error
        }
    }
}

This example shows how you can obtain a Connection instance from the DriverManager. There are a few different signatures for the getConnection() method. Consult the API documentation that comes with your JDK for more specific information on how to use them.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
 
Connection conn = null;
...
try {
    conn =
       DriverManager.getConnection("jdbc:mysql://localhost/test?" +
                                   "user=monty&password=greatsqldb");
 
    // Do something with the Connection
 
   ...
} catch (SQLException ex) {
    // handle any errors
    System.out.println("SQLException: " + ex.getMessage());
    System.out.println("SQLState: " + ex.getSQLState());
    System.out.println("VendorError: " + ex.getErrorCode());
}

DATABASE CONNECTION WITH JAVA & MY ACCESS

116. Data base connection code example in java with Ms Access
 It is quiet easy to connect MS Access database through java program. Before proceeding with the program, let me explain some basic concepts used in this program.

Class.forName

              
This causes the driver class to dynamically load at  runtime and it causes the driver to get initialized and returns the class object associated with it. If the driver used is correct then the static intializer of the class can be invoked to get the connection. Rest stuffs are self explanatory.
import java.sql.*;
public class UserLogin {
public static void main(String[] args) {
try {
// Load MS accces driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 
// C:\\databaseFileName.accdb" - location of your database 
String url = "jdbc:odbc:Driver={Microsoft Access Driver 
(*.mdb, *.accdb)};DBQ=" + "C:\\bank.accdb";
 
// specify url, username, pasword - make sure these are valid 
Connection conn = DriverManager.getConnection(url, "username", "password");
 
System.out.println("Connection Succesfull");
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
 
}}}


IGNOU BCA MCA - PROJECT VIVA Question Answer for JAVA - JSP Part XIII

IGNOU BCA MCA - PROJECT VIVA Question Answer for JAVA - JSP

JAVA - JSP Selected Question Answer - PART XIII


110. What are Directives ? What are the different types of Directives available in JSP ? Directives are instructions that are processed by the JSP engine, when the page is compiled to a servlet. Directives are used to set page-level instructions, insert data from external files, and specify custom tag libraries. Directives are defined between < %@ and % >.The different types of directives are shown below:
·         Include directive: it is used to include a file and merges the content of the file with the current page.
·         Page directive: it is used to define specific attributes in the JSP page, like error page and buffer.
·         Taglib: it is used to declare a custom tag library which is used in the page.

111. What are JSP actions ? JSP actions use constructs in XML syntax to control the behavior of the servlet engine. JSP actions are executed when a JSP page is requested. They can be dynamically inserted into a file, re-use JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.Some of the available actions are listed below:
·         jsp:include – includes a file, when the JSP page is requested.
·         jsp:useBean – finds or instantiates a JavaBean.
·         jsp:setProperty – sets the property of a JavaBean.
·         jsp:getProperty – gets the property of a JavaBean.
·         jsp:forward – forwards the requester to a new page.
·         jsp:plugin – generates browser-specific code.

112. What are Scriptlets ? In Java Server Pages (JSP) technology, a scriptlet is a piece of Java-code embedded in a JSP page. The scriptlet is everything inside the tags. Between these tags, a user can add any valid scriplet.

113. What are Decalarations ? Declarations are similar to variable declarations in Java. Declarations are used to declare variables for subsequent use in expressions or scriptlets. To add a declaration, you must use the sequences to enclose your declarations.

114. What are Expressions ? A JSP expression is used to insert the value of a scripting language expression, converted into a string, into the data stream returned to the client, by the web server. Expressions are defined between <% = and %>tags.

115. What is meant by implicit objects and what are they ? JSP implicit objects are those Java objects that the JSP Container makes available to developers in each page. A developer can call them directly, without being explicitly declared. JSP Implicit Objects are also called pre-defined variables.The following objects are considered implicit in a JSP page:
·         application
·         page
·         request
·         response
·         session
·         exception
·         out
·         config

·         pageContext

IGNOU BCA MCA - VIVA Question Answer for JAVA - JSP Part XII

IGNOU BCA MCA - VIVA Question Answer for JAVA - JSP

JAVA - JSP Selected Question Answer - PART XII

101. What is the structure of the HTTP response ? The HTTP response consists of three parts:
·         Status Code: describes the status of the response. It can be used to check if the request has been successfully completed. In case the request failed, the status code can be used to find out the reason behind the failure. If your servlet does not return a status code, the success status code, HttpServletResponse.SC_OK, is returned by default.
·         HTTP Headers: they contain more information about the response. For example, the headers may specify the date/time after which the response is considered stale, or the form of encoding used to safely transfer the entity to the user. 
·         Body: it contains the content of the response. The body may contain HTML code, an image, etc. The body consists of the data bytes transmitted in an HTTP transaction message immediately following the headers.

102. What is a cookie ? What is the difference between session and cookie ? A cookie is a bit of information that the Web server sends to the browser. The browser stores the cookies for each Web server in a local file. In a future request, the browser, along with the request, sends all stored cookies for that specific Web server.The differences between session and a cookie are the following:
·         The session should work, regardless of the settings on the client browser. The client may have chosen to disable cookies. However, the sessions still work, as the client has no ability to disable them in the server side.
·         The session and cookies also differ in the amount of information the can store. The HTTP session is capable of storing any Java object, while a cookie can only store String objects.

103. Which protocol will be used by browser and servlet to communicate ? The browser communicates with a servlet by using the HTTP protocol.

104. What is HTTP Tunneling ? HTTP Tunneling is a technique by which, communications performed using various network protocols are encapsulated using the HTTP or HTTPS protocols. The HTTP protocol therefore acts as a wrapper for a channel that the network protocol being tunneled uses to communicate. The masking of other protocol requests as HTTP requests is HTTP Tunneling.

105. What’s the difference between sendRedirect and forward methods ? The sendRedirect method creates a new request, while the forward method just forwards a request to a new target. The previous request scope objects are not available after a redirect, because it results in a new request. On the other hand, the previous request scope objects are available after forwarding. FInally, in general, the sendRedirect method is considered to be slower compare to the forward method.

106. What is URL Encoding and URL Decoding ? The URL encoding procedure is responsible for replacing all the spaces and every other extra special character of a URL, into their corresponding Hex representation. In correspondence, URL decoding is the exact opposite procedure.
JSP
107. What is a JSP Page ? A Java Server Page (JSP) is a text document that contains two types of text: static data and JSP elements. Static data can be expressed in any text-based format, such as HTML or XML. JSP is a technology that mixes static content with dynamically-generated content. 

108. How are the JSP requests handled ? On the arrival of a JSP request, the browser first requests a page with a .jsp extension. Then, the Web server reads the request and using the JSP compiler, the Web server converts the JSP page into a servlet class. Notice that the JSP file is compiled only on the first request of the page, or if the JSP file has changed.The generated servlet class is invoked, in order to handle the browser’s request. Once the execution of the request is over, the servlet sends a response back to the client. 

109. What are the advantages of JSP ? The advantages of using the JSP technology are shown below:
·         JSP pages are dynamically compiled into servlets and thus, the developers can easily make updates to presentation code.
·         JSP pages can be pre-compiled.
·         JSP pages can be easily combined to static templates, including HTML or XML fragments, with code that generates dynamic content.
·         Developers can offer customized JSP tag libraries that page authors access using an XML-like syntax.

·         Developers can make logic changes at the component level, without editing the individual pages that use the application’s logic.

IGNOU BCA MCA Students - VIVA Question Answer for JAVA Servlet Part XI

IGNOU BCA MCA Students - VIVA Question Answer for JAVA Servlet

JAVA Servlet Selected Question Answer - PART XI


91. What is a Servlet ? The servlet is a Java programming language class used to process client requests and generate dynamic web content. Servlets are mostly used to process or store data submitted by an HTML form, provide dynamic content and manage state information that does not exist in the stateless HTTP protocol.

92. Explain the architechure of a Servlet. The core abstraction that must be implemented by all servlets is the javax.servlet.Servlet interface. Each servlet must implement it either directly or indirectly, either by extending javax.servlet.GenericServlet or javax.servlet.http.HTTPServlet. Finally, each servlet is able to serve multiple requests in parallel using multithreading.

93. What is the difference between an Applet and a Servlet ? An Applet is a client side java program that runs within a Web browser on the client machine. On the other hand, a servlet is a server side component that runs on the web server.An applet can use the user interface classes, while a servlet does not have a user interface. Instead, a servlet waits for client’s HTTP requests and generates a response in every request.

94. What is the difference between GenericServlet and HttpServlet ? GenericServlet is a generalized and protocol-independent servlet that implements the Servlet and ServletConfig interfaces. Those servlets extending the GenericServlet class shall override the service method. Finally, in order to develop an HTTP servlet for use on the Web that serves requests using the HTTP protocol, your servlet must extend the HttpServlet instead. Check Servlet examples here.

95. Explain the life cycle of a Servlet. On every client’s request, the Servlet Engine loads the servlets and invokes its init methods, in order for the servlet to be initialized. Then, the Servlet object handles all subsequent requests coming from that client, by invoking the service method for each request separately. Finally, the servlet is removed by calling the server’s destroy method.

96. What is the difference between doGet() and doPost() ? doGET: The GET method appends the name-value pairs on the request’s URL. Thus, there is a limit on the number of characters and subsequently on the number of values that can be used in a client’s request. Furthermore, the values of the request are made visible and thus, sensitive information must not be passed in that way. doPOST: The POST method overcomes the limit imposed by the GET request, by sending the values of the request inside its body. Also, there is no limitations on the number of values to be sent across. Finally, the sensitive information passed through a POST request is not visible to an external client.

97. What is meant by a Web Application ? A Web application is a dynamic extension of a Web or application server. There are two types of web applications: presentation-oriented and service-oriented. A presentation-oriented Web application generates interactive web pages, which contain various types of markup language and dynamic content in response to requests. On the other hand, a service-oriented web application implements the endpoint of a web service. In general, a Web application can be seen as a collection of servlets installed under a specific subset of the server’s URL namespace.

98. What is a Server Side Include (SSI) ? Server Side Includes (SSI) is a simple interpreted server-side scripting language, used almost exclusively for the Web, and is embedded with a servlet tag. The most frequent use of SSI is to include the contents of one or more files into a Web page on a Web server. When a Web page is accessed by a browser, the Web server replaces the servlet tag in that Web page with the hyper text generated by the corresponding servlet.

99. What is Servlet Chaining ? Servlet Chaining is the method where the output of one servlet is sent to a second servlet. The output of the second servlet can be sent to a third servlet, and so on. The last servlet in the chain is responsible for sending the response to the client.

100. How do you find out what client machine is making a request to your servlet ? The ServletRequest class has functions for finding out the IP address or host name of the client machine. getRemoteAddr() gets the IP address of the client machine and getRemoteHost() gets the host name of the client machine. 

IGNOU BCA MCA Students - VIVA Question Answer for JAVA or JSP Part X

IGNOU BCA MCA Students - VIVA Question Answer for JAVA or JSP

JAVA or JSP Selected Question Answer - PART X

Remote Method Invocation (RMI)

78. What is RMI ? The Java Remote Method Invocation (Java RMI) is a Java API that performs the object-oriented equivalent of remote procedure calls (RPC), with support for direct transfer of serialized Java classes and distributed garbage collection. Remote Method Invocation (RMI) can also be seen as the process of activating a method on a remotely running object. RMI offers location transparency because a user feels that a method is executed on a locally running object. Check some RMI Tips here.

79. What is the basic principle of RMI architecture ? The RMI architecture is based on a very important principle which states that the definition of the behavior and the implementation of that behavior, are separate concepts. RMI allows the code that defines the behavior and the code that implements the behavior to remain separate and to run on separate JVMs.

80. What are the layers of RMI Architecture ? The RMI architecture consists of the following layers:
·         Stub and Skeleton layer: This layer lies just beneath the view of the developer. This layer is responsible for intercepting method calls made by the client to the interface and redirect these calls to a remote RMI Service.
·         Remote Reference Layer: The second layer of the RMI architecture deals with the interpretation of references made from the client to the server’s remote objects. This layer interprets and manages references made from clients to the remote service objects. The connection is a one-to-one (unicast) link.
·         Transport layer: This layer is responsible for connecting the two JVM participating in the service. This layer is based on TCP/IP connections between machines in a network. It provides basic connectivity, as well as some firewall penetration strategies.

81. What is the role of Remote Interface in RMI ? The Remote interface serves to identify interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface. A class that implements a remote interface should declare the remote interfaces being implemented, define the constructor for each remote object and provide an implementation for each remote method in all remote interfaces.

82. What is the role of the java.rmi.Naming Class ? The java.rmi.Naming class provides methods for storing and obtaining references to remote objects in the remote object registry. Each method of the Naming class takes as one of its arguments a name that is a String in URL format.

83. What is meant by binding in RMI ? Binding is the process of associating or registering a name for a remote object, which can be used at a later time, in order to look up that remote object. A remote object can be associated with a name using the bind or rebind methods of the Naming class.

84. What is the difference between using bind() and rebind() methods of Naming Class ? The bind method bind is responsible for binding the specified name to a remote object, while the rebind method is responsible for rebinding the specified name to a new remote object. In case a binding exists for that name, the binding is replaced.

85. What are the steps involved to make work a RMI program ? The following steps must be involved in order for a RMI program to work properly:
·         Compilation of all source files.
·         Generatation of the stubs using rmic.
·         Start the rmiregistry.
·         Start the RMIServer.
·         Run the client program.

86. What is the role of stub in RMI ? A stub for a remote object acts as a client’s local representative or proxy for the remote object. The caller invokes a method on the local stub, which is responsible for executing the method on the remote object. When a stub’s method is invoked, it undergoes the following steps:
·         It initiates a connection to the remote JVM containing the remote object.
·         It marshals the parameters to the remote JVM.
·         It waits for the result of the method invocation and execution.
·         It unmarshals the return value or an exception if the method has not been successfully executed.
·         It returns the value to the caller.

87. What is DGC ? And how does it work ? DGC stands for Distributed Garbage Collection. Remote Method Invocation (RMI) uses DGC for automatic garbage collection. Since RMI involves remote object references across JVM’s, garbage collection can be quite difficult. DGC uses a reference counting algorithm to provide automatic memory management for remote objects.

88. What is the purpose of using RMISecurityManager in RMI ? RMISecurityManager provides a security manager that can be used by RMI applications, which use downloaded code. The class loader of RMI will not download any classes from remote locations, if the security manager has not been set.

89. Explain Marshalling and demarshalling. When an application wants to pass its memory objects across a network to another host or persist it to storage, the in-memory representation must be converted to a suitable format. This process is called marshalling and the revert operation is called demarshalling.


90. Explain Serialization and Deserialization. Java provides a mechanism, called object serialization where an object can be represented as a sequence of bytes and includes the object’s data, as well as information about the object’s type, and the types of data stored in the object. Thus, serialization can be seen as a way of flattening objects, in order to be stored on disk, and later, read back and reconstituted. Deserialisation is the reverse process of converting an object from its flattened state to a live object.