Featured

    Featured Posts

MDU B.Tech First year Sample Papers All Semesters Papers Free download


MDU B.E/B.Tech Sample Papers in PDF Download Here

Download free sample papers of MDU B.E/B.Tech 1st year common semester solved papers.  All the previous solved sample papers can be downloaded from here with the links provided.

1. Essentials Of Communication 1st Semester Solved Sample Paper.
2. Fundamentals Of Computer Programming Solved Sample Papers.
3. Manufacturing Process Solved Sample Papers.
4. Engineering Physics I Solved Sample Papers
5. Engineering Mathematics 1 Solved Sample Papers.
6. Engineering Chemistry Solved Sample Papers.


MDU BE/B.Tech 2nd Semester Solved Sample Papers.  Previous Year MDU BE/B.Tech Solved Sample Papers.  Shortcut to prepare for your semester exams.
  1. Engineering Physics 2 Solved Sample Paper.
  2. Engineering Mathematics 2nd Solved Sample Paper.
  3. Communication Skills in English Solved Sample Paper.
  4. Elements Of Mechanical Engineering Solved Sample Paper.
  5. Electrical Technology Solved Sample Papers.
  6. Basics Of Electronics Solved Sample Papers.

MDU B.E/B.Tech Previous Year Solved Sample Papers

 

MDU B.Tech Sample Papers, Download All Year MDU B.Tech Previous Year Solved Question Papers

  Here you will find all the previous years solved sample papers.  We will keep posting the latest papers timely.  So keep in touch with us guys for more updates.


MDU B.E/B.Tech Sample Papers for All Branches and All Semesters

1. First Year Common Subjects Sample Papers
2. Information Technology.
3. Computer Sc. and Engineering.
4. Mechanical Engineering.
5. Electronics & Communication Engineering.
6. Electrical Engineering.
7. Electronics & Electrical Engineering.


INTEGRATED DEVELOPMENT ENVIRONMENT FOR VISUAL BASIC (IDE)

One of the most significant changes in visual basic 6.0 is Integrated Development Environment.
    IDE is a term commonly used in the programming world to describe the interface and environment that we use to create our application.
       It is called integrated because we can access virtually all the development tools that we need from one screen called an interface.
The Visual Basic IDE is made up of a number of components :->
1.  Menu Bar.
2.  Tool Bar.
3.  Project Explorer.
4.  Properties windows.
5.  Form Layout Window.
6.  Tool Box.
7.  Form Designer.
8.  Object browser.
                

1. Menu Bar

        The menu bar displaying the commands that we are required to build an application.  The main menu items have sub menu items that can be chosen when needed.  Various menus available in menu bar are File, Edit, View, Project etc.

2. Tool Bar

        The standard tool bar :-> The standard tool bar appears just below the menu bar and contains tools for openings and saving, files, cutting, copying, pasting and a variety of other commands.
  The toolbar in the menu bar provide quick access to the commonly used commands and a button in the toolbar is clicked one to carryout the actions represented by it.

3. Project Explorer

       The project explorer is docked in the right side of the screen, just under the tool bar.
The project explorer serves as a quick reference to the various elements of a project namely form, classes and modules.  All of the objects that make up the  application are packed in a project.
     A simple project will typically contains one form which is a window that is designed as part of a program interface.
       It is possible to develop any no. of forms for us in a program.  In addition to forms, the project explorer window also lists code modules and classes.

4. Properties Window

       The properties window is docked under the project explorer window.  The properties window exposes the various properties/ characteristics of a selected objects.  Each and every form in an application  is considered as an object.  Now, each object in VB has characteristics such as color and size other characteristics affect not just the appearance of the object but the way it behaves too.  All these characteristics of an object are called its properties.
      Thus,  form has properties and any controls placed on it will have properties too.

5. Object Browser

      The Object Browser allows us to browse through the various properties, events and methods that are made available to us.  It is accessed by selecting object browser from the view menu or by pressing the key F2.  The left column of the object browser lists the objects classes that are available in the projects that are opened and the controls that are opened are referenced in them.  After an object from the classes list, we can see its members( properties, methods and events) in the right column.
                                 

6. Tool Box

       The Toolbox contains a set of controls that are used to place on a form at design time thereby creating the user interface area.
      Additional controls can be included in the toolbox by using component menus item on the project menu.
Various controls available in the Toolbox are:-.>
1. The pointer provides a way to move and resize the controls and forms.
2. Label displays a text that the user cannot modify or interact with.
3. Check box displays a true/false or yes/no options.
4. Text box is a control used to display message and enter text.
5. The list box display a list of items from which a user can select one.
6. Combo box contains a text box and a list box.  Thus allows the user to select an item from the drop down list box or to type the in a selection in the text box.
7. H scrollbar and V scrollbar controls allow the user to select a value within the specified range of values.
8. Timer control executes the time events at specified intervals of time.
9. OLE control is used to link or embedded an object, display and manipulate data from other window based application.
10. Command button carries out the specified action when the clicks it.
11. Line controls draws a straight line to the form.

7. Form Layout Window

        The Form layout window appears at the right side of the screen just below the properties window.  This gives information about where the form will appear on the screen.

8. Form Designer

        The form designer as the name indicates is used to design forms.  The various controls such as textboxes, buttons, and labels can be placed on a form depending on the requirement of an application.

Storage Management in Programming Language
Programming Languages Concepts 
Subprogram Sequence Control in Programming language. 
Structured Sequence Control in Programmig language 
Sequence Control with in Statements 
Implicit and Explicit sequence Control 
Difference between C language and C++ language.


INTEGRATED DEVELOPMENT (IDE) FOR VC++

Integrated Development (IDE) for VC++ :->

    The integrated development environment for VC++ consists of the following :->

1.  The workspace.
2.  The output pane.
3.  The editor area.
4.  Menu bar & tool bar.

