Hamid

   
 
  CS-74
Course Code : CS-74
Course Title : Introduction to Internet Programming
Assignment Number : BCA(6)-74/Assignment/09
Maximum Number : 100 (weightage = 25)
Last Date of Submission : 30th April, 2009/30th October, 2009

This assignment is having six questions. Answer all the questions. 


Q. 1 Answer the following questions through examples:

(i) What are the benefits of inheritance in Java programming?    
      

Ans:-    One of the key benefits of inheritance is to minimise the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organisation of code and smaller, simpler compilation units.

Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass Example, then the application can be adapted to return any class that is descended from Example.


(ii) What are the applications of super and this keyword?

Ans:-

This Keyword
     The this keyword followed by a dot is used to access members variables and methods of the current object.

Example:

 public SimpleTime(int hour, int minute, int second) {
    this.hour = hour;
    this.minute = minute;
    this.second = second;
 }


Super Keyword
       There are two uses of the super keyword.
i. It is used for calling the superclass constructor.
ii. It is used to access those members of superclass that are hidden by the member of subclass.

The super keyword followed by a dot is used to access the original version of the method from the subclass. The super keyword can be handy if you want to access the original method in the superclass that has not been overwritten in your subclass.

When a constructor is defined in any subclass, it needs to initialize its superclass variables. A subclass can call a constructor method defined by its superclass by use of following form of super (parameter_list). Parameters needed by the superclass constructor are passed in super (parameter_list). The super keyword helps in conflict resolution in subclasses in the situation of "when members name in superclass is the same as members name in a subclass, and the members of the superclass is to be called in subclass".
super.member; // The member may be either member function, or member data.

Example :

    public class Superclass {

        public void printMethod() {
            System.out.println("Printed in Superclass.");
        }
    }

// Here is a subclass, called Subclass, that overrides printMethod():

    public class Subclass extends Superclass {

      public void printMethod() { //overrides printMethod in Superclass
          super.printMethod();
          System.out.println("Printed in Subclass");
      }
      public static void main(String[] args) {
         
      Subclass s = new Subclass();
      s.printMethod();   
      }

    }

Compiling and executing Subclass prints the following:

    Printed in Superclass.
    Printed in Subclass



(iii) What is the use of the final modifier?

Ans:-
final Modifier
The final Modifier may be applied to a class, indicating the class may not be extended (subclassed).
The final Modifier may be applied to a method, indicating the method may not be overridden in any subclass.

Examples :
public final class MyFinalClass
{
}
public class MyClass
{
      public final String myFinalMethod()
            {
                  <statements>
            }
}

A class may never be both abstract and final. abstract means the class must be extended, while final
means it cannot be.
 
A method may never be both abstract and final. abstract means the method must be overridden, while
final means it cannot be.


Q. 2
(i) What is the input and output to a Java compiler?


Ans:-

refer




(ii) What is the relationship between java and HTML?

Ans:-
Java isn't a page description language like HTML. It's a programming language. Description languages specify content and placement; programming languages describe a process for generating a result. Where there is generally a direct mapping between an HTML description of a document and the result, the relationship between a Java program and its result is likely to be more complex. It's a little like the difference between a list of square roots of numbers from zero to 10 and a program to calculate the list.

This is the code that specifies the Java code to run:

<APPLET CODEBASE="java" CODE="SqrtList" WIDTH=160 HEIGHT=162>
  <EM>You need a Java-aware browser</EM>
</APPLET>

The <APPLET> tag specifies the class to load (the CODE= field), URL information (the CODEBASE= field) and the size of the region the applet will own. Notice that Java doesn't exactly integrate with the rest of the page. Within that region of the page Java is king: it decides background color and fonts and does all the mouse and keyboard handling.

Parameters to the applet are placed in <PARAM> tags between the <APPLET> and </APPLET> tags. Anything else between these tags is ignored.


(iii) What is the import statement for ?

Ans:-
Import Keyword
The import keyword makes one class or all classes in a package visible in the current Java source file.
Imported classes can be referened without the use of fully−qualified class names.

Examples
import java.io.File;
import java.net.*;

Many Java programmers use only specific import statements (no '*') to avoid ambiguity when
multiple packages contain classes of the same name.


(iv) what are the differences between application and applets? How do you run an application and an applet?

