Work Sheet No. 3


Answer the following questions:


1) Java programs are of two types : One is application and the other is an applet. What is the difference between these two?

2) Java programs are compiled into client machine language - ture or false.

3) Java programs are compiled into Java Virtual Machine and they are executed at the server side. true or false.

4) In Java, one can write functions as an independent entity. true or false

5) Explain what is a static method.

6) Is there a type associated with a class? Explain.

7) What is inheritence? Explain? What type of inheritence Java has?

8) You can use an interpreter (java ) to execute java applet programs. true or false.

9) In applets, you need to have some graphics component. true or false

10) Java applets are called by the browser from a html document. true or false

11) Mention at least three differences between C and Java?


12) What does the following Java Program do?

public class mystery {
public static void main(String argsv[])
{ int y, x=1, total= 0;
	while (x <=10) {
	y= x *x;
	System.out.println(y);
	total +=y;
 	++x; }

System.out.println(total);
}
}

Do we need argsv[] and if so why?


13) Write a Java applet to display:


	*******
	*     *
	*     *
	*     *
	*******
use drawString inside paint method.


14) What are the mistakes in the following Java Programs:

int sum (int x, int y) {
int result;

result = x+y;
}

int sum (int n) {
if (n ==0) return 0;
else 
	n + sum(n-1);
}

15) What dos the following Java program do?
import java.awt.*;
import java.applet.Applet;

public class Myclass extends Applet {
	int result;

	public void start()
 { int a[] = {1,2,3,4};

  	result = What(a,a.length);
 }

public void paint(Graphics g)
{
	g.drawString("Result is" + result,25,25);
}

public int What(int b[], int size)
	{ if (size ==1)
	return b[0];
	else return b[size-1]+What(b,size-1);
 }
}

16) Define a point class with x and y co-ordinates.

Define a constructore method, setter method, getX, getY methods.

public String toString()
 { return "["+x+","+y+"]" ; }
is also defined for tthis class. Discuss an use for it.