The work space :->

       When you start visual c++ for the first time, an area on the left side of screen is known as the workspace.  It is also known as viewer windows.
     This area is a key to navigating the various pieces and parts of your development projects.
     The workspace allows you to view the parts of your application in three different ways :-

1.  Class View :->

       Class view allows you to navigate and manipulate your source code on a c++ class level.

2. Resource view :->

       Resource view allows you to find and edit each of the various resources in your application, including dialog window designs icons and menus.

3.File view :-> 

        File view allows you to view and navigate all the files that make up your application.


The output pane :->

       The output pane is also known as Result window appears at the bottom of the screen.
The output pane might not be visible when you start VC++ for the first time.  After you compile your application, it appears at the bottom of the screen and remains open until you choose to close it.
     The output pane is where you see all the compiler progress, statements, warnings and error message and where the VC++ debugger displays all the code.  After you close the output pane, it reopens itself when VC++ has any message that it needs to display for you.

The Editor Area :->

          The area on the right side of the screen is the editor area.  This is the area where you perform all your editing when using VC++.
It is the area :->
-> Where the code editor window displays when you edit C++ source code.
-> Where the window pointer displays when you design a dialog box.
  The editor area is basically the entire area that is not otherwise occupied by the passes ( work space pane and output pane menus or toolbars )

Menu bars and Tool bars :->

       The menu bar appears just below the tittle bar.  The menu bar is where we  find various menus like file, edit, view, insert, project etc.

1.  The Standard Toolbar :->

      It contains most of the standard tools for opening and saving files, writing, copying, pasting & a variety of other commands.

2.  The Wizard bar Toolbar :->

       It enables you to perform a number of class wizard actions without opening the class wizard.

3. The Build mini Bar :->

       It provides you with the build & run commands that you are most likely to use as you develop and test your applications.

Event Oriented Language

Event Oriented Languages :->

     In the traditional programming approach the actions are carried out in a prescribed order.  This is the order which is specified by the programmer (i.e the order of execution is determined internally within the program).  But in event-oriented programming each feature in the program is activated only when the user responds to a corresponding object (i.e either by clicking the mouse or by pressing a key).

    The user actions such as clicking the mouse or pressing a key are referred to as events and the code that responds to a particular event is known as event handler.

    The languages that support  events are called event-oriented languages such as VC++, VB, VB.NET and JAVA.

     In event-driven programming  the sequence of operations for an applications is determined by the user's interaction with the applications interface (forms, menus, buttons etc.).  The code for an event-driven application remains in the background until certain events happen.  So with event-driven programs the user dictates the order of program execution not the programmer.  Instead the program "driving" the user, the user "drives" the program.

     All the windows programs are event-driven.  This means that programs respond to user actions called events.  Such as clicking the mouse, striking a key and so on.  Each time such an event occurs the corresponding method (event handler) is called in our program.  In this way, the whole program is broken up into bite sized methods responding various windows events.

MDU ADVANCE JAVA Dec 2016 CSE-404-F SAMPLE PAPER





Q.1. Explain the following with examples :           (20)
(a) Control statements in in JAVA.
(b) Multithreading in JAVA.
Ans. (a) Control statements in JAVA : Java programs is a set of statements that either executes sequentially or in the order in which they appear. There may arise situations in which a program breaks the normal sequential flow and jumps to another part of the code. This condition is called branching.  Branching can either be conditional or unconditional. Conditional branching occurs on a particular situation or a statement in the program code while unconditional branching occurs without any particular decision. Java deals with different control and iterative statements listed below. The control statements are :
(i) if-else loop
(ii) switch statement
(iii) while loop
(iv) do-while loop
(v) for loop
(i) if-else loop : It is a powerful decision making statement that is used to control the flow of execution of statements. The syntax for if loop is :
if (expression)
(ii) Switch Statement : Switch is an another decision-making statement that can be used as an alternative to if statement. It is a special multi-way decision maker that checks whether an expression matches one of the given values. The syntax is:
switch (expression )
{
case value 1:
statement 11;
statement 12;
break;
case value 2:
statement 21;
statement 22;
break;
.
.
.
case value n :
statement n;
break;
default:
statement;
}
(ii) While loop : While loop is used when we are not sure if a loop will execute or not. If the condition is true, then loop will continue until the condition satisfies.
Its syntax is:
while (expression)
{
    //Block of statements;
}
(iv) do-while loop : do-while loop is a repetitive loop supported by Java. It's an exit condition loop i.e. the set of statement will execute first, and then at the exit time the condition will be checked for repetition. If the condition return true then the loop will re-execute the statements otherwise it will terminate.
Its syntax is:
do
{
    Block of statements
    .............
}      while (expression)
(v) for loop : for loop is the simplest loop in Java. It contains three expressions :
- initial expression : used to initialize the counter of the loop
- termination expression : used to give a termination condition on the loop
- steps expression : used to either increase or decrease the value of the counter
All above three expressions are optional, according to need of the logic, we will add in for loop.
The syntax for loop is :
for (initial expression; termination expression; steps expression)
{
   Body of the loop;
}


(b) Multithreading in JAVA : A thread is a stream of code execution. This means that a single program can perform more than one task at the same time. Thread-based multitasking deals with the application program. A thread can be loosely defined as a separate stream of execution that takes place simultaneously. Every thread has a name for identification.
Initially, when a Java program starts, it has only one thread, i.e. main thread. Threads can be created in two ways : one method is to create a class as the subclass of thread class. The example related to the first method is explained :
class New_Thread extends Thread
{
   New_Thread()
{
  start();
}
Public void exec ()
{
   \\ Block of code
}
}
We can create and start a thread of this type as :
New_Thread th1 = new New_Thread();
Another method to create a thread is to declare a class that implements a Runnable interface. The example related to this method explained below:
class New_Thread implements Runnables
{
  Thread th1;
   New_Thread()
{
th1 = new Thread (this, "Second");    //this is used to pass class reference
thread start();
}
public void exec()
{
  //Block of code
}
}
This code would then create a thread and start it as :
New_Thread th1 = new New_Thread ();