Ans:-
Applets :
1. applets can be embedded in HTML pages and downloaded over the internet, or Intranet.
2. Applets can only be executed inside a Java-compatible container, such as a modern Web Browser.
3. Applets execute under strict security limitations that disallow certain operations, such as accessing files or systems servies on the user's computer.
4. Applets are the programs written specially for distribution over a network. These programs contain information to be delivered to the world and involve user interaction, for example, order entry form, registration form mailing, etc.

Applications :
1. Applications have no special support in HTML for embedding or downloading.
2. Applications can be executed from the command line with a small booting utility such as javac.exe or java.exe.
3. Applications have no inherent security restrictions.
4. Applications are system level programs i.e., these programs run in the background and don't involve user interaction, for example, server administration, security manager, etc.


Q. 3
(i) Describe the JAVA throughable class hierarchy and types of exceptions. 

JAVA Throughable class hierarchy :


Types of Exceptions and their Descriptions. :-

NullPointerException :
Raised when a variable is used without initialization.

ArithmaticException :
Raised when a number is divided by zero.

ArrayIndexOutofBoundsException :
Raised when an array element which does not exist is accessed.

ClassNotFoundException :
Raised when a specified class file is not found.

StringIndexOutofBoundsException :
Raised when attemptiong to access a string element which does not exist is attempted to be accessed.

IOException :
Deals with file related errors.

Exceptions and Exception Types



(ii) What is the purpose of claiming exceptions?

The purpose of claiming exceptions is to tell the Java runtime system what can go wrong. You claim an exception using the throws keyword in the method declaration. You can claim multiple exceptions, separated by commas.

To claim an exception in a method, use the throws keyword.
modifiers MethodName(list of params) throws 
      Exception_1, Exception_2, ..., Exception_N

Example:
public void myMethod() throws IOException
{
  ...
}


(iii) What is the keyword throw and throws used for?
Ans.
      The keyword to claim an exception is throws and the keyword to throw is exception in throw.

Throw Java Keyword
The throw keyword is used to raise an exception.

Examples
import java.io.IOException;
public class MyClass
{
public method readFile(String filename) throws IOException
{
<statements>
if (error)
{
throw new IOException("error reading file");
}
}
}

The throw statement takes a java.lang.Throwable as an argument. The Throwable is propagated up the
call stack until it is caught by an appropriate catch block.
Any method that throws an exception that is not a RuntimeException must also declare the exceptions
it throws using a throws modifier on the method declaration.

Throws Java Keyword
The throws keyword may be applied to a method to indicate the method raises particular types of exceptions.

Examples
import java.io.IOException;
public class MyClass
{
public method readFile(String filename) throws IOException
{
<statements>
if (error)
{
throw new IOException("error reading file");
}
}
}

· The throws keyword takes a comma−separated list of java.lang.Throwables as an argument.
- Any method that throws an exception that is not a RuntimeException must also declare the exceptions
it throws using a throws modifier on the method declaration.
- The caller of a method with a throws clause is required to enclose the method call in a try−catch
block.


Q. 4
Design a menu-driven interactive programme to find out capital cities of all the states of India using switch statement.           

