Tuesday, October 21, 2014

WBUT 5Years Java Solutions for BCA,BTech,MCA Course



1.           What is local applet? What is remote applet?


   A LOCAL applet is the one, which is stored on our computer system.when browser, try to access the applet, it is not necessary for our computer to be connected to The Internet.

A REMOTE applet is the one, which is not stored on our computer system, and we are required to be connected to the Internet. 


2.          What are the differences between Java application & Java applet?   

   

Java Applet is a kind of application that running on the client's browser, when a browser request a applet embedded page, the applet will downloaded to the client computer and executed within the browser.

Servlets is a application that running on the server, when a server receive a request of a servlet, the server will process the servlet and give the result to the client back after the servlet is done.



3.           What are the attributes of applet tag?


height: Defines height of applet width: Defines width of applet align: Defines the text alignment around the applet alt: An alternate text to be displayed if the browser support applets but cannot run this applet archive: A URL to the applet when it is stored in a Java Archive or ZIP file code: A URL that points to the class of the applet codebase: Indicates the base URL of the applet if the code attribute is relative hspace: Defines the horizontal spacing around the applet vspace: Defines the vertical spacing around the applet name: Defines a name for an applet object: Defines the resource name that contains a serialized representation of the applet title: Display information in tool tip


4.         Write a program in Java to explain how different priorities can be assigned to different threads.


   // Demonstrate thread priorities.

class clicker implements Runnable

{

  int click = 0;

  Thread t;

  private volatile boolean running = true;

  public clicker(int p)

  {

    t = new Thread(this);

    t.setPriority(p);

  }

  public void run()

  {

    while (running) {

    click++;

    }

  }

  public void stop() {

    running = false;

  }

  public void start() {

    t.start();

  }

}

class HiLoPri

 {

  public static void main(String args[])

  {

    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

    clicker hi = new clicker(Thread.NORM_PRIORITY + 2);

    clicker lo = new clicker(Thread.NORM_PRIORITY - 2);

    lo.start();

    hi.start();

    try {

         Thread.sleep(10000);

         } catch (InterruptedException e) {

    System.out.println("Main thread interrupted.");

    }

  lo.stop();

  hi.stop();

  // Wait for child threads to terminate.

  try {

  hi.t.join();

  lo.t.join();

  } catch (InterruptedException e) {

  System.out.println("InterruptedException caught");

  }

  System.out.println("Low-priority thread: " + lo.click);

  System.out.println("High-priority thread: " + hi.click);

  }

}


5.         What is a package?


A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.


Packages are used for:


i)        Resolving naming conflict of classes by prefixing the class name with a package name. For example, com.zzz.Circle and com.yyy.Circle are two distinct classes. Although they share the same class name Circle, but they belong to two different packages: com.zzz and com.yyy. These two classes can be used in the same program and distinguished using the fully-qualified class name - package name plus class name. This mechanism is called Namespace Management.

ii)      Access Control: Besides public and private, Java has two access control modifiers – protected and default – that are related to package. A protected entity is accessible by classes in the same package and its subclasses. An entity without access control modifier (i.e., default) is accessible by classes in the same package only.

iii)     For distributing a collection of reusable classes, usually in a format known as Java Archive (JAR) file.



6.      Explain the different access controls for packages in Java.


Packages acts as a container for classes and other subordinate packages. Classes are containers of data and code. Class is the smallest unit of abstraction. There are four categories of visibility for class members. They are:
• Sbuclass in the same package
• Non-subclass in the same package
• Subclass in different packages
• Classes that are not in the same package or in the subclass


There are four access specific; public, private, protected and default or no modifier. A public member of a class can be accessed from anywhere; within the package, outside the package, within a subclass, as well as within a non-subclass. The only condition is that the package must be imported into the class that uses it. Similarly a member of a class that is declared private can be accessed only within the class but not anywhere outside the class. If no access specifier is given, it is assumed to be default or friendly or package access. There is however no special keyword to denote this. Default or package access means the member would be accessible within any class in the same package but not accessible outside the package.

No comments:

Post a Comment