mi0041-javaandwebdesign

Upload: guru-vashist

Post on 07-Aug-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/21/2019 mi0041-javaandwebdesign

    1/12

    ASSIGNMENT

    DRIVE SPRING 2014

    PROGRAM MBA IT(SEM 4)

    SUBJECT CODE & NAME MI0041- JAVA AND WEB DESIGN

    BK ID B1327

    CREDITS 4

    MARKS 60

    Q. 1 Write down what the following tags will perform

    a.

    b.

    c. d.

    e.

    Answer: a. The HTML tables basically consist of three elements rows, columns and cells. These tables are powerfultools used in creating Web pages for providing precise structure or position to the content that you inserton the Web page.The most important function of table is to display text and numeric information in rows and columns.

    The next important use of tables is to place Web content for example, text, images and so on in individualtable cells. This enables you to organize the content properly on the Web page. Therefore, by organising

    the rows and columns of the Web page you can organize the entire Web page.

    It allows you to align text in tables. You can see an example of this on our Support page. How you do thisis start with and if you want borders, just use the below commands.

    Good

    b. To fix the width of the table we use the attribute width. For example:

    In the above code the entire width of the table is 200 pixels. You can vary the width by changing thevalue that you pass to the attribute.

    c. This HTML tag is used to add multimedia elements like video, audio, images and so on, on the Web page.

    Now let us learn how to use this tag to insert a multimedia file. The syntax show below explains how touse this tag.

  • 8/21/2019 mi0041-javaandwebdesign

    2/12

    In the above syntax you can see that we use the attribute "src" to pass the file name or the URL of the

    multimedia file which is mentioned using the term "value" in the syntax. The "value" can be a file nameor URL of the location of the file. If you use that file name you have to make sure that you also providethe extension of the file. The example code given below shows how to use the tag to insert animage with the file name "video.avi" which is a video file.

    d.

    This is a hyperlink tag. On the Web page if you want to include a hyperlink to a media file you can use

    this tag. Example:

    Text

    The above syntax shows how you can provide hyperlink to a media file. In the above syntax, the "value"is the Uniform Resource Locator (URL) or file name of the document that you want to link to and the

    "Text" can be a single word or sentence which is displayed on the Web page as a hyperlink to the "value".We need to know that the "value" can be a file of any format such as audio, video, graphic and so on. Youwill be able to link to that particular file and open it when you click on the hyperlinked text.

    e.

    The World Wide Web Consortium (W3C) recommended to use tag instead of tag to

    add multimedia files on to the Web page. This was because, most of the latest versions of the browserssupported only tag. The object element is created using the opening and closing tags,

    and . The below example code helps us to understand how to use the tag to insert themultimedia file on the Web page.

    You can see in the above code that we are using two attributes namely "data" and "type". These attributesare used to specify the file type. Where, the attribute "data" specifies the URL or file name that you wantto pass to the object. Similar to the attributes "href" and "src" used with and tags, here also

    we need to provide the file name along with the extension specifying the file format. The "type" attributespecifies the Multipurpose Internet Mail Extensions (MIME) type of the file that you refer in the "data"attribute. The MIME is an Internet standard that specifies the format of the data that you want totransferee. This standard has a collection of various media formats that the Internet supports for dataexchange via Internet. This can be text, images, audio, and video and so on.

    Q.2 Write short notes on

    a. Web browsers

    Answer: The World Wide Web created in 1990 was the first Web browser. However, later this namewas changed to Nexus to avoid confusion with the World Wide Web. Today, there are a number of Web

    browsers available in the market for example, the Internet Explores (IE), Firefox, Flock, Web 2.0, Safari,Opera, and so on.Let us now study the two main functions of a Web browser:

  • 8/21/2019 mi0041-javaandwebdesign

    3/12

    To make a request for a page from a computer. You can do this by typing the URL of the page inthe address field of the browser. Even when you click on a hyperlink the similar action that ofaccessing the Web page associated with the URL is performed by the browser.

    To interpret the HTML page sent back by the Web server. This is done because the HTML textreceived from the Web server is in the American Standard Code for Information Interchange(ASCII) form. The Web browser, after receiving this text interprets it and creates the page in itsoriginal form.

    A web browser (commonly referred to as a browser) is a software application for retrieving, presentingand traversing information resources on the World Wide Web. An information resource is identified by a

    Uniform Resource Identifier (URI/URL) and may be a web page, image, video or other piece of content.Hyperlinks present in resources enable users easily to navigate their browsers to related resources.

    Although browsers are primarily intended to use the World Wide Web, they can also be used to accessinformation provided by web servers in private networks or files in file systems.

    Figure shows the Microsofts Internet Explorer Web browser. The arrows point to the features that areavailable on the Web browser along with the name of the corresponding feature mentioned at the otherend of the arrow.

    Address f ield: This is the area on the browser window where you enter the Web page address orURL. At the right end of this area, there is a small arrow pointing towards the menu bar, whenyou click this arrow you will view a list of some of the Websites that you have visited recently.When you click on these URLs you will view the respective Website or else you can directlyenter the address in the address field. After you enter the address you can either press "Enter" or

    click on the "Go" button (which is present next to the downward facing arrow button in somebrowsers).

    Back and forward buttons: The back button is used to go back to the previous page that you haveopened in a particular browser window. The forward button allows you to view pages that you

  • 8/21/2019 mi0041-javaandwebdesign

    4/12

    have previously viewed in that browser window. In some browsers, there is a small arrowpointing towards the menu bar arrow right next to these buttons, when you click this arrow you

    will see the list of Websites that you have visited after opening the browser window.

    Home button: When you click this button you will be able to view the page that you have set ashome page. A home page is a default page that opens when you open the browser window.

    Menu bar: A menu bar is a part of each browser window, it contains menus like File, Edit, View,Favourites or Bookmarks, Tools and Help.

    Refr esh or reload: When you click the refresh or reload button, the page is updated. For example,if you think that the contents of a browser window may have changed since the last time youviewed it, you can click this button to update the page.

    Securi ty indicators: At the left corner of the window, a lock icon appears when you use abrowser and this is called padlock. If the padlock is in a lock position then you can say that your

    server connection is secure, i.e. the data being sent and received by the server is encrypted. Thisindicates that nobody else can access this data. There is another way to find out whether your

    browser is secure or not and that is done by looking at the URL. If the URL of your Websitebegins with "https://" for example, you enter an address "www.gofind.com" in the address field

    and press enter or click "Go" then automatically the address changes to"https://www.gofind.com" indicating that your browser connection is secure.

    Status bar: This is a bar at the bottom of the browser window which indicates the URL of theWeb page currently being loaded into the browser window. It also displays the URL of the linkon which the cursor of your mouse is placed. While loading, the Web page shows a progressindicator which shows how much percentage of a file has been downloaded.

    Stop button: This button is used to stop the browser from loading the Web page on to thebrowsing window.

    b. Web development tools:

    Web development tools allow web developers to test and debug their code. They are differentfrom website builders and IDEs in that they do not assist in the direct creation of a webpage,

    rather they are tools used for testing the user facing interface of a website or web application.

    Moreover Web development tools are software that enables you to design Web pages easily andefficiently. The Web development tools enable you, as a designer to design the Web page under

    controlled conditions within a short span of time. Let us not go for an in depth analysis of these tools but,we shall learn some of most popular tools that are used by the professional Web designers for creatingWeb pages.You can use Web development tools mainly for editing and viewing the Web page, testing the codeswritten using a mark-up language, and previewing the working of codes written before it is actually used

    on the platform for which it is designed.

    Let us now learn few popular tools that are used by Web designers:

    Dreamweaver: This Web development software tool was initially created byMacromedia and now it is a part of Adobe System. We can see that the initial versions ofthis tool comprised of simple HTML based editors. From the last 10 to 15 years

    Dreamweaver has been the most popular Web development tool that is used by the Web

  • 8/21/2019 mi0041-javaandwebdesign

    5/12

    developers. It currently holds 80% of the HTML editor market in the world and rated as

    the most preferred HTML editor.

    Frontpage: This is a product of Microsoft. You can use this tool for designing andediting Web pages. There is no need for you to learn HTML to use the Frontpage editor.

    This is because the editor creates or generates all the HTML tags and other features like

    CSS, frames and so on by itself. Using the Frontpage editor's HTML view you can entertext, edit HTML tags and also use the standard Microsoft Word commands such as Cut,Paste, Find and Replace, and so on. Therefore, using Frontpage editor for creating your

    Web page is as simple as creating a word document using Microsoft Word.

    Q.3 Write a programme to create a webpage that prints the name of the STUDENT database in

    Wide Latin font and set the subtitle with description of the STUDENT to the screen. Set the page

    layout to the webpage. Insert one image after the database with a Thank you note.

    Answer: Programme coding

    import java.awt.*;

    import java.awt.event.*;import java.sql.*;

    public class College implements ActionListener{Panel p;Frame f;

    Button b1,b2,b3,b4,b5,b6,b7;TextField tf1,tf2,tf3,tf4,tf5,tf6,tf7;Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15;GridLayout gl;Connection con;

    Statement st;

    String s1,s2,s3,s4,s5,s6,s7,sr1,sr2;TextArea ta1;College(){

    f=new Frame();p=new Panel();

    p.setBackground(Color.cyan);gl=new GridLayout(31,8,3,3);

    p.setLayout(gl);

    b1=new Button("Insert");b1.addActionListener(this);

    b2=new Button("Select");

    b2.addActionListener(this);b3=new Button("Select");b3.addActionListener(this);b4=new Button("Results");

    b4.addActionListener(this);b5=new Button("Select");b5.addActionListener(this);b6=new Button("Exam");b6.addActionListener(this);

  • 8/21/2019 mi0041-javaandwebdesign

    6/12

    b7=new Button("Submit");b7.addActionListener(this);

    tf1=new TextField(50);tf1.setBackground(Color.yellow);tf2=new TextField(10);tf2.setBackground(Color.yellow);

    tf3=new TextField(50);tf3.setBackground(Color.yellow);tf4=new TextField(20);tf4.setBackground(Color.yellow);tf5=new TextField(6);tf5.setBackground(Color.yellow);

    tf6=new TextField(10);tf6.setBackground(Color.yellow);

    tf7=new TextField(10);tf7.setBackground(Color.yellow);

    tf8=new TextField(10);tf8.setBackground(Color.yellow);

    ta1=new TextArea(10,2);l1=new Label("Enter student info");l2=new Label("Update student info");

    l3=new Label("View student info");l4=new Label("View results");l5=new Label("Delete student info");

    l6=new Label("View exam details");l7=new Label("Name");

    l8=new Label("Roll");l9=new Label("Address");l10=new Label("Phone");

    l11=new Label("E-Mail");

    l12=new Label("Gender");l13=new Label("Date of Birth");l14=new Label("Result");l15=new Label("Exam Details");

    p.add(l1);p.add(b1);p.add(l2);p.add(b2);p.add(l3);p.add(b3);p.add(l4);p.add(b4);p.add(l5);p.add(b5);p.add(l6);p.add(b6);

    p.add(l7);p.add(tf1);p.add(l8);p.add(tf2);p.add(l9);p.add(tf3);p.add(l10);p.add(tf4);p.add(l11);p.add(tf5);p.add(l12);p.add(tf6);p.add(l13);p.add(tf7);p.add(b7);p.add(l14);p.add(tf8);p.add(l15);p.add(ta1);f.add(p);

    f.setSize(100,200);f.setVisible(true);

    }

    public void actionPerformed(ActionEvent e){

    if(e.getSource()==b1)

    {try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");con=DriverManager.getConnection("jdbc:odbc:Avishek");

  • 8/21/2019 mi0041-javaandwebdesign

    7/12

    s1=tf1.getText();s2=tf2.getText();

    s3=tf3.getText();s4=tf4.getText();s5=tf5.getText();s6=tf6.getText();

    s7=tf7.getText();st=createStatement.executeQuery("insert into Table1 values(?,?,?,?,?,?,?)");st.setString(1,s1);st.setString(2,s2);st.setString(3,s3);st.setString(4,s4);

    st.setString(5,s5);st.setString(6,s6);

    st.setString(7,s7);st.executeUpdate();

    st.execute();st.close();

    }catch(Exception i){

    System.out.println("Error");}}

    if(e.getSource()==b2){

    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    con=DriverManager.getConnection("jdbc:odbc:Avishek");

    s1=tf1.getText();s2=tf2.getText();st=createStatement.executeQuery("update Table1 set Name=?"+"where Roll=?");st.setString(1,s1);

    st.setString(2,s2);st.executeUpdate();st.execute();st.close();}

    catch(Exception i){

    System.out.println("Error");

    }}if(e.getSource()==b3){

    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");con=DriverManager.getConnection("jdbc:odbc:Avishek");ResultSet rs=con.createStatement("Select * from Table1");

  • 8/21/2019 mi0041-javaandwebdesign

    8/12

    while(rs.next()){

    String s1=rs.Name;String s2=rs.Roll;String s3=rs.Address;String s4=rs.Phone;

    String s5=rs.E-Mail;String s6=rs.Gender;String s7=rs.Date Of Birth;tf1.setText(s1);tf2.setText(s2);tf3.setText(s3);

    tf4.setText(s4);tf5.setText(s5);

    tf6.setText(s6);tf7.setText(s7);

    }rs.close();

    }}catch(Exception i)

    {System.out.println("Error");}

    }if(e.getSource()==b4)

    {try{

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    con=DriverManager.getConnection("jdbc:odbc:Avishek");s2=tf2.getText();ResultSet rs1=con.createStatement("select from Result where SRoll=?");while(rs.next())

    {if(s2.equals(Roll)){String sr1=rs.SRoll;String sr2=rs.SResult;

    tf2.setText(sr1);tf8.setText(sr2);

    }

    }rs.close();}catch(Exception i)

    {System.out.println("Error");}}if(e.getSource()==b5)

  • 8/21/2019 mi0041-javaandwebdesign

    9/12

    {try

    {s2=tf2.getText();st=createStatement.executeQuery("delete from Somu where Roll=?");st.setString(2,Roll);

    st.executeUpdate();st.execute();st.close();}}catch(Exception i)

    {System.out.println("Error");

    }}

    if(e.getSource()==b6){

    String exam="\nB-Tech 1st sem starts 12.2.2010.\n"+"\nB-Com 1st sem starts 10.2.2010.\n"+"\nMBA 1st sem starts 15.2.2010.\n";

    ta1.setText(exam);}}

    public static void main(String args[]){

    College c=new College();}}

    Q4. a) Give reasons as to why ABC institute decided to choose XYZ Company for the development

    of Java application.

    Answer: ABC institute decided to choose XYZ for the development of Java application because theinstitute understood the importance of e-records. As it had already faced the problems in keeping hardcopy of the records. XYZ organization was well efficient in developing java based software so it waschosen. Other important reason was maintenance of records. It is very essential to keep records safe. Eachschool has a responsibility to maintain its records and record keeping systems. Although schools will

    have their own methods of creating and keeping records and sharing information with staff, students,parents and the general public, they should be aware that, in doing so, they need to take account of

    matters such as children names and their details with respective years.

    Easy to Start: Since Java programming language is completely based on object-orientedlanguage, it's easy very simple and easy to learn, especially for programmers already known withC or C++.

    Easy to write code: As compared to program metrics (class counts, method counts, and so on)tell us that a program written in the Java programming language can be four times smaller ascompare to the same program written in C++.

    Write better code: The Java programming language encourages good coding practices, andmanages automatic garbage collection which helps you avoid memory leaks. Based on the

  • 8/21/2019 mi0041-javaandwebdesign

    10/12

    concept of object orientation, its Java Beanscomponent architecture, and wide-range, easilyextendible, flexibility and API can reuse existing, tested code and introduce fewer bugs.

    Develop programs and Time Safer: The Java programming language is easier and simpler thanC++, as such, manages your development time up to twice as fast when writing in it. The

    programs will also require fewer lines of code.

    Platform Independencies: The program keeps portable and platform independent by avoidingthe use of libraries written in other languages.

    Write Once and Used in any Java Platform:Any Source code of Program are written in theJava programming language, that is compiled into machine-independent byte codes and runconsistently on any platform of java.

    Distribute software makes work easy: Using Java Web Start software, users will be able tolaunch own applications with a single click on mouse. An automatic version checks

    initially weather users are always up to date with the latest version of your software. If an updateis available for it, the Java Web Start software will automatically update their installation.

    Hence java application made by XYZ Company is necessary for ABC school for keeping records and

    make records secure, Interactive and can be used for various other purposes.

    b) Discuss the reasons for using JSP in java application.The use of JSP program to create dynamic Web pages by considering a simple program that embeds JSPwithin HTML program.

    The JSP codes are plain text documents that we can create using any text editor such as a notepad. Theyare like the HTML documents; however they have additional JSP elements or tags. Some of the mostcommon JSP elements are as follows:

    Action: We use this tag to add more functionality to our program. The syntax of action tag is asfollows:

    Directive: We use this tag to import java packages, to define the error handling pages or to definethe information related to session or JSP page. The syntax of directive tags is as follows:

    Declaration: We use this tag to define the functions and variables that need to be used in the JSPprogram. The syntax of directive tags is as follows:

    Scriplet: We use this tag to add java code. The syntax of scriplet tag is as follows:

    Expression: We use this tag to output any information on the Web page. The expression will beevaluated and included in the content sent back to the client. The syntax of expression tag is asfollows:

    Comment: We use this tag to give a brief explanation of the line or lines of code written.Comments are not visible to the client. The syntax of comment tag is as follows:

    Q.5 For the above case study answer the following questions

    a. State the reason for using database connection in the application.

  • 8/21/2019 mi0041-javaandwebdesign

    11/12

    Answer: Database connection is the means by which a database server and its client software

    communicate with each other. The term is used whether or not the client and the server are on

    different machines. The client uses a database connection to send commands to and receive replies

    from the server. A database is stored as a file or a set of files on magnetic disk or tape, optical disk, or

    some other secondary storage device. The information in these files may be broken down into records,each of which consists of one or more fields. Fields are the basic units of data storage, and each field

    typically contains information pertaining to one aspect or attribute of the entity described by the

    database. Records are also organized into tables that include information about relationships between

    its various fields. Although database is applied loosely to any collection of information in computer files,

    a database in the strict sense provides cross-referencing capabilities. Connections are a key concept

    indata-centric programming. Since someDBMS require considerable time to connect,connection

    pooling is used to improve performance. No command can be performed against a database without an

    "open and available" connection to it.

    Once a connection has been built, it can be opened and closed at will, and properties (such as the

    command time-out length, ortransaction,if one exists) can be set. The connection string consists of a set

    of key/value pairs, dictated by the data access interface of the data provider.

    In this application we use database to make a record by storing the student names and details. With thehelp of java we make application but to store the complete record we have to make a database to make a

    integration of data and make database which is connected to the application and provide the detailswhenever application required.

    b. Explain the purpose of creating a java application for the ABC institute.

    Answer: It is clear from above discussion that java application is important for ABC institute for keepingand maintaining its record and to collaborate with its other branches. Manual record maintenance is very

    tedious job and is not reliable.

    1. With the help of this application, staff and students can now take information directly by justlogging into the webpage of the institute.

    2. Java is one of the most popular programming languages used to create Web applications andplatforms. It was designed for flexibility, allowing users to work easily. Java has thrown outmany of the complex features of C++ and C resulting in a simpler language (no pointers, no

    unions, and no enumerations).

    3. Java is a single-root, single-inheritance object oriented language4. Using Java RMI (remote method invocation) you can access objects on other machines almost as

    if they were local5. Java is simple, easy to design, easy to write, and therefore easy to compile, debug, and learn thanany other programming languages.

    6. Java is object-oriented, that is used to build modular programs and reusable code in otherapplication.

    Q.6 How do you handle exception in java? Give with an example.

    Answer: A Java exception is nothing but an object that defines an exceptional condition, or an error thathas occurred in a piece of code. In Java, we can handle this exception by creating an object that represents

    http://en.wikipedia.org/w/index.php?title=Data-centric&action=edit&redlink=1http://en.wikipedia.org/wiki/Databasehttp://en.wikipedia.org/wiki/Connection_poolinghttp://en.wikipedia.org/wiki/Connection_poolinghttp://en.wikipedia.org/wiki/Database_transactionhttp://en.wikipedia.org/wiki/Database_transactionhttp://en.wikipedia.org/wiki/Connection_poolinghttp://en.wikipedia.org/wiki/Connection_poolinghttp://en.wikipedia.org/wiki/Databasehttp://en.wikipedia.org/w/index.php?title=Data-centric&action=edit&redlink=1
  • 8/21/2019 mi0041-javaandwebdesign

    12/12

    the exception, and throwing that object into the method that triggered the error. The method may handlethe exception by itself or pass on the exception to another method to handle it. In either of the ways, the

    exception is caught and processed at some point.There are two ways by which exceptions can occur. They are as follows:

    Java run-time system: These exceptions relate to the fundamental errors that violate the rules ofthe Java programming language or the constraints of the Java execution environment.

    Code generated: The code that we write can manually generate exceptions. These are used toreport some error condition to the caller of a method.

    Using throw

    We can throw an exception explicitly by using the throw statement. The general form of throw is as

    follows:Throwable Instance must be an object, which is of type Throwable or a subclass of Throwable. Wecannot use primitive types, such as int or char, and non-Throwable classes, such as String and Object, asexceptions. We can obtain a Throwable object in the following two ways:

    Using a parameter in a catch clause. Using the new operator.

    The execution of the program stops immediately after the execution of the throw statement. Thesubsequent statements are not executed. The program checks for a catch statement that matches

    the type of exception in the nearest try block. If a matching catch statement is found, control is

    transferred to that statement. If a matching catch statement is not found, the programs checks for

    a matching catch statement in the next try block and so on. If a matching catch statement is notfound, the default exception handler halts the program and prints the stack trace.

    Using finally

    We have discussed the try; catch blocks and how to use throw and throws in the previoussections. Now let us discuss the use of the finally block. When exceptions are thrown, the

    execution of a method is interrupted and this alters the normal flow of the program. Sometimes,the code is written in such a way that an exception causes a method to return prematurely. Thismay create problems in few methods. For example, suppose you have a code for opening a file,

    entering data, and closing the file. In such a situation, you will want that part of the code, which

    closes the file, to be executed at any cost. It may happen that this part of the code is not executed due toan exception that occurred when opening the file. Hence, we need a mechanism to handle such cases. Thefinally keyword is used to address this issue.finally is a block of code that is executed:

    After the execution of the try/catch block. Before the execution of the code following the try/catch block.

    The finallyblock of code is executed at any cost. If there is an error in the program, the catchblock isexecuted, then the finally block is executed. If there are no errors, the try block is executed, then thefinallyblock is executed.