import java.io.*;
public class capital
{
  public static void main(String args[]) throws Exception
  {
    System.out.println("Enter 1 for Andra Pradesh");
    System.out.println("Enter 2 for Arunachal Pradesh.");
    System.out.println("Enter 3 for Assam.");
    System.out.println("Enter 4 for Bihar.");
    System.out.println("Enter 5 for Chhattisgarh.");
    System.out.println("Enter 6 for Goa.");
    System.out.println("Enter 7 for Karnataka.");
    System.out.println("Enter 8 for Gujrat.");
    System.out.println("Enter 9 for Haryana.");
    System.out.println("Enter 10 for Himachal Pradesh.");
    System.out.println("Enter 11 for Mizoram.");
    System.out.println("Enter 12 for Jammu & Kashmir.");
    System.out.println("Enter 13 for Jharkhand.");
    System.out.println("Enter 14 for Kerala.");
    System.out.println("Enter 15 for Madhya Pradesh.");
    System.out.println("Enter 16 for Maharashtra.");
    System.out.println("Enter 17 for Manipur.");
    System.out.println("Enter 18 for Meghalaya.");
    System.out.println("Enter 19 for Nagaland.");
    System.out.println("Enter 20 for Orissa.");
    System.out.println("Enter 21 for Punjab.");
    System.out.println("Enter 22 for Rajasthan.");
    System.out.println("Enter 23 for Sikkim.");
    System.out.println("Enter 24 for Tamil Nadu.");
    System.out.println("Enter 25 for Tripura.");
    System.out.println("Enter 26 for Uttar Pradesh.");
    System.out.println("Enter 27 for Uttaranchal.");

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String read = br.readLine();
    int ch = Integer.parseInt(read);

      switch(ch)
      {       
        case 1:  System.out.println("Hyderabad");
            break;
        case 2:  System.out.println("Itanager");
            break;
        case 3:  System.out.println("Dispur");
            break;
        case 4:  System.out.println("Patna");
            break;
        case 5:  System.out.println("Raipur");
            break;
        case 6:  System.out.println("Panaji");
            break;
        case 7:  System.out.println("Bangalore");
            break;
        case 8:  System.out.println("Gandhinagar");
            break;
        case 9:  System.out.println("Chandigarh");
            break;
        case 10:  System.out.println("Shimla");
            break;
        case 11:  System.out.println("Aizawl");
            break;
        case 12:  System.out.println("Srinagar(Summer) & Jammu(Winter)");
            break;
        case 13:  System.out.println("Ranchi");
            break;
        case 14:  System.out.println("Trivandrum");
            break;
        case 15:  System.out.println("Bhopal");
            break;
        case 16:  System.out.println("Bombay");
            break;
        case 17:  System.out.println("Imphal");
            break;
        case 18:  System.out.println("Shillong");
            break;
        case 19:  System.out.println("Kohima");
            break;
        case 20:  System.out.println("Bhubaneswar");
            break;
        case 21:  System.out.println("chandigarh");
            break;
        case 22:  System.out.println("Jaipur");
            break;
        case 23:  System.out.println("Gangtok");
            break;
        case 24:  System.out.println("Chennai");
            break;
        case 25:  System.out.println("Agartala");
            break;
        case 26:  System.out.println("Lucknow");
            break;
        case 27:  System.out.println("Dehra Dun");
            break;
        default: System.out.println("Invalid entry!");
             break;
      }
   }
}




Q. 5
Admission to a professional course is subject to the following condition:
a)    Marks in mathematics > = 60
b)    Marks in Physics > = 50
c)    Marks in Chemistry > = 40
d)    Total in all three subjects > = 200
Or
Total in mathematics and Physics > = 150

Given the marks in the three subjects, write a programme to process the applications to list the eligible candidate.

import java.io.*;
class stud1
{
 public static void main(String[] args) throws IOException
 {
  System.out.println("Press Controll +C to terminate");
  System.out.println("Enter Mark of Math : ");
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  String read = br.readLine();
  int m = Integer.parseInt(read);

  System.out.println("Enter Mark of Physics : ");
  String readone = br.readLine();
  int p = Integer.parseInt(readone);

  System.out.println("Enter Mark of Chemistry : ");
  String readtwo = br.readLine();
  int c = Integer.parseInt(readtwo);

  int t=m+p+c;
  int mp=m+p;

    if(m>=60 && p>=50 && c==40 && t>=200)
    {
        System.out.print("Qualified.");
    }
    else if(mp>=150)
    {
        System.out.print("Qualified.");
    }
    else
    {
        System.out.print("DisQualified.");
    }

 }
}


Q. 6     Write a programme to perform binary operations on integer argument. The arguments and operators should be accepted using command line parameters.

Ans.
Download.
.
http://www.ziddu.com/download/4623744/CS-74_Q6.doc.html
 
Login
 
Username:
Password:
Donate
 
You can help this website
by donate or
you can click an
advertisement.

IGNOU Students
 
Sample Synopsis

Time Table BCA 2009
Projects (Vb n ASPnet) : Download
Synopsis Form

Training Letter

Guide Remuneration Form

Certificates of Originality

Java KeyWords - PDF

Java KeyWords - Wikipedia


Click Here / Click Here

Edit Plus (Use it as Java editor) Download

How to configure EditPlus to compile JAVA codes click here


Advertisement
 
PC Games (Full, Rip, Compressed)
 
 
© 2007 - 2009 HamidRaza - Today, there have been 28 visitors (37 hits) on this page!
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free