States of a Thread : A thread is a small part of the process dedicated to perform certain job. The process has its own lifecycle, & at any instant of time a process will be in any of the state. Similarly, a thread will also have a life cycle & will be in any of the following state at any instant of time :
(i) New Thread
(ii) Runnable
(iii) Blocked
(iv) Waiting
(v) Terminated
The figure shows five states of the thread.

             figure             States of a Thread

  1. New State : When a thread object is created, a thread is born. This state is called New state. At this stage, the new thread can start & move to Runnable state or this new thread can be killed immediately. Then it is called Dead thread. 
  2. Runnable : It means that the thread is ready for execution and is waiting for the availability of the processor for execution.  
  3. Blocked : A thread is in a blocked state when it is not allowed to enter the Runnable state.  This can happen when a thread is either suspended or sleeping.  At this stage, the thread is not considered dead. 
  4. Waiting : This is the state when a thread is waiting for the processor either to its newborn state or due to to the round-robin scheduling of the processor. 
  5. Terminated : A thread is considered terminated when it has been killed.




Q.2. How servers are implemented ? Give suitable example of advanced socket programming.    (20)
Ans. To implement networking in Java, java.net package classes, these give access to IP address, & a range of methods related to TCP, UDP, & URL, I/O stream classes are also used to read and write data from and to communication channel.
The virtual-stream supports IO stream to transport data from & to either of the connection. There are two important classes, participates in communication. InetAddress class using to provides IP address of target connection.  Socket class using to creates TCP connection.  Once a connection has been created, we bind the both end socket with their streams, and communication will start by writing & reading data on these streams to and from remote application.
     Before looking at how to implement to server, let's have a look on the classes of java.net that are used to implement a server, are given below :
(i) Class InetAddress : Computer on internet is identified by IP address, that is currently in two version with different size, in IPv4 it is 32-bit long and in IPv6 it is 128-bit long.  InetAddress provides an abstraction to access IP address.

fig here

There is no constructor of this class.  The class provides some static methods to create the instance of the class i.e. an object.

(ii) Class Server Socket :  The ServerSocket class provides the facility by which a server accepts a connections requested from clients across the network.  The class creates a Socket for individual client connection.  After socket creation, an InputStream and an OutputStream will be created for communicating with client.

Fig. ServerScocket

The fundamental mechanism for implementing a server is to open a ServerSocket with a specific and certain local port number.  The ServerSocket will start to wait for connection.  As client generates the request to connect to this port, the connection will be established.
           ServerSocket is constructed by choosing a port on the local machine. This port number should be in the range 1-65536; however, ports 1-1023 are reserved for system services and can be used only by the machine administrator.
         A server accepts the explicitly connection request from a ServerSocket to obtain a client's Socket connection. As the ServerSocket is created, operating system started to accept the connections from clients, & insert in a queue, & delete one-by-one as the server call the accept() method.
ServerSocket(int portNumber) throws IOException creates a ServerSocket that listen on the specified port portNumber and countValue specified the number of outstanding connection requests.
ServerSocket ssckt = new ServerSocket(1889,40);

(iii) Class Socket : A Socket represents a TCP connection with a machine on network.  This class facilitate in establishing the stream-based channel with a remote machine.
 For TCP/IP communication, there is a need to create a Socket with the remote machine. The class Socket class creates a socket & automatically established a TCP connection, & throws an exception if it fails.  Socket address is the combination of two components : one is host id, which can be referring with the host name. IP address, and the port number.  The port no. is an integer value lie between 1 & 65536.  In fact, on every host there are 65536 different addresses.  But there must be a server, and dynamically listening on the specified port.

                                                        Fig. Socket

There are two constructor of the Socket class.  Creating a Socket object automatically connects to the given host and port.
Socket(String hostName, int portNumber) throws IOException creates a Socket object and connects to the given host on the given port number.
Socket sckt = new Scoket("mymac", 1889);
Socket(InetAddress hostAddress, int portNumber) throws IOException creates a Socket Object and connects to the given host address on the given port number.

InetAddress mac =  InetAddress.getByName("127.0.0.1");
Socket sckt   =  new Socket(mac.getAddress, 1889);
Socket sckt  = new Scoket ( mac.getAddress, 1889);
OR Socket sckt = new Socket " 127.0.0.1",1889);


Example of advantage socket programming
// Create a socket without a timeout
try {
        InetAddress addr = InetAddress.getByName("java.sun.com");
        int port = 80;
// This constructor will block until the connection succeeds
Socket socket = new Socket( addr, port);
}catch ( UnknownHostException e ) {
} catch ( IOException e ) {
}
// Create a socket with a timeout
try {
       InetAddress addr = InetAddress.getByName("java.sun.com");
       int port = 80 ;
       SocketAddress sockaddr = new InetSocketAddress (addr, port);
// Create an unbound socket
Socket sock = new Socket ();
// This method will block no more than timeoutMs.
// If the timeout occurs, SocketTimeoutException thrown.
int timeoutMs = 2000 ;   //2 seconds
sock.connect (sockaddr, timeoutMs);
} catch ( UnknownHostException e) {
} catch ( SocketTimeoutException e) {
} catch ( IOException e) {
}

