Wednesday, January 16, 2008

Core Java Frequently Asked Questions

Q. Is Java pure oop?
a) yes

Q. what are oop concepts?
a) 1. encapsulation 2. -abstraction 3. inheritance 4. polymorphism

Q. what is encapsulation?
a) Encapsulation is raping up of data and methods into a single class.

Q. what is abstraction?
a) hiding the details

Q. what is inheritence?

Q. what is polymorphism? Types? How can you achieve them?
a) many forms.

Q. What is runtime polymorphism?
Q. What is class? what is an instance? Difference between them?
Q. what is interface?

Q. Difference between overriding & overloading?
a) overriding - writing same method more than one time with different signature in the same
lass is called overriding.
overloading - writing same method with same signature in base class and derived class is
called overloading.

Q. Explain System.out.println();
a) System - system is a class in java.lang package.
out - out is an object of PrintStream type.
println() - println() is a method in that object.

Q. what is abstract class?
Q. Abstract class has constructors?
Q. If a class donot have constructors then what will happen?
Q. Who will call default constructors?
Q. what is concrete class?
Q. what is abstract method?
Q. what is final class?
Q. what is final method?
Q. what is final field?
Q. Can we change final field method?
Q. How to count no of instances for an object?
Q. Example class for final class from API?
Q. How to sort by using field?
Q. what is base class for java?
Q. what is base class for exception?
Q. how to handle exceptions in java?
Q. What is exception?
Q. Difference between abstract class and interface?
Q. Can we override or overload a static method with non static method?
Q. Is java support multiple inheritance?
Q. Can we use this in static method?
Q. Interface has constructors?
a) no

Q. Interface has constants?
a) yes

Q. Can we extend interface with another interface?
a) yes.

Q. How to convert Integer to String?
a) Integer.toString(int i);
Q) What is wrapper class?
Q. Different types of exceptions?
a) 1.checkedExceptions and 2. uncheckedExceptions.

Q. Differences between checked and unchecked exceptions?
Q. What exceptions you have handled in your project?

Q. How you handle NULLpointerExceptions?
a) using if else

Q. When garbage collector collects the objects?
a) If an object is no loger time used by the user and is set to null then garbage collector will collect the objects

Q. what is finally block? and why finally block?

Q. Is there any order imposed on writing catch blocks after try block?
a) yes.

Q. Difference between string and string buffer?
a) String - immutable
StringBuffer - mutable

Q. What is mutable and immutable?
a) Mutable - can alter the contents.
Immutable - can't alter the contents.

Q. How to handle threading in java? or How to write multithreading in java?
a) 1. Thread class 2. Runnable interface.

Q. when we will use runnable interface?
a) If you want to extend another class

Q. Thread life cycle?
Q. Thread States?

Q. How thread communication will happend?
a) 1. wait 2. notify 3. notify all

Q. What is dynathread?
a) A thread with least priority

Q. How will you set priorities of thread?
a) Using setPriority() method.

Q. Different types of priorities?
a) 1. MIN_PRIORITY 2. NORM_PRIORITY 3. MAX_PRIORITY

Q. Is stop() = sleep()?
a) No.

Q. How to stop next transaction for next 5min?
a) sleep(time);

Q. How to stop a thread?
a) using stop() method.

Q. What is multithreading?
Q. what is clonable?

Q. what is serialization?
a) Serialization is a process of writing a state of an object to a byte stream.

Q. How to make a class serializable?
a) Extend Serialozable interface.

Q. How can we serialize some instaces of objects rather than entire class? or how to stop serialization?
a) By specifing a field as trancient

Q. How to make a class deserializable?
Q. what is deserialization?

Q. How to deserialize Transient data?
a) We cant deserialize transient data.

Q. Where we use volatile?
a) if u specify a variable as volatile all threads will work on master data.

Q. What is singleton class?
Q. How to make a class singleton?
Q What is ananymous class?

Q. What is externalization?
a) Compressing or encryption of an object

Q. command for creating zar file?

Q. What is outputStream?
a) OutputStream is an abstract class.

Q. Equals which class method?
a) Object

Q. Difference between equals and ==?
Q. how to set class path?
Q. what is dynamic binding?

Q. what is DTD?
a) DTD is document type definition

Q. what is synchoronous and asynchoronous?
a) Synchronous - synchoronous is multiple threads can't access a resource at a time.
asynchrouns - asynchoronous is multiple threads can access a resource at a time.

Q. Difference between ArrayList and vector?
a) ArrayList - ArrayList is asynchronous and collection class
Vector - Vector is synchronous and legacy calss

Q. Methods in vector?

Q. Difference between iterator and enum?
a) iterator works as pointer for collection.
enum works as pointer for legacy.

Q. Write program for access elements from hash table?

Q. Difference between map and hashMap?
a) HashMap is following hashing techniques so accessing is easy compared to map.

Q. Difference between HashTable and HashMap?
a) HashTable is legacy and synchronous.
HashMap is collection and asynchoronous.

Q. Difference between vector and array?
a) array can store same type of objects.
vector can store different types of objects.

Q. Difference between arraylist and linkedlist?
a) ArrayList maintains index. It is useful for random access.
LinkedList is doubleLinked List it maintains 2 pointers add, delete elements at starting and ending is faster.

Q. Difference between collection and Collections?

Q. How to make a collection synchoronize?
a) Collections.synchronizedMap(new HashMap());
Collections.synchronizedSet(new HashSet());
Collections.synchronizedList(new List());
..................

Q. How to make a list read only?
a) Collections.unModifiableList();

Q. How to sort vector elements?

Q. What is the purpose of Arrays class?
a) Arrays class is for sorting and searching.

Q. How can your implement hashMap if you are not having it in java?

Q. What is cocoon?
a) cocoon is a frame work.

Q. Difference between SAX and DOM?
Q. Explain some sorting techniques?

Q. How to create jar file?
a) jar -cf filename.jar *.class

Q. How to extract a jar file?
a) jar -xf filename.jar

Q. How to find version of java?
a) java -version



No comments: