Anda di halaman 1dari 13

CORE JAVA & J2EE

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

getPriority(): Obtain a threads priority


isAlive(): Determine if a thread is still running
join(): Wait for a thread to terminate, this method when called from the parent thread makes
parent thread wait till child thread terminates.
7- What is Ajax ? And how the Cache maintain will be maintan in Ajax.
Ans: The following will prevent all future AJAX requests from being cached, regardless of
which jQuery method you use ($.get, $.ajax, etc.)
$.ajaxSetup({ cache: false });
8- Write down steps for connect with database with JDBC.
Ans:
9- We have created A class with constructor and A class extending by B class then constructor
will be inherited by default in B class.
Ans: No. Only by calling super we can access parent constructor.
10- Explain the Hierarchy of Exception.
Ans:
11- What is difference between Exception and Error.
Ans:
12- What is difference between Abstract class and Interface.
Ans:
13- Explain the Hierarchy of Collection.
Ans:
14- What is difference between Servlet and JSP.
Ans:
15- What is translation phase of JSP.
Ans:
16- What is Serializable.
Ans:
17- Can we use both Serilizable and Transient if yes then how it will work.
Ans: Yes. we can implement Serializable interface and Transient can be used with property if
transient used then that property will not
be serialized.
18- What are tags in JSP.
Ans:

19- What are conditions of Abstract Class.