Q.3. Explain the following :
(a) Design of JDBC
(b) LDAP.                      (20)
Ans. (a) Design of JDBC : JDBC is a set of Java API for executing SQL statements.  It's a collection of classes and interfaces : those facilitate to easy of the database & perform operations on the database.  Just by using few methods calls, we can easily interact with database.  The program design a good GUI interface then with knowing back processing of the database, without writing complex SQL statement, communication with database will become effortless.
      Types of JDBC Drivers :  There are various vendors of DBMS. Each vendor provides own API's (vendor specific APIs) to interact with Database.  It's a big problem to the developer to handle all these.  It has removed the need to access native APIs of specific vendor; it's the responsibility of the intermediate layer to make the native calls.

Figure Types of JDBC drivers

1. JDBC-ODBC Bridge-Type 1 : The type 1 driver provides a bridge between the JDBC API and the ODBC API.  The bridge is responsible to convert the JDBC calls to the corresponding ODBC calls and finally request to data source using ODBC libraries, that must be required on client tier.

Fig Type 1 driver

J2SE contains the classes for the JDBC-ODBC bridge & so that there is no need to install any other packages.  Though, you have to create Data Source Name (DNS) using ODBC manager.

2.  Native-API Partly Java Driver-Type 2 : Type 2 driver works on a combination of vendor-specific and Java implemented APIs to communicate with data source.  Here, the client makes the JDBC calls & these calls are interpreted into vendor-specific APIs, finally from vendor-specific APIs to database to perform the operation on it.  Database process the request & send the results back through the vendor-specific API, which will be forwarded back to the JDBC driver.  Now, here JDBC driver will convert the response to the JDBC standards and send to Java application.  The driver can be used where there is the need of, high-performance and large transaction volume.
Type 2 driver fig.


3. JDBC-Net Pure Java Driver-Type 3 : The type 3 driver works as middleware server between a numbers of Java clients to multiple vendor databases.  Type 2 is a multitier and vendor-neutral driver.  To connect with database server, client (Java client application) uses a server component in-between the client and database, that works as a gateway for multiple database servers.  The client application sends the request to intermediate data access server, by making the JDBC call through a JDBC driver.  The intermediate data access server completes the request to the Database using native driver.
Type 3 driver....fig.

4. Native-protocol Pure Java Driver-Type 4 :- Type 4 drivers converts JDBC API request directly to networking protocols of vendor-specific.  By making the socket connections with databse they communicate with database.  There is no need of other libraries or any middleware interface to deploy it.
Type 4 driver fig.

b) LDAP : The lightweight Directory Access Protocol(LDAP) was developed in the early 1990s as a standard directory protocol. LDAP is now probably the most popular directory protocol & because JNDI can access LADP.
"LDAP defines the mechanism by which clients should be able access data on the server.  It does not however, gives details how the data should be stored on the server."
LADP uses the hierarchical tree structure to organize the data, called a Directory Information Tree(DIT).  In DIT each leaf is an entry, and the first entry is called root entry.
An entry contains a Distinguished(DN) & attributes-value pairs related to it.  The DN is a comprises the information how it is related to rest of the DIT, same as the Pathname shows how the file is related to rest of file system.
The path to a file on a system root to file. A DN reads right to left for example: uid=sujjain, oi=people, o=theweb.com  The leftmost part of a DN is called a Relative Distinguished Name(RDN) his example would be uid=scarter.
LADP attributes often use mnemonics as their names.
LADP servers have other following benefits:
  1. They support references pointers to other LDAP directories where data is stored.  So that just by one client request a single LDAP server could search milliones of entries.
  2. Reliability & speed is improved by replication of LDAP data.
  3. LDAP also has a exceptionally strong security model that contains.
  4. ACLs to protect data inside the server. 
  5. Secure Socket Layers(SSL).
  6. Trasport Layer Security(TSL).
  7. Simple Authentication & Security Layer (SASL) protocols.
Applications : There are basic three basic applications of LADP in Java today;
  1. Access Control
  2. White Pages Services
  3. Distributed Computing Directory.
LDAP Operations : Standard LADP Operations are as follows :
  • Connect to the LDAP server
  • Bind to the LDAP server
  • Search the server
  • Add a new entry
  • Modify an entry
  • Delete an entry
  • Disconnect from the LDAP server.
 

Q.4. What is the concept of :
a) Remote method invocation. 
b) Explain Java IDL.
 Ans. (a) Remote Method Invocation : Remote method invocation (RMI) frameworks provides a mechanism by which a Java object running in one JVM and call method of another Java object running in another JVM.  It provides object-to-object communication regardless of their location.  This allows an application to access and make the call to object method located remotely.
         In RMI jargon, the client object makes a remote call to the remote object located at server machine, called server object.  The computer running the application or a process that calls the remote method is called client, and the computer running the object that processes the call request from client, is called server.  If the server generates a remote call to an object resides on another machine JVM then the server becomes the client and the remote computer will become server.
       If we want two Java applications executing within different virtual machines to communicate with each other there are a couple of other Java-based approaches that can be taken besides RMI :
- Sockets
- Java Message Service(JMS)
       RMI is different with JMS in such a way that the object stays local at one JVM, but in JMSthe object (message) pass through across the network from one JVM to another JVM.
REMOTE METHOD INVOCATION FIG...

Architecture of RMI : Transparency is the one of the most important aspect of RMI designn. A method invocation on a remote has the same syntax as method invocation on a local object.  The RMI architecture supports to create a distributed application, in which one object call the method of remote object.
           Specifically, in RMI, the definition of a remote service is coded using a java interface.  The implementation of the remote service is coded in a class.  Therefore, the key to understanding RMI is to remember that interfces define behaviour and classes define implementation.
RMI system fig.
         The RMI architecture is high-level of abstraction.  It is constructed using three layer architecture.  The layered architecture gives a transparency for application architecture, mean implementation gives flexibility.
         The RMI is constructed using the following three abstract layers :
- The Stub-Skeleton Layer : The responsibility of this layer is to intercept and redirect the client request for method calls to remote object.
- The remote Reference Layer : It inter-prates and  manages between references, those are made by client to the remote object.
- Transport Layer : It provides the connectivity to machines.

