Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1- If your super class A extends Object class default and B class extends your super class then
Object class
of inherited of A class or inherited by defult or both.
Ans: Object Class will be inherited of A Class.
2- What is dynamic polymorphism in codding.
Ans: Method overloading is an example of compile time/static polymorphism because method
binding b/w method call and method definition happens l
at compile time and it's depend on the ref. of the class(ref. create at compile time and goes to
stack).
Method overriding is an example of run time/dynamic polymorphism because method binding
b/w method call and method definition happens
at run time and it's depend on the object of the class (object create at runtime and goes to heap)
The overriding method can throw any unchecked (runtime) exception, regardless of whether
the overridden method declares the exception.
The overriding method must not throw checked exceptions.
In Overriding the return type must be the same as, or a subtype of, the return type declared in
the original overridden method in the superclass
(also called covariant return type).
Overloaded methods can change the return type.
3- What is Deadlock and how it will be resolved.
Ans:
4- Write down code for create custom exception.
Ans:
5- Write down code for sort by Name from (name,id) arraylist.
Ans
6- What is Multithreading.
Ans: Java provides built-in support for multithreaded programming. A multithreaded program
contains two or more parts that can run concurrently.
Each part of such a program is called a thread, and each thread defines a separate path of
execution.
Multithreading is a process of executing multiple threads simultaneously.
getName(): It is used for Obtaining a threads name
SPRING QUESTIONS
1224567891011-
What is Spring.
What is IOC and what is use of IOC in Spring.
Explain the IOC by using code.
Explain the DI by using simple example.
Explain the life cycle of Bean.
What are the Scope of Spring.
What are the Collection in Spring.
What is AOP ? and what is JoinPoint.
How you will map Object with hbm.XML.
By default what is scope in Spring.
What do you mean by Singleton in Spring.
HIBERNATE QUESTIONS
1234567-
class.
19- How to make a List (ArrayList,Vector,LinkedList) read only?
Ans: A list implemenation can be made read only using Collections.unmodifiableList(list).
If a user tries to perform add operation on the new list; UnSupportedOperationException is
thrown.
20- What is ConcurrentHashMap?
Ans: A concurrentHashMap is thread-safe implementation of Map interface. In this class put
and remove method are synchronized but not get method.
This class is different from Hashtable in terms of locking; it means that hashtable use object
level lock but this class uses bucket level lock
thus having better performance.
21- Which is faster to iterate LinkedHashSet or LinkedList?
Ans: LinkedList.
22- Which data structure HashSet implements.
Ans: HashSet implements hashmap internally to store the data. The data passed to hashset is
stored as key in hashmap with null as value.
23- Arrange in the order of speed - HashMap,HashTable,
Collections.synchronizedMap,concurrentHashmap.
Ans: HashMap is fastest, ConcurrentHashMap,Collections.synchronizedMap,HashTable.
24- What is WeakHashMap?
Ans: A hashtable-based Map implementation with weak keys. An entry in a WeakHashMap
will automatically be removed when its key is no longer in ordinary use.
When a key has been discarded its entry is effectively removed from the map, so this class
behaves somewhat differently than other Map implementations.
25- Once the control switches to the catch block does it return back to the try block to execute
the balance code?
Ans: No. Once the control jumps to the catch block it never returns to the try block but it goes
to finally block(if present).
26- What happens if the exception is never caught and throws down the method stack?
Ans: If the exception is not caught by any of the method in the methods stack till you get to
the main() method, the main method throws that exception
and the JVM halts its execution.
27- Can you catch more than one exceptions in a single catch block?
Ans: Yes. Ex- The catch block will catch IOException and all its subclasses e.g.
FileNotFoundException etc.
28- What happens if the exception is never caught and throws down the method stack?
Ans: If the exception is not caught by any of the method in the methods stack till you get to
the main() method, the main method throws that exception and
the JVM halts its execution.
29- What is the difference when the synchronized keyword is applied to a static method or to a
non static method?
Ans: When a synch non static method is called a lock is obtained on the object. When a synch
static method is called a lock is obtained on the class and not
on the object.
30- What is a volatile keyword?
Ans: Each thread has its own stack, and so its own copy of variables it can access. When the
thread is created, it copies the value of all accessible variables
in its own memory. The volatile keyword is used to say to the jvm "Warning, this variable may
be modified in an other Thread". Without this keyword the JVM
is free to make some optimizations, like never refreshing those local copies in some threads.
The volatile force the thread to update the original variable
for each variable.
The volatile keyword could be used on every kind of variable, either primitive or objects!
31- What are The general rules of method overloading.
Ans: a) Overloaded methods must have different argument list
b) Overloaded methods may or may not have different return type. Since return type is not
part of method signature,
there is no mandate have different return types.
c) Overloaded methods may have different access specifiers.
d) Overloaded methods can declare new or broader checked exceptions.
32- Can we Overload in subclass.
Ans: Yes.
//See in Eclipse class name OverloadInSubClass
33------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------IBM Challenging Questions
------------------------------------------------------------------------------------1- When we write Ajax then which method of Java Script will be called.
Ans:
2- What are types of Controller.
Ans:
3- What is difference between Persist and Save in hibernate.
Ans:
4- How to make Thread safe to JSP.
Ans:
5- What is Session and Application JSP.
Ans:
6- What are configuration files in Spring.
Ans:
7- What is Transaction in JSP.
Ans:
8Ans:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------COGNIZANT QUESTIONS
-----------------------------------------------------------------------------------------------------------------------------------------------1- What is class method and instance method in overriding.
Ans: Class method means the call will decide at compile time and it is static method so thats
why we saying if we override static method then we cant say
it's override but we can write same method and same signature, and when we try to call by
object then always super class method will be called.
In case of instance method the call will decide at run time it is non static method so it's called
run time polymorphis.
2- What is Covariant return type.
Ans: Before Java 5.0, when you override a method, both parameters and return type must
match exactly. In Java 5.0, it introduces a new facility called covariant
return type. You can override a method with the same signature but returns a subclass of the
object returned. In another words, a method in a subclass can
return an object whose type is a subclass of the type returned by the method with the same
signature in the superclass.
Finaly As of Java 5, you're allowed to change the return type.
Ex :- Class Animal {
Animal myType() { return new Animal(); } }
Class Dog extends Animal {
Dog myType() { return new Dog(); } }
//legal override after java 5
saved ex. in eclipse.
//See this