Skip to main content

Posts

Showing posts from 2013

Review Questions

Topic: Applet, AWT and Event Handling 1. What are Applets? How it is different from Normal java class? 2. What is the difference between Panel, Applet, Window and Frame? Can we add a Frame within a Panel? 3. Explain the Applet Life cycle. What is the importance of paint() and repaint(). 4. List various methods of Graphics class. Write code snippet to draw the following shapes in Applet: String, Rectangle, Oval, Circle, Rounded Corner Rectangle, Polygon and Polylines. 5. What do you mean by Event Handling? Explain Event Delegation Model. How will you register an event source with Listener? Write code snippet. 6. WAP to create a GUI having 4 text fields in four different sides of a frame and a button at the center. Contents of Text fields must be swapped (North<--> South and East<--> West) when the button is pressed 7. WAP to create an applet displaying a ball filled with blue color. Use event handling to move the ball with the mouse-pointer. 8. Wh

Programming Exercise for MTE

1. WAP to demonstrate the use of Anonymous class. 2. WAP to demonstrate the inheritance of class-class, interface-interface and interface-class. 3. WAP to calculate the sum of all the elements on the major diagonal of a square matrix using the following method: public static int MajorDiagonal(int [][] arr) 4. WAP in which prompt the user to enter two numbers a and b. If a is divisible by b then throw NumberFormatException. Rethrow the exception from the catch block. And catch the re-thrown exception in a generalized catch block. 5. WAP to create a custom Exception class "TooLongException". Prompt the user to enter a String. If the length of String is greater than 10, then throw TooLongException. 6. WAP in which prompt the user to enter a number. If the number is less than 100 the throw an exception and display "Number is less than 10" and if it is greater than 20 then throw an exception and display "Number is greater than 20". Rethrow the exception in bot

Program to demonstrate the use of 'this' keyword and Constructor Chaining

// Use of this to refer the instance member in case of name conflict between local variable and //instance variable class ThisDemo           {            int a;            int b;         ThisDemo1(int a,int b)             {               //a=a;                    this.a = a;                          // b=b;                  this.b = b;             }         public static void main(String [] rks)             {               ThisDemo1 td = new ThisDemo1(50,30);                                 System.out.println(td.a);               System.out.println(td.b);                           }         } // Use of this for constructor Chaining class A    {     public static void main(String ravi[])        {         A a = new A(1);           }     A()     {            //this(1);         System.out.println("Default Constructor");     }     A(int x)     {            this(1, 1.5);         System.out.println("One argumented Constructor");     }     A(int x, double d)     {  

Program to demonstrate the use of 'super' keyword

class TestSuper1    {     int x =10;     TestSuper1(int p)        {         System.out.println("Super class Argumented Constructor");        }     void demo()        {         System.out.println("Super class");        }    } class SuperTest1 extends TestSuper1    {     int x=100;     SuperTest1()        {         // super class constructor using super         super(1);         System.out.println("Sub-class Constructor");        }     public static void main(String rks[])        {                 SuperTest1 t = new SuperTest1();         t.demo();        }     void demo()        {         System.out.println("Sub-class Demo");         // super class method using super         super.demo();         System.out.println("Sub-class x: "+ x);         // super class data member x using super         System.out.println("Super class x: "+ super.x);                }    }

Important Questions for MTE

1. Differences between: (i) >> and >>> operator (ii) & and &&, | and || operator (iii) JDK, JVM and JRE (iv) Overloading and overriding (v) Method and Constructor (vi) final and finally (vii) throw and throws (viii) checked exception and unchecked exception (ix) Exception and Error (x) Abstract class and Interface 2. Nested classes and Inner class (Local class and Anonymous class) with Example 3. Defining and importing the packages 4. Jagged Array, Array as an Argument and as a return type of any method 5. Methods of String and StringBuffer and ArrayList class 6. Various Access modifiers (public, protected, private and default) 7. this, super, static and final keywords 8. Constructor Chaining 9. Chained Exceptions and Custom Exceptions 10. Wrapper classes and need of Wrapper class.

Brain-storming !!!

1. Can we declare and use a private constructor in any class? 2. Can we use return statement between two statements of a method in Java? 3. Can we create the object of a local class in any other class? How? 4. Can we override a static method? 5. How can you find the address of an ArrayList object in Java?

What will be the Output of this Program?

What will be the Output of this Program? class P    {        int z=2;     P()     {        System.out.println("Default");     }     P(int x)     {        this();        System.out.println("one argument");     }     P(int m, int n)     {          this(z);          System.out.println("Argumented");     }         public static void main(String arr[])        {         P p = new P(1, 2);               }   }

Brain_Teaser Questions

1. Can we define a class within a constructor? 2. What will happen if we define a static nested class in a constructor? Given:  If Class A (class A has only one parametrized constructor) is the super class of B (Class B has two parametrized constructors). 3. Can we invoke the parametrized constructor of class A and the parametrized constructor of class B from the other constructor of class B. 4. What will happen if we create the object of class B:     B b1 = new B(5);     assume that there is a constructor B(int x) in class B.

Casting the Objects

class A   {       // body of class A   } class B extends A    {       // body of class B    } We can cast the subclass object to a super class reference variable. i.e. Super class reference variable can hold the subclass object... A a = new B(); But Subclass reference variable can not hold the super class object. WHY? B b = new A();                     // Compile time error
What will be the output of the following program? class Testing {    public static void main(String ar[])     {        Testing t = new Testing();        t.show(1);     }    void show(byte b) {System.out.println("Byte");}       void show(short s) {System.out.println("Short");}    void show(int i) {System.out.println("Int");}    void show(long l) {System.out.println("Long");}    } (a) What will be the output when we remove the  void show(int i)      {System.out.println("Int");} from the class. (b) What will be the output when we remove last two methods from the class? Explain the output.

What is Java? What is the need of Java and what are its features?

Java is an Object-oriented programming language developed by Sun Microsystems (James Gosling) in 1990. Need of Java: Java is an internet programming language. Security and platform-independence are the two most important requirements for Web applications. Java provides both. Java enables users to develop and deploy applications on the internet for servers, desktops and small hand-held devices. Features of Java: Java is: 1. Simple 2. Object Oriented 3. Secure 4. Platform independent 5. Multi-threaded 6. Robust