Ans. (b) Java IDL : Java IDL (java Interface Definition Language) is a technology design for distributed objects; those are communicating with each other and running on different platform across the network.  It is similar to RMI but with one advantage that interaction among the object written in any programming language like C, C++ etc. including Java.
      IDL-Java Bridge Data Type Mapping : When data moves between IDL and a Java object, IDL automatically converts variable data types.
The java IDL, development Process are as know :
  1. Define the remote interface.
  2. Compile the remote interface.
  3. Implement the server.
  4. Implement the client.
  5. Start the applications.


Q.5. What are the progress indications? Explain. Wap implementing trees in JAVA. (20)
Ans. Progress indicators or progress bars are the new controls that gives the users some indications of the progress of an operation.  They were originally developed to cheek the progress of installation processes but are now frequently used for all time-consuming operations.  When we call JProgressBar, we can set the maximum and minimum value for the progress bar.  The inheritance diagram for JProgressBar class is as follow :
            

Java.lang.Object
                
Java.awt.Component
                
Java.awt.Container
                
Javax.swing.JComponent
                
Javax.swing.JProgressBar
               
Fig : Inheritance diagram for J Progress Bar

Table : Fields of JProgressBar class

Table : Constructors of JProgressBar class

Wap to implement trees in Java :
import Java.awt.*;
import Javax.swing.*;
import Javax.swing.tree.*;
import Java.awt.event.*;
public class SimpleTree extends JFrame {
public static void main(string[] args) {
new simple tree();
public SimpleTree() {
super("Creating a Simple JTree") ;
WindowUtilities.setNativeLookAndFeel() ;
addWindowListener(new ExitListener()) ;
Container content = getContentPane() ;
Object[] hierarchy = {"1. CHAPTER 1",
new Object[] { "1.1 INTRODUCTION TO JAVA",
"1.1.1 History of JAVA",
"1.1.2 JAVA and Internet",
"1.1.3 JAVA Virtual Machine",
"1.1.4 JAVA's Magic : The Byte Code",
"1.1.5 Features of JAVA',
"1.1.6 JAVA Environment"},
new Object[]{ "1.2 DATA TYPES & OPERATORS"},
new Object[] { "1.3 ARRAYS",
"1.3.1 Declaration of Array Variables",
"1.3.2 Array Construction",
"1.3.3 Initialization of Array",
"1.3.4 Array Access",
"1.3.5 Arrays of Characters"},
new Object[] { "1.4 CONTROL STATEMENTS"},
new Object[] { "1.5 A SAMPLE PROGRAM IN JAVA"},
new Object[] { "1.6 CLASSES & METHODS",
"1.6.1 Constructor",
"1.6.2 Garbage Collection"},
new Object[] {"1.7 INHERITANCE",
"1.7.1 Single Inheritance",
"1.7.2 Multiple Inheritance",
"1.7.3 Multilevel Inheritance",
"1.7.4 Hybrid Inheritance",
new Object[] {"1.8 INTERFACE"},
new Object[] {"1.9 PACKAGES"},
new Object[] {"1.10 EXCEPTION HANDLING",
"1.10.1 try and catch with multiple catch clause,"
"1.10.2 throw and throws",
"1.10.3 finally"},
new Object[] {"1.11 MULTITHREADING",
"1.11.1 States of Thread"},
new Object[] {"1.12 COLLECTIONS"},
new Object[] {"1.13 I/O STREAMS",
"1.13.1 Working with InputStream and OutputStream",
"1.13.2 Working with Reader and Writer"},
new Object[] {"1.14 AWT"},
new Object[] {1.15 APPLET PROGRAMMING",
DefaultMutableTreeNode root = processHierarchy(hierarchy) ;
JTree tree = new JTree(root) ;
content.add(new JScrollPane(tree), BorderLayout.CENTER ;
setSize(275, 300) ;
setVisible(true) ;
}
private DefaultMutableTreeNode processHierarchy (object[] hierarchy) {
DefaultMutableTreeNode node = new
DefaultMutableTreeNode(hierarchy[0]) ;
DefaultMutableTreeNode child;
for(int i=1; i<hierarchy,length; i++) {
object nodeSpecifier = hierarchy[i] ;
if (nodSpecifier instanceofobject[])  // Ie node with children
child = processHierarchy((object[]) nodeSpecifier) ;
else
child = new DefaultMutableTreeNode(nodeSpecifier) ;  // le Leaf
node.add(child) ;
}
return(node) ;
}}
import Javax.swing.*;
import Java.awt.;
public class WindowUtilities {
public static void setNativeLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) ;
} catch(Exception e) {
System.out.println(" Error setting native LAF : " +e) ;
} }
public static void setJavaLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getCross PlatformLookAndFeelClassName());
} catch(Exception e) {
system.out.println("Error setting Java LAF : "+e) ;
} }
public static void setMotifLookAndFeel() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel") ;
} catch(Exception e) {
System.out.println("Error setting MotifLAF : "+e ) ;
}
  }
public static JFrame openInJFrame(Container content, int Width, int height, String title, Color bgColor) {
JFrame frame = new JFrame(title) ;
frame.setBackground(bgColor) ;
content.setBackground(bgColor);
frame.setSize(width, height);
frame.setContentPane(content) ;
frame.addWindowListener(new ExitListener() ) ;
frame.setVisible(true) ;
return(frame) ;
}
public static JFrame openInJFrame(Container content, int width, int height, String title ;
{
   return (openInJFrame( content, width, height, title, color.white ) ) ;
}
public static JFrame openInJFrame(Container content, int width, int height) {
  return(openInJFrame(content, width, height, content.getClass().getName(), Color.white)) ;
    }
}
import Java.awt.* ;
import Java.awt.event.* ;
public class ExitListner extends WindoAdapter {
public void windowClosing(WindowEvent event) {
System.exit(0) ;
   }
}
The output interface would look like :
Figure here---------



