Sie sind auf Seite 1von 7

Unit-1

Methods and Constructors

Differentiate between method overloading and method overriding with the


help of a program.
Differentiate between method and constructors.
What do you mean by constructor? Do you think that Constructors are
static?
"If a class has any parameterized constructor, then it must define a no-
argument constructor also." Comment on this statement.
Can we declare a Constructor Private? Can we overload a constructor? Can
we override the constructors?
What do you mean by Constructor Chaining? Explain with the help of a
program.
Use of static modifier in java. Explain with help of program.

Abstract Class, Interfaces and Nested Classes

What is an interface? Can we define a constructor in an interface?


Define Abstract class? Do you agree that Every abstract class must have at
least one abstract method?
What is the difference between Abstract Class and Interface? Can we
define an interface within a class?
What are the uses of 'super', this and final keywords in Java? Explain with a
program.
What is use of final modifier with classes, methods and fields?
What is Nested class? Can we define a class inside a constructor?
How static nested classes are different from inner classes? How will you
create the objects of static and non-static nested classes?
What is an Anonymous Class? How it is different from Local Class?
Write the code snippet for creating the object of a static nested class and a
non-static nested class.
Can we declare a class private? How will you prevent the inheritance of a
class?
What is the significance of using short-circuit AND (&&) instead of Logical
AND (&) operator?
What do you understand by "Garbage Collection" in Java? How Garbage-
Collection is done in Java?
Discuss any five methods of Object class.
WAP in which override the method of super class in the subclass. Now
invoke both the super class method and sub-class method with the help of
sub-class object.
WAP in which define an abstract class A containing a non-abstract method
demo() and an integer variable x initialized to 10. Define an interface B
containing demo() method and a double variable x initialized with 20.0.
Now create a class Test which inherits A and B. Invoke the demo() method
and print the value of x. Explain the output.
What are the various access modifiers in java? Explain the accessibility of
public, protected and private members with the help of a program.
What is a Local class? WAP to demonstrate how you will invoke the method
of a local class from another class.
Differentiate between >> and >>> shift operators with example.
Differentiate between & and && logical operators in Java. Explain with an
example.
Differentiate between instance variable and local variable.
Write a program in which a class Child inherits class Parent and
overrides the following method:

int sumOf(int a, int b)

Now invoke both the super-class method and sub-class method with the
help of subclass object only.
Write a program to create a class named Demo which cannot be
inherited and which inherits a class named Test which cannot be
instantiated.
Unit-2

Array and ArrayList

WAP to demonstrate the use of any five methods of ArrayList class. Explain
the output. Also explain use get and set methods present in ArrayList class.
How ArrayList is different from Array in java? Can you add a string and an
integer in the same ArrayList?
What do you mean by Jagged Array? Write code snippet to create Jagged
Array.
WAP to create a two-dimensional array in which dimensions of the array
and array elements are entered by user at run time.
WAP to create a square matrix and initialize it at run time. Now display the
sum of all its elements on the major diagonal using the following method:

public static int MajorDiagonal(int[][] m)

Write a code snippet to find out the first occurrence of an integer in an


arraylist.
WAP to create a two-dimensional array dynamically. Now write a method
to find out the largest element of that array.
Differentiate between add() and addAll() in the ArrayList class. What will
happen if we add a collection object to an arraylist using add method?
Write a Program to create a two-dimensional array of double type
dynamically and use method public int[] double_to_Int(double [] ar) to
convert all the double values of argumented array into int.
String Handling

Differentiate between ensureCapacity() and setLength() in StringBuffer


class.
Differentiate between the length() and capacity() methods in StringBuffer
class.
How many Strings will be created in the code snippet given below? Explain.

String s = "Hello";

String s1 = new String("Hello");

String s2 = "Hello";

s1.toUpperCase();

Write code snippet to create a String object s, initialized with first 4


characters of a character array char [] mychar.
How you can covert an array of character to String object and String object
to array of characters.
What will be the Output of the following code snippet? Explain.

System.out.println("Hello World".compareTo("Hello"));

"String objects are immutable." What do you mean by this statement?


Explain the working of getChars() and toCharArray() method in String class
with an example.
Explain insert() and replace() methods with example.
Write the method header of any five methods of StringBuffer class and
explain their working with an example.
Write the method header of any five methods of String class and explain
their working with an example.
WAP which prompts the user to enter a sentence in present continuous
tense. Now write your own method to convert the sentence in to past
continuous sentence.
How String is different from StringBuffer? Write the method header of any
two methods of StringBuffer class which are not available in String class.
Differentiate between append() and concat() methods. What will happen if
we call the toUpperCase() on any String?

WAP that prompts the user to enter a String. Write your own method

String rev_String(String s) to display the reverse of that string and check


whether it is palindrome or not?

WAP to prompt the user to enter a String and a character. Write your own
method that counts the occurrences of a given character in a string using
the following header: public static int count(String s, char c)
Ex: count(Hello, l) returns 2.

Wrapper Class

What do you mean by Wrapper class? What is Auto-boxing and Unboxing?


Why we need Wrapper class? Do you think that String is a Wrapper class?
How will you create a Double object initialized with the value stored in a
String object? Write code snippet and explain.
How the parseInt() is different from valueOf() method in Integer class?

Unit-3

Packages

What do you mean by Package? What is the need of Packages? How will
you restrict the access of a data member outside the package?
Discuss all the access specifiers in Java. Can we define a private class?
WAP to create a class A in package P1 which invokes a non-static method
demo() of another class B of package P2. (Write the code of class A only)
How will you create a class Test in a package named "MyPack"? Write code
snippet only.
Exception Handling

What is the need of Exception Handling? Explain the Exception class


hierarchy.
Differentiate between Exception and Error.
Differentiate between catch block and finally block.
Differentiate between Checked and Unchecked Exception.
Differentiate between throw and throws keywords.
What are the two ways to deal checked exceptions in Java? Name any two
checked exceptions in Java. What will happen if we don't handle the
checked exception manually?
What do you mean by generalized catch block? Can we use multiple catch
blocks with one try block?
What do you mean by Chained Exception? Explain with Example.
Differentiate between Exception Chaining and Rethrowing.
Explain all the keywords used in Exception Handling. Can we throw multiple
exception objects with throw keyword?
WAP in which prompt the user to enter two numbers x and y. If x is divisible
by y then throw ArithmeticException. Rethrow the exception from the
catch block.
WAP to create a custom Exception class "NotPrimeException". Prompt the
user to enter a number. If the number is not prime, then throw
NotPrimeException. Otherwise display that prime number.
Why finally block is important in Exception handling?
How do you throw an exception? Can you throw multiple exceptions in one
throw statement? Can we declare multiple exception in one method?
Note:

1- Code snippet: Means segment of code(No need to write complete code)


2- Try to implement your logic in program
3- Practice on the program of user Defined exception
4- For any problem you can come in my cabin of block 34. Room no(202)

Das könnte Ihnen auch gefallen