Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
KARNATAKA STATE OPEN UNIVERSITY I Semester M.SC(IT) Examination, S.2014 ADVANCED JAVA Time: 3 Hours Max. Marks: 75 SECTION A ANSWER THE QUESTIONS: 1. Define URL and UDP. 2. Write any three AWT controls used in Java. 3. What is the method of setting the paint mode? 4. What is a Swing Class? 5. What is the Java Servlet API? SECTION B ATTEMPT ANY TWO QUESTIONS: 6. What are the benefits of Enterprise Beans? 7. Compare Servlet to CGI applications. Servlet Programs that use standard Java interfaces such as JDBC. Programs that use HTTP session maintenance or cookies. Complex or resource-intensive Java programs. CGI program Programs that need low-level access to system resources. Programs that interface with another product through a non-Java API. 8. What is meant by HTTP Servlet? Give an example. SECTION B ATTEMPT ANY TWO QUESTIONS: 9. What are JDBC layers? 10. What are the main reasons to use JSP? 11. Expand the following: a. executeUpdate() b. getURL() c. getUserName() d. getDatabaseProductVersion() PART – B (10x5=50) 1. Explain the usage of reserved sockets in client/server system. This example introduces you to Java socket programming. The server listens for a connection. When a connection is established by a client. The client can send data. In the current example the client sends the message "Hi my server". To terminate the connection, the client sends the message "bye". Then the server sends the message "bye" too. Finally the connection is ended and the server waits for an other connection. The two programs should be runned in the same machine. however if you want to run them in two different machines, you may simply change the adress "localhost" by the IP adress of the machine where you will run the server. The server import java.io.*; import java.net.*; public class Provider{ ServerSocket providerSocket; Socket connection = null; ObjectOutputStream out; ObjectInputStream in; String message; Provider(){} void run() { try{ //1. creating a server socket providerSocket = new ServerSocket(2004, 10); //2. Wait for connection System.out.println("Waiting for connection"); connection = providerSocket.accept(); System.out.println("Connection received from " + connection.getInetAddress().getHostName()); //3. get Input and Output streams out = new ObjectOutputStream(connection.getOutputStream()); out.flush(); in = new ObjectInputStream(connection.getInputStream()); sendMessage("Connection successful"); //4. The two parts communicate via the input nd output streams do{ try{ message = (String)in.readObject(); System.out.println("client>" + message); if (message.equals("bye")) sendMessage("bye"); } catch(ClassNotFoundException classnot){ System.err.println("Data received in unknown format"); } }while(!message.equals("bye")); } catch(IOException ioException){ ioException.printStackTrace(); } finally{ //4: Closing connection try{ in.close(); out.close(); providerSocket.close(); } catch(IOException ioException){ ioException.printStackTrace(); } } } void sendMessage(String msg) { try{ out.writeObject(msg); out.flush(); System.out.println("server>" + msg); } catch(IOException ioException){ ioException.printStackTrace(); } } public static void main(String args[]) { Provider server = new Provider(); while(true){ server.run(); } } } 2. What is the structure of component class? Explain with diagram. Type Structure Diagram Usage A Component diagram has a higher level of abstraction than a Class Diagram. Each component usually contains bunch of classes and represents relatively independent piece of software, which can be updated and (or) purchased apart from other parts of the system. Single component is displayed as a box shape with special icon in top right corner. Alternatively, you can use the «component» keyword . Components are connected through required and implemented interfaces, often using the ball-and-socket notation. Each component can be decomposed by using Composite Structure Diagram just as any class from Class Diagram. 3. Explain the swing class hierarchy with diagram. Swing brought a huge improvement in the GUI with new capabilities that ranged from buttons with user selected icons to checkboxes to tables with multiple columns and rows. The Look & Feel, that is, the color scheme and design, of the components could also be customized. See Sun's Visual Index to the Swing Components for a look at the great variety of components available. Swing and came as part of the Java Foundation Classes (JFC) set of packages that also include : Pluggable Look & Feel - the style of the components, such as their color scheme and design, can be customized and can look the same regardless of the platform. Accessibility API - modifies the interface for easier use by the disabled. Drag and Drop - provides for moving data between Java programs and other programs running on the native host. Java2D - an expanded set of drawing tools. These work within both the Swing and AWT components. We will discuss some basic Java2D techniques in the Chapter 6: Supplements. The Swing classes build upon the lower level classes of the original AWT (java.awt) graphics packages. As the diagram shows below, the Swing user interface components, which always begin with the letter "J", extend from theContainer and Component classes. The JComponent subclasses are lightweight (see AWT page), so they essentially run within a single heavyweight high level component, such as JFrame and JDialog, and draw and re-draw themselves completely within Java, no native code peer components involved. Combined with the event handling process described in Chapter 7: Java, Swing components provide very flexible and elaborate GUI tools. One can also develop custom components in a straight forward manner by extended eitherJComponent or one of its subclass components. It is now generally recommended that everyone switch their Java user interface design from AWT to Swing for all serious program development for PC and equivalent platforms. 4. Explain Java .net package with a diagram. A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality. A package provides a unique namespace for the types it contains. Classes in the same package can access each other's package-access members. with the system Business Processing A package housing classes responsible for implementing business functionality Data A package housing classes responsible for implementing data storage functionality Packages allow us to partition our system into logical groups and then to relate these logical groups; otherwise, it could become overwhelming to work with every class and its relationship at once. A package is shown as a large rectangle with a small rectangle or "tab" attached to its top, left side. The packages in the previous list, together with their relationships, are shown in Figure Introduction Many times when we get a chance to work on a small project, one thing we intend to do is to put all java files into one single directory. It is quick, easy and harmless. However if our small project gets bigger, and the number of files is increasing, putting all these files into the same directory would be a nightmare for us. In java we can avoid this sort of problem by using Packages. Packages are nothing more than the way we organize files into different directories according to their functionality, usability as well as category they should belong to. An obvious example of packaging is the JDK package from SUN (java.xxx.yyy) as shown below: Figure 1. Basic structure of JDK package Basically, files in one directory (or package) would have different functionality from those of another directory. For example, files in java.io package do something related to I/O, but files in java.net package give us the way to deal with the Network. In GUI applications, it's quite common for us to see a directory with a name "ui" (user interface), meaning that this directory keeps files related to the presentation part of the application. On the other hand, we would see a directory called "engine", which stores all files related to the core functionality of the application instead. Packaging also help us to avoid class name collision when we use the same class name as that of others. For example, if we have a class name called "Vector", its name would crash with the Vector class from JDK. However, this never happens because JDK use java.util as a package name for the Vector class (java.util.Vector). So our Vector class can be named as "Vector" or we can put it into another package like com.mycompany.Vector without fighting with anyone. The benefits of using package reflect the ease of maintenance, organization, and increase collaboration among developers. Understanding the concept of package will also help us manage and use files stored in jar files in more efficient ways. How to create a package Suppose we have a file called HelloWorld.java, and we want to put this file in a package world. First thing we have to do is to specify the keywordpackage with the name of the package we want to use (world in our case) on top of our source file, before the code that defines the real classes in the package, as shown in our HelloWorld class below: // only comment can be here package world; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } 5. What are the steps in running RMI system? The Java Remote Method Invocation Application Programming Interface (API), or Java RMI, is a Java API that performs the object-oriented equivalent of remote procedure calls (RPC). 1. The original implementation depends on Java Virtual Machine (JVM) class representation mechanisms and it thus only supports making calls from one JVM to another. The protocol underlying this Java-only implementation is known as Java Remote Method Protocol (JRMP). 2. In order to support code running in a non-JVM context, a CORBA version was later developed. Usage of the term RMI may denote solely the programming interface or may signify both the API and JRMP, whereas the term RMI-IIOP (read: RMI over IIOP) denotes the RMI interface delegating most of the functionality to the supporting CORBA implementation. Steps to creation of an RMI system: The short version 1) Create an interface. (in this case, the interface is myRMIInterface.java). 2) Create a class that implements the interface. (in this case, myRMIImpl.java). 3) Create a server that creates an instance of this class 4) Create a client that connects to the server object using Naming.lookup() 5) Compile these classes. 6) Run the RMI interface compiler on the .class file of the implementation class (in this case, you'd say "rmic myRMIImpl"). 7) Start the RMI registry (on Windows NT/95, say "start rmiregistry"). 8) Start the server class ("start java myRMIServer"). 9) Run the client program ("java myRMIClient"). 6. Discuss the steps used to group components within one area of applet or frame. The applet is implemented as a button that brings up the window showing the components. The window is necessary because the program includes a menu, and menus can be used only in windows. Here, for the curious, is the source code for the window that displays the components. (The Using Components lesson will show and explain examples of using each component.) The program has both an Applet subclass and a main() method, so it can run either as an applet or as an application. The program uses the AppletButton class to provide an applet framework for the window. The AWT provides two types of containers, both implemented as subclasses of the Container class (which is a Component subclass). TheWindow subclasses -Dialog, FileDialog, and Frame -- provide windows to contain components. Panels group components within an area of an existing window. The example program uses a Panel to group the label and the text area, another Panel to group them with a canvas, and a third Panel to group the text field, button, checkbox, and pop-up list of choices. All these Panels are grouped by the Applet object, since the Applet class is a subclass of Panel. The example program uses a Frame to hold the Menu and List. (Frames create normal, fullfledged windows, as opposed to the windows that Dialogs create, which are dependent on Frames and can be modal.) When the program is run as an application, then the main()method creates a Frame to hold the Applet. Finally, when you select the "File dialog..." item in the menu, the program creates a FileDialog object, which is a Dialog that can be either an Open or a Save dialog. Applets cannot read or write files on the host unless the host specifically marks those files or their directory as readable or writable respectively. Applets cannot make network connections except to the host they came from. Applets cannot start any program on the host that is executing them. Windows that an applet opens look different than other windows. They have additional text warning that they are untrusted applet windows. Additional restrictions can be made by enhancing the SecurityManager class (inheriting from it and overriding its methods so that they are sufficiently secure). 7. Discuss the compatibility of JDBC and Java data types. With the exception of the data types listed in Unsupported JDBC Features, the Ingres JDBC Driver supports conversion of Ingres data values into Java/JDBC values as required by the JDBC specification. Because Ingres does not support all the JDBC data types, the following conventions are used when sending Java/JDBC parameters to the DBMS: NULL Generally, NULL values sent to the DBMS are associated with the data type provided in the setNULL() or setObject() method call or the data type implied by the setXXX() method call. A generic or typeless NULL value can be sent to the DBMS using one of the following method calls: setNull( idx, Types.NULL ) setObject( idx, null ) setObject( idx, null, Types.NULL ) BOOLEAN Boolean values are sent to the DBMS as single byte integers with the value 0 or 1. BIGINT Long values are sent to the DBMS as DECIMAL (if supported by the DBMS) or DOUBLE values when BIGINT is not supported by the DBMS. DECIMAL BigDecimal values are sent as DOUBLE values when DECIMAL is not supported by the DBMS. Avoid using the BigDecimal constructor that takes a parameter of type double. This constructor can produce decimal values that exceed the scale/precision supported by Ingres. JDBC programmers will normally not need to concern themselves with the actual SQL type names used by a target database. Most of the time JDBC programmers will be programming against existing database tables, and they need not concern themselves with the exact SQL type names that were used to create these tables. JDBC defines a set of generic SQL type identifiers in the class java.sql.Types. These types have been designed to represent the most commonly used SQL types. In programming with the JDBC API, programmers will normally be able to use these JDBC types to reference generic SQL types, without having to be concerned about the exact SQL type name used by the target database. These JDBC types are fully described in the next section. The one major place where programmers may need to use SQL type names is in the SQL CREATE TABLE statement when they are creating a new database table. In this case programmers must take care to use SQL type names that are supported by their target databases. The table "JDBC Types Mapped to Database-specific SQL Types" on page 111 provides some suggestions for suitable SQL type names to be used for JDBC types for some of the major databases. We recommend that you consult your database documentation if you need exact definitions of the behavior of the various SQL types on a particular database. The JDBC types CHAR, VARCHAR, and LONGVARCHAR are closely related. CHAR represents a small, fixed-length character string, VARCHAR represents a small, variable-length character string, and LONGVARCHAR represents a large, variable-length character string. The SQL CHAR type corresponding to JDBC CHAR is defined in SQL-92 and is supported by all the major databases. It takes a parameter that specifies the string length. Thus CHAR(12) defines a 12character string. All the major databases support CHAR lengths up to at least 254 characters. The SQL VARCHAR type corresponding to JDBC VARCHAR is defined in SQL-92 and is supported by all the major databases. It takes a parameter that specifies the maximum length of the string. Thus VARCHAR(12) defines a string whose length may be up to 12 characters. All the major databases support VARCHAR lengths up to 254 characters. When a string value is assigned to a VARCHAR variable, the database remembers the length of the assigned string and on a SELECT, it will return the exact original string. 8. Explain the weblogic support for Oracle. Integrates effortlessly with other Oracle products through Oracle GridLink for RAC, Oracle Enterprise Grid Messaging, and other connection technologies Optimized for Oracle Exalogic Elastic Cloud, the world’s first and only engineered system for cloud computing Tested and tuned by Oracle to provide the best foundation for Java applications, Oracle applications, and other enterprise applications to run with blazing performance Includes Oracle WebLogic Server 12c, which is certified for the full Java EE 6 platform specification and has improved integration with Oracle Real Application Clusters (Oracle RAC) Oracle WebLogic Portal, formerly BEA WebLogic Portal, is the best-of-breed portal framework for creating highly interactive composite applications in a SOA environment with a powerful, integrated set of design-time tools for Java developers and strong support for standards. Oracle WebLogic Portal's framework provides reliable, performant, and personalized application delivery that engages customers, keeps infrastructure costs down, delivers solutions rapidly, and standardizes application architecture. The integrated development environment provided by WebLogic Portal includes a rich, graphical environment for developing portal-based solutions. Web-based configuration tools, content publication wizards, and other run-time tools enable distributed portal management. Once built, your portals can be readily adapted when your business needs change, all at significantly lower costs. Thanks to its unified portal framework, simplified portal lifecycle mangement, and modular portal business services and portal extensions, Oracle WebLogic Portal simplifies, personalizes, and lowers the cost of customer, partner, and employee access to information, applications, and business processes. Oracle has acquired BEA Systems, Inc., a leading provider of enterprise application infrastructure solutions. The addition of BEA is expected to accelerate innovation by bringing together two companies with a common vision of a modern service-oriented architecture (SOA) infrastructure and to further increase the value that Oracle delivers to its customers and partners. Together, Oracle and BEA provide a complementary best-in-class middleware portfolio that spans Java Application Servers, transaction processing monitors, SOA and business process management, user interaction and Web 2.0, identity management, business intelligence, enterprise content management and vertical-specific technologies.