Q.6.Explain the following :
(a) Transparency and compositions    (20)
(b) Clipboard

Ans: (a) Transparency :-  Java 2D allows you to give transparency value to drawing operations, so that the graphic to be drawn, partially shows that underlying images.  AlphaComposite object has to create by Alphacomposite.getInstance to provide and set the transparency.  The object of AlphaComposite will be passed to setComposite method of Graphics2D object.  There are 8 built-in mixing rules, but the one normally used for drawing with transparency settings is AlphaComposite. SRC_OVER.  Alpha values range from 0.0F (completely transparent) to 1.0F (completely opaque).
Example :
import Java.awt.AlphaComposite ;
import Java.awt.Color ;
import Java.awt.Graphics ;
import java.awt.Graphics2D ;
import Java.swing.JFrame ;
import Java.swing.JPanel ;
public class TransparentRectangles extends Jpanel {
public void paint(Graphics g) {
super.paint(g) ;
Graphics2D g2d = (Graphics2D) g ;
g2d.setColor(Color.BLUE) ;
for (int i = 1; i<= 10; i++) {
g2d.setComposite(AlphaComposite.getInstance ( AlphaComposite.SRC_OVER, i*0. If)) ;
g2d.fillRect (50*i, 20, 40, 40) ;
    }
}
public static void main (String[] args) {
JFrame frame = new JFrame ("Transparent Rectangles") ;
frame.add(new TransparentRectangles() ) ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
frame.setSize(590, 120) ;
frame.setLocationRelativeTo(null) ;
frame.setVisible(true) ;
   }
}

Ans. (b) Clipboard : In Java, there are actually two kinds of Clipboard-system and local.  The system clipboard corresponds to the usual idea of sharing data between otherwise independent applications running on the same computer.  Local Clipboards are visible only with a single Java application.  They are created by simply passing a name of the Clipboard constructor. A clipboard acts as a temporary staging area where application users store cut or copied information, including text, graphics, objects, and other data types.  It is a heavily exploited data sharing facility.  Therefore, when developing new applications, it makes sense to expend extra effort to support the clipboard, Netlecting clipboard functionallity can resulting in an application that gets complaints, requires new development, or-worst of all-never gets used.


Q.7. What are bean ?  Explain the naming pattern for bean components with suitable example.
Ans.   Java Bean is a softwear component written in Java, provides portability, platform-independent component model, and re-usability.  You can add these components into applets, applications, or with other bean components.
By nature, beans are dynamic like other software components; these can be changed or customized.
The JavaBeans architecture was built through a collaborative industry effort and enables developers to write reusable components in the Java programming language.
With the Java Beans API you can create re useable, platform-independent components.
There are three types of benas:
  1. Visible Bean : A bean component that is visible to an end user, such as a button or any graphical component, that is used with GUI. 
  2. Invisible Bean : A bean that added with any application but not visible to the end user on GUI, for example checking the spelling of a document.  
  3. Container Bean : A bean can contain another bean component, is called the container bean for example a tree bean can contain another component like images, labels, etc.
The bean is created by combining the following components:
- Properties define the characteristics of the bean. It can be change at design time or run time if it is not read only and some mutator methods are given in its implementation.
- Events to momunicate with other beans.
- Methods can be called from other beans or from the environment or application in that it is  added.
Advantages of beans :  There are following advantages of Java Bean components:
  1. It supports or provide "write-once, run-anywhere" paradigm.
  2. Three component of the bean are exposed to an application builder tool.
  3. It has to run in different environment, so that, it is designed correctly.
  4. It's configuration setting is stored and helps to persist its state and can be used later.
  5. A Bean may receive events and can communicate with other by generating the events, if it is registered with events.
  • States of Bean :  Bean is a resusable software component.  So as software hs its development life cycle similarly bean component  has its own states.  These states defines its lifecycle, and are as following; 
  • Consturaction State : In this  state, the bean is under coding phase.  The developer busy in writing the code for it. 
  • Build State : Bean is in build state, where after construction, it is added with any application. 
  • Run State:  As the container application runs, then bean is in run state.

Characteristics of bean :
  1. Communication :  One bean can communicate with other bean and application in that it is build.  By message passing to method, it do communication. 
  2. Introspection :  It is an automatic process to analyze the properties, evens and methods.
  3. Persistance :  A bean persists by storing and retrieving the properties from storage.  The state of component to be stored in a non-volatile place for later retrieval. 
  4. Customizers : Modifiying the appearance and behaviour at the time of building, and run time.

Example :
import Java.awt.Graphics;
import Java.beans.PropertyChangeListener;
import Java.beans.PropertyChangeSupport;
import Java.io.Serializable;
import Javax.swing.JComponent;
public  class MyFirstBean extends JComponent implements Serializable
{
priavate String caption;
private final PropertyChangeSupport ob = new
PropertyChangeSupport( this );
public String getCaption()
{ return this.caption; }
public void setCaption ( String caption )
{
String oldcaption = this.caption;
this.caption = caption;
this.ob.firstPropertyChange( "caption", oldcaption, caption );
}
public void addPropertyChangeListener ( PropertyChngeListener listener )
{
this.ob.addPropertyChangeListener (listener);
}
public void removePropertyChangeListener ( PropertyChangeListener listener )
{
this.ob.removePropertyChangeListner (listnere);
}
protected void paintComponent ( Graphics g )
{
g.setColor ( getForeground()  );
int height = g.getFontMetrics ().getHeight ();
paintString ( g, this.caption, height  );
}
private void paintString ( Graphics g, String str, int height )
{  ( str != null )
g.drawString ( str, 0, height )
}
}


Q.8. Does Java has security constraints ? Explain byte code verification and code signing.  (20)
Ans.  Yes, Java has security constraints.
Byte code verification :  When a class loader presents the bytecodes of a newly loaded Java platform class to the virtual machine, the bytecodes are first inspected by a verifier.  All classes except system classes are verified.  We can deactivate verification with the undocumented-noverify option.  For exaple:
       java -noverify NewProgram
The bytecode verifier traverses the bytecodes, constructs the type state information, and verifies the types of the parameters to all the bytecode instructions.  The figure shows the flow of data and control from the source code to the class loader and bytecode verifier and finally on to the Java virtual machine, which contains the interpreter and runtime system.  The bytecode verifier acts gatekeeper as it ensures that code passed to the Java interpreter is in a good state to be executed and can run without the fear of breaking the Java interpreter.  Imported code is not allowed to execute by any means until after it has passed the verifier's tests.
           Once the verifier is done, a number of important properties are known.  Knowing these properties makes the Java interpreter much faster, because it doesn't have to check anything.  There are no operand type checks and no stack overflow checks.  The interpreter can thus function at full without compromising reliability.  The properties are :
> There are no operand stack overflows or underflows.
> The type of the parameters of all bytecode instructions are known to always be correct.  Object field accesses are known to be legal -- private, public or protected.

Flow of data and control.......fig.-----

           The verifier permits only some bytecode sequences in valid programs and the verifier ensures that any given instruction operates on a fixed stack location that allows the JIT compiler to transform stack accesses into fixed register accesses.  Due to this, the JVM does not imply a speed penalty for emulation on register-based architectures when using a JIT compiler.  In the face of the code-verified JVM archetecture, it makes no difference to a JIT compiler whether it gets named imaginary registers or imaginary stack positions that need to be allocated to the target architecture's registers.  Code verification makes the JVM different from a classic stack architecture whose efficient emulation with a JIT compiler is more complicated and is carried out by a slow interpreter.

   The following verification checks are performed by the bytecode verifier.  It verifies that
  • > The byte stream is either truncated nor padded with extra bytes.
  • > The class bytes adhere to the correct format for the class itself, methods, fields and other components.
  • > There are no overflows of operands on the stack.
  • > There are no underflows of operands on the stack.
  • > The proper access specifiers of methods and field variables is defined.
  • > final classes are not subclassed.
  • > final methods are not overridden.
  • > final variables are assigned an initial value and not modified.
  • > methods are invoked with the correct number and types of arguments.
  • > final variables of the class are assigned with values of the correct type.
  • > no local variables is accessed before it has an assigned value.
  • > the class has one superclass.

Code signing :  One of the most important uses of authentication technology is signing executable programs.  If a program is downloaded, then we are concerned about damage that a program can do.  For example, the program could have been infected by a virus.  If we know where the code comes from and that it has not been tempered then we can be comfortable in using the program.  For this, we use authentication to verify where the code came from and then run the code with  a security policy that enforces the permissions that you want to grant the program, depending on its origin.  The most common use of code signing is to provide security when deploying.  Almost every code signing implementation will provides some sort of digital signature mechanism to verify the identity of the author or build system, and a checksum to verify that the object has not been modified.  Code signing is done on JAR files.
              The Java Archive(JAR) file format enables you to pile multiple files into a single archive file.  A JAR file contains the class files and auxiliary resources associated with applets and applications.  The general steps involved with code signing process are :
  1. Compile the code to the signed into class files.
  2. Creates a JAR files.
  3. Sign the JAR file.
  4. Export a public key certificate.
          The Java application that wants to accept the code only from a trusted source that has signed the code follows these steps :
  1. Import the certificate as a trusted certificate.
  2. Create a policy file indicating that such a principal should be trusted for certain permissions.
  3. Load the trusted code with your Java application.

ADVANCE JAVA

 

 

ADVANCE JAVA

May 2009

Paper Code : CSE-404-E

Q.1. Explain the concept  of arrays in java with suitable program.  Also explain the inheritance and exception handling with examples.

Ans. Arrays :  An Arrays is a (fixed length) data structures used to store multiple data elements of same type.  The memory allocated to an array is consecutive. All the elements of an array are under one variable name.  Every data element of an array is accessed by its position and that position in indicated by an integer value that start from 0 called index.  The array size is fixed and cannot be changed at runtime of the program.
Java supports two types of arrays:
(i) One Dimensional Array.
(ii) Multiple Dimensional Array.

In Java, arrays can be of either types, primitive data types or reference types.  In primitive data type array, all elements are of a definite primitive data type.  In references type array all elements are of definite reference type.
Declaration of Array Variables : The syntax to declare either type of arrays , i.e. one -dimensional or multiple dimensional array is :
<data.type>[]  <array - name>;                 //One Dimensional Array
Or
<data.type>  <array - name>[];               //One Dimensional Array
Syntax to create an array:
<array - name> = new <data-type> [<array-size>];                //One dimensional Array

Initialization of Array : Initialization means to assign the value to the array at the time of constructing and declaring in one statement simultaneously.
<data - type> [] <array - name> = { <initial value list>};
For example :
int an_Array = {1,2,3,4,5,6,7,8,9 };                //One dimensional Array
for(int i=0;i<3;i++)
System.out.println(anArray[i]);      //Accessing ith index Value.
int matrix[] [] = {{1,2,3},{4,5,6,},{7,8,9}};      //Two dimensional Array
for (int i=0; i<3; i++)
{ for (int j=0; j=3; j++)
         System.out.print(matrix[i][j]);
System.out.println();
}