Ans: 1) Use abstraction if you know something needs to be in class but implementation of that
varies.
2) In Java you can not create instance of abstract class , its compiler error.
3) abstract is a keyword in java.
4) a class automatically becomes abstract class when any of its method declared as abstract.
5) abstract method doesn't have method body.
6) variable can not be made abstract , its only behavior or methods which would be abstract.
7) If a class extends an abstract class or interface it has to provide implementation to all its
abstract method to be a concrete class.
alternatively this class can also be abstract.
8) We can have Constructor and main() method in abstract class.
20- Can we inherit the Constructor of Superclass in subclass.
Ans: Constructor declarations are not members. They are never inherited and therefore are not
subject to hiding or overriding and also no return type.
super() is the way to call your superclass's constructor.
21- What modifier will be used for variable in abstract class.
Ans: Modifier for the field a; only public, protected, private, static, final, transient & volatile
are permitted.
22- How to create Singleton in Java.
Ans: public class EagerSingleton {
private static volatile EagerSingleton instance = new EagerSingleton();
// private constructor
private EagerSingleton() {

public static EagerSingleton getInstance() {


return instance;
}}
Step -1: Constructor should be private.
Step -2: getInstance() method should called for instantiate the singleton.
23- Can we change the format of public static void main(String args[]).
Ans- Yes. We can change like
static public void main(String args[])
public static void main(Integer args[])
Only we change modifier (public,static) not return type.And we can not override main
method.
24- When to use Comprale and when Comprator.
Ans: Use Comparable if you want to implement default sorting. e.g. Employees will be sort

based on their employee ids.


Comparator should be used when you are adding multiple ways of sorting or sorting on
uncommon fields.
e.g. sorting based on Lastname or emaployee age.
25- Can we override run() method and call start method without extending Thread or
Runnable.
Ans:
26- Why wait() and notify() method are Object class.
Ans: These methods works on the locks and locks are associated with Object and not Threads.
Hence, it is in Object class.
The methods wait(), notify() and notifyAll() are not only just methods, these are
synchronization utility and used in communication
mechanism among threads in Java.

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.

12- What is difference between Sigleton and Prototype.


13- If we are not using getter then how you can access the value.
14- How you can Integrate Hibernate with Spring.

HIBERNATE QUESTIONS
1234567-

What is ORM.How it is working in hibernate.


Why we choose the Hibernate for connectivity not JDBC.
What do you know in J2EE.
What id difference between connectivity from MSSQL and Oracle or DB2.
What is Connection Pooling.
What id other benefit by using Hibernate.
What is Driver ? and what is use of this.

-------------------------------------------------------------------------------------------------------------------------------------------------MINDTREE INTERVIEW QUESTIONS


-------------------------------------------------------------------------------------------------------------------------------------------------1- What is Java concepts.
2- What is polymorphism.
3- Can we have return type in Overloading and Overriding.
4- Can we throw the exception in case of Overriding if yes then what will be format of
overriding.
5- Can we throw exception in subclass when we overriding method without throwing the
exception in superclass.
6- We have static method ,static block and static variable in java how it will be executed and
store in memory.
7- what is static and what is use of static in java.
8- What is Abstract and Encapsulation.
9- Can you draw the Structure diagram of Exception Hierarchy.
10- How you can create custom exception.
11- What is collection.
12- What is Superclass of Error in Exception.
13- Why we override the Equals and HashMap in java what is purpose of this.
14- What is Serialization and when we have to use.
15- If we define the Transient to variable and try to deserialize then how it will work.
16- If I want to sort the name by ID then how we can sort.
17- Can you write down the program for reverse the String Variable.

18- What is Synchronization in java.


19- Can we synchronized to static method.
20- What is lifecycle of JSP.
21- Can we override init(),Service() or destroy method in JSP.
22- What is Directive in JSP.
23- What are the Element of JSP.
24- What is difference between forword and sendRedirect method in JSP.
25- What are the implicit object in jsp.
26- How you can hanle the Exception in JSP ?And how you can use implicit object Exception
in JSP.
27- When you comile the JSP then which part of servlet it will go the code.
28- What is IOC in Spring and what is benefit of this.
29- What difference between Spring MVC and normal MVC.
30- What are the Scopes in Spring.
31- Waht do you mean by Prototype and Request scope in Spring.
32- How the Beans are instanciated in Spring.
33- What are the lifecycle of Beans.
34- Can we call the Destroy method within the init() method in servlet if yes then what will
happen.
35- What is difference between Unique Key and Primary key in sql.
36- What are the joins explain one by one ?And what is cross join.
37- What is final finally and finalize.
38- If we define the finally and return in catch block then finally will be excuted or not.s
-----------------------------------------------------------------------------------------------------------------------------------1- Can Synchronized static method in Java.
Ans: Yes
2- Can we Synchronize run() method in Multithreading.
Ans: Yes
3- Can we Overload or Override static method.
Ans: We can Overload but we cant override to static method because override will be in
runtime.
4- Can Synchronized abstract method in Java.
Ans: No. Does not make sense.
5- Can we define main() methos as final and Synchrinized.
Ans: Yes
6- Can we Overload or Override main() method in java.
Ans: We can Overload main method but cant Override because it's static.

7- What is use of dialect in hibernate.


Ans: Hibernate uses "dialect" configuration to know which database you are using
so that it can switch to the database specific SQL generator code wherever/whenever
necessary.
8- Can we create constructor in abstract class.
Ans: Yes.
9- If we say we can not create instance of abstract class then why do Java adds constructor in
abstract class.
Ans: One of the reason which make sense is, when any class extend abstract class, constructor
of sub class will invoke constructor of super class
either implicitly or explicitly. This chaining of constructors is one of the reason abstract class
10- How to get second highest salary from employee table.
Ans: SELECT MAX(Salary) FROM Employee WHERE Salary NOT IN (SELECT
MAX(Salary) FROM Employee).
11- Why we write wait() and notify() method within synchronized block.
Ans: If we will not do then it will throw exception. IllegalMonitorStateException.
12- How to get nth highest salary from employee table.
Ans: SELECT *FROM Employee Emp1 WHERE (n-1) = (SELECT
COUNT(DISTINCT(Emp2.Salary)) FROM Employee Emp2 WHERE Emp2.Salary >
Emp1.Salary)
13- Can we have empty abstract class.
Ans: Yes
14- Can we define static and final in abstract class.
Ans: No. but we can define public, protected, and private concrete methods.
15- What is default behaviour of field and methods in Interface.
Ans: All fields are automatically public, static, and final, and all methods that you declare or
define (as default methods) are public.
16- Can we define to variable as abstract.
Ans: No.
17- How to iterate Map<Object,List<String>> and Map<Class,List<Object>>.
Ans:
18- What is difference between Collection and Collections.
Ans: Collection is a base interface for most collection classes, whreas Collections is a utility

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

3- Can we have different exception through in overriding.


Ans: The overriding method in a subclass can only declare to throw that exception or its
subclass.
Ex:- class A {
public void foo() throws IOException {..}
}
class B extends A {
public void foo() throws SocketException {..} // allowed
public void foo() throws SQLException {..} // NOT allowed
}
SocketException extends IOException, but SQLException does not.
Step:1- If the superclass method does not declare an exception, subclass overridden method
cannot declare the checked exception but it can declare
unchecked exception.
Step:2- If the superclass method declares an exception, subclass overridden method can
declare same, subclass exception or no exception but cannot
declare parent exception.
4----------------------------------------------------------------------------------------------------------------------------------------------------------Popular Ques from Teato and L&T and Allianz
------------------------------------------------------------------------------1- What is difference between Abstract and Abstraction.
Ans: Abstraction is implemented in Java using interface and abstract class while Encapsulation
is implemented using private, package-private and
protected access modifier.
2-

If we define final to Class reference then how it will work.

like - final Person P = new Person();


Ans:
3- How to define checked and unChecked exception with overriding.
Ans: Yes can define Checked and Unchecked.
4- How you can decide which scenerio will be used abstract and other in Interface.
Ans:
5- If we are using HashSet and insert duplicate value without override equals and hashcode
method then how many records are.
And: Whithout override equals and hashCode method it will display 2, and using method
display 1 records.
6- In the exception handling define try, catch and finally if try throw exception then still finally
will be executed.
Ans:
7- What is Generics in java.
Ans:
8- How you can explain with example that Spring is loosely coupled.
Ans:
9- Why we Override and Overload method in Java.
Ans:
10- Why pointer does not support in Java.
Ans:
11- How to pass the Object from one thread to other thread.
Ans:
12- If two hashCode are same for different object then how it will store and what will be the
structure.
Ans:
13- How many object will in String class.
Ans:

14- Set is in Order or UnOrder and why.


Ans:

Anda mungkin juga menyukai