Skip to main content

Posts

Showing posts from September, 2013

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?