Inheritance : Inheritance is one of the most important and useful feature of object-oriented programming.  There is a main class, called base class or super class, from which a new class id derived, called derived class or sub class.  Base class is also called parent class and the derived class is called child class.  Inheritance provides a mechanism for deriving new classes from existing ones.  In OOP, ther are several type of mechanisms:
(1) Single Inheritance
(2) Multiple Inheritance
(3) Multilevel Inheritance
(4) Hybrid Inheritance

In Java a class can be derived from another class using the general form :
access_specifier class Subclass extends Superclass
{ //Derived class data and methods
}
Example:
class A {
int x;
int y;
int get(int p, int q) {
x = p; y = q; return(0);
}
void show() {
System.out.println(x);
}
}
class B extends A {
void showb() {
System.out.println("B");
}
}
class c extends B {
void display() {
System.out.println("C");
}
}
public static void main(strings args[]) {
A a = new A();
a.get(5,6);
a.show();
}
}
Exception Handling : An exception is a run-time error or an anomalous condition that arises in the program during run time. A Java exception is an object that describes an abnormal condition in the program code.  When an abnormal condition is encountered in the object code, an object representing that condition or exception is created an thrown in the method that caused the error.  The method can then make the choice to handle the exception itself or pass it on.  An exception may also be caught and processed.  Exception can also be manually generated by your program code. Exceptions thrown by Java programs are actually the errors that violate the constraints of Java runtime.  In Java, exception handling
- try
- catch
- throw
- throws
- finally
The program statements to be monitored for exceptions are kept within a 'try block'.  If an exception occurs in the 'try block', then it is thrown.  The statements that have to be thrown manually are kept in the 'catch block'.  System generated exceptions are automatically thrown by Java runtime environment.  The general form of exception handling is :
try
{      //block of code to be monitored
}
catch (Exception_TypeA obj)
{     //exception handler for Exception_TypeA
}
Finally
{       //block of code to be executed
}
All types of exceptions are the subclass of built-in class Throwable. Throwable contains two subclasses, one is exception for the abnormal conditions that the user programs must handle.  Exceptions include conditions like divide by zero.  This type of exception is called Arithmatic Exception.  Another subclass is error that contains the conditions that are not expected to be caught under normal conditions.
Example:
class Multiple_Catch
{
Public static void main(String args[])
{
try
{
int x=0;
int y=y/x;
int a[] = {6};
a[89] = 44;
}
catch (Arithmetic Exception e1)
{
System.out.println("ERROR : Divide by Zero" +e1);
}
catch (Array Index Of Bound Exception e2)
{
System.out.println("ERROR : Array out of Bound" +e2);
}
}
}

Q.2. Explain the concept of E-Mail server.

Ans. E-Mail server : A socket will be created, connect to port 25, which is SMTP port number.  Simple mail transfer Protocol describes the format in which e-mail message will be sent.  In UNIX OS, sendmail daemon was already implemented to support this features.

Example :
import Java.io.BufferedReader;
import Java.io.FileReader;
import Java.io.IOException;
import Java.io.InputStream;
import Java.io.InputStreamReader;
import Java.io.OutputStream;
import Java.io.OutputStreamWriter;
import Java.io.PrintWriter;
import Java.net.InetAddress;
import Java.net.Socket;
import Java.net.UnknownHostException;
public class SMTPDemo  {
public static void main (String args[] throws IOException, UnknownHostException  {
String msgFile = "file.txt";
String from = "java2s@java2s.com";
String to = "yourEmail@yourServer.com";
String mailHost = "yourHost";
SMTP mail = new SMTP(mailHost);
if(mail != null) {
if (mail.send(new FileReader (msgFile), from, to))    {
System.out.println("Mail sent.");
} else  {
System.out.println("Connect to SMTP sever failed !");
}
}
System.out.pritnln("Done");
}
static class SMTP   {
private final static int SMTP_PORT = 25;
Inetdderess mailHost;
Inetddress localHost;
BufferedReader in;
Public SMTP (String host) throws UnknownHostException  {
mailHost = InetAddress.getByName (host);
localHost = InetAddress.getLocalHost ( );
System.out.println("mailhost = "+ mailHost );
System.out.println("localhost = "+ localHost);
System.out.println("SMTP construtor done\n");
}
public boolean send (FileReader msgFileReader, String from, String to ) throws IOException   {
Socket smtpPipe;
InputStream inn;
OutputStream outt;
BufferedReader msg;
msg = new BufferedReader(msgFileReader);
smtpPipe = new Socket(mailHost, SMTP_PORT);
if (smtpPipe == null)  {
return false; }
inn = smtpPipe.getInputStream( );
outt = smtpPipe.getOutputStream( );
in = new BufferedReader(new InputStreamReader(inn));
out = new PrintWriter(new OutputStreamWriter(outt), true);
if (inn = = null \\ out= = null) {
System.out.println("Failed to open streams to socket.");
return false;
}
StringinitialID = in.read.Line( );
System,out.println(initialID);
System.out.println("HELO " + localhost.getHostName( ));
out.println("HELO " + localhost.getHostName( ));
String welcome = in.readLine ( );
System.out.println(welcome);
System.out.println("MAIL From:<" + from + ">");
out.println("MAIL From:<" + from + ">");
String senderOK = in.readLine( );
System.out.println(senderOK);
System,out.println("RCPT TO:<" + to + ">");
out.println("RCPT TO:<" + to + ">");
String RecipientOK = in.readLine( );
System.out.println(recipientOK);
System.out.println("DATA");
out.println("DATA");
String line;
While((line = msg.readLine ( )) != null )  {
out.println(line);
}
System.out.println(".");
out.println(".");
String acceptedOK = in.readLine( );
System.out.println(acceptedOK);
System.out.println("QUIT");
out.println("QUIT");
return true;
     }
   }
}

www.CodeNirvana.in

www.posthatke.com. Powered by Blogger.
Copyright © www.posthatke.com | Blogger Templates | Designed By posthatke.com