12
JAVA TOP QUESTIONS www.futurepathfinder.com JAVA INTERVIEW QUESTION Here we are presenting the important question asked in an java interview. These are the beat question with answer collected for the interview it consists of all the important question which can be asked an interview. Q: - What's the difference between J2SDK 1.5 and J2SDK 5.0? There's no difference, Sun Microsystems just re-branded this version. Q: - What is the use of bin and lib in JDK? bin contains all tools such as javac, applet viewer, awt tool etc., whereas lib contains all packages and variables Q: - What declarations are required for every Java application? A class and the main( ) method declarations. Q: - Is a class a subclass of itself? Yes Q: - What modifiers may be used with top-level class? public Abstract final. Q: - Which method is used to garbage collect an object? Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

java_interview_q&a.pdf

  • Upload
    rahulv

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

Page 1: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

JAVA INTERVIEW QUESTION

Here we are presenting the important question asked in an java interview. These are the beat question with answer collected for the interview it consists of all the important question which can be asked an interview.

Q: - What's the difference between J2SDK 1.5 and J2SDK 5.0?

There's no difference, Sun Microsystems just re-branded this version.

Q: - What is the use of bin and lib in JDK?

bin contains all tools such as javac, applet viewer, awt tool etc., whereas lib contains all packages and variables

Q: - What declarations are required for every Java application?

A class and the main( ) method declarations.

Q: - Is a class a subclass of itself?

Yes

Q: - What modifiers may be used with top-level class?

public

Abstract

final.

Q: - Which method is used to garbage collect an object?

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 2: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

finalize ()

Q: - You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList?

ArrayList

Q: - Can you write a Java class that could be used both as an applet as well as an application?

Yes, Add a main() method to the applet.

Q: - Explain the usage of the keyword transient?

This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

Q: - How can you force garbage collection?

You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

Q: - What methods java providing for Thread communications ?

Java provides three methods that threads can use to communicate with each other: wait, notify, and notifyAll. These methods are defined for all Objects (not just Threads). The idea is that a method called by a thread may need to wait for some condition to be satisfied by another thread; in that case, it can call the wait method, which causes its thread to wait until another thread calls notify or notifyAll.

Q: - Can I call a abstract method from a non abstract method ?

Yes, We can call a abstract method from a Non abstract method in a Java abstract class

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 3: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

Q: - What is a collection ?

Collection is a group of objects. java.util package provides important types of collections. There are two fundamental types of collections they are Collection and Map. Collection types hold a group of objects, Eg. Lists and Sets where as Map types hold group of objects as key, value pairs Eg. HashMap and Hashtable.

Q: - What is super?

Super is a keyword which is used to access the method or member variables from the superclass.

Q: - What are the three OOPs principles and define them?

Encapsulation, Inheritance and Polymorphism are the three OOPs Principles.

Q: - What is Encapsulation?

Encapsulation is a technique used for hiding the properties and behaviors of an object and allowing outside access only as appropriate. It prevents other objects from directly altering or accessing the properties or methods of the encapsulated object.

Q: - What is Dynamic Binding?

Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time.

Q: - What is Abstraction?

Abstraction refers to the act of representing essential features without including the background details or explanations.

Q: - What is an abstract class?

Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation.

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 4: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

Q: - When you declare a method as abstract, can other nonabstract methods access it?

Yes

Q: - Can there be an abstract class with no abstract methods in it?

Yes

Q: - How do you achieve multiple inheritances in Java?

We can use interfaces.

Q: - Is it possible to use few methods of an interface in a class ? If so, how?

Yes. Declare the class as abstract.

Q: - What is Constructor?

A constructor is a special method whose task is to initialize the object of its class.

Q: - Can constructor be inherited?

No

Q: - How this() is used with constructors?

this() is used to invoke a constructor of the same class.

Q: - How super() used with constructors?

super() is used to invoke a super class constructor

Q: - What is an EntrySet View?

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 5: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

Entry Set view is a set that is returned by the entrySet() method in the map and contains Objects of type Map.

Q: - What is a KeySet View ?

KeySet is a set returned by the keySet() method of the Map Interface, It is a set that contains all the keys present in the Map.

Q: - What is a Map ?

A map is an object that stores associations between keys and values (key/value pairs).

Q: - What are the main Implementations of the Map interface ?

HashMap

HashTable

TreeMap

EnumMap

Q: - What is an EnumSet ?

An EnumSet is a specialized set for use with enum types, all of the elements in the EnumSet type that is specified, explicitly or implicitly, when the set is created.

Q: - What is Dictionary class?

The Dictionary class is the abstarct super class of Hashtable and Properties class.Dictionary provides the abstarct functions used to store and retrieve objects by key value. This class allows any object to be used as a key or value.

Q: - What is the Hashtable class?

The Hashtable class implements a hash table data structure. A hash table indexes and stores objects in a dictionary using hash codes as the objects' keys

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 6: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

Q: - Why would you use a synchronized block vs. synchronized method?

Synchronized blocks place locks for shorter periods than synchronized methods.

Q: - Is it possible to override the main method?

NO, because main is a static method. A static method can't be overridden in Java.

Q: - What is the List interface?

The List interface provides support for ordered collections of objects. Lists may contain duplicate elements.

Q: - Can we instantiate an interface?

You can’t instantiate an interface directly, but you can instantiate a class that implements an interface.

Q: - Can we create an object for an interface?

Yes

Q: - Is it is necessary to implement all methods in an interface?

Yes

Q: - What are the two types of multitasking?

process-based

Thread-based

Q: - What is the % operator?

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 7: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

The % operator is the modulo operator or reminder operator. It returns the reminder of dividing the first operand by second operand.

Q: - What is the Java API?

Java API is not but a set of classes and interfaces that comes with the JDK. Java API is actually a huge collection of library routines that performs basic programming tasks such as looping, displaying GUI Forms etc

Q: - What is java native interface?

The Java Native Interface (JNI) is a programming framework that allows Javacode running in a Java Virtual Machine (JVM) to call and to be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages, such as C, C++ and assembly.

Q: - What is Java Virtual Machine?

A Java Virtual Machine (JVM) enables a set of computer software programs and data structures to use a virtual machine model for the execution of other computer programs and scripts.

Q: - What is the ActionForm?

ActionForm is javabean which represents the form inputs containing the request parameters from the View referencing the Action bean.

Q: - What are the important methods of ActionForm?

validate()

reset()

Q: - What is ActionMapping?

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 8: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

Action mapping contains all the deployment information for a particular Action bean. This class is to determine where the results of the Action will be sent once its processing is complete.

Q: - What is role of Action Class?

An Action Class performs a role of an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request.

Q: - What modifiers are allowed for methods in an Interface?

public

abstract

Q: - What are the advantages of ArrayList over arrays ?

It can grow dynamically

It provides more powerful insertion and search mechanisms than arrays.

Q: - Can null value be added to a List?

Yes

Q: - How do we change the values of the elements of the array?

The array subscript expression can be used to change the values of the elements of the array.

Q: - Which method waits for the thread to die ?

join() method

Q: - What is the default thread at the time of starting the program?

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 9: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

main thread

Q: - What is the method available for setting the priority?

setPriority()

Q: - Garbage collector thread belongs to which priority?

low-priority

Q: - What are the possible access modifiers when implementing interface methods?

public

Q: - What are all the methods available in the Runnable Interface?

run()

Q: - What are the ways in which a thread can enter the waiting state?

1. It can also enter the waiting state by invoking it's suspend() method.

2. By blocking an I/O and unsuccessful attempt to acquire an object's lock or by invoking an object's wait() method.

3. A Thread can enter waiting state by invoking sleep() method.

Q: - Can we have catch block with out try block?

No

Q: - Which methods in the Object class are declared as final?

getClass()

notify()

notifyAll()

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 10: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

wait()

Q: - What is a framework?

A framework is made up of the set of classes which allow us to use a library in a best possible way for a specific requirement.

Q: - What is casting?

Casting is process of convert the value of one type to another.

Q: - What is phantom memory?

Phantom memory is false memory. Memory that does not exist in reality.

Q: - What is MVC?

Model-View-Controller (MVC) is a design pattern put together to help control change.

Q: - What are the components of Struts?

Model

View

Controller

Q: - Can we have more than one struts-config.xml file for a single Struts application?

Yes

Q: - What are the different kinds of actions in Struts?

IncludeAction

SwitchAction

ForwardAction

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 11: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

DispatchAction

LookupDispatchAction

Q: - What is IncludeAction?

The IncludeAction class is useful when you want to integrate Struts into an application that uses Servlets.

Q: - What is SwitchAction?

The SwitchAction class provides a means to switch from a resource in one module to another resource in a different module. SwitchAction is useful only if you have multiple modules in your Struts application.

Q: - What is the GenericServlet class?

GenericServlet is an abstract class that implements the Servlet interface and the ServletConfig interface.

Q: - What are the uses of Servlet?

Processing and/or storing data submitted by an HTML form.

Providing dynamic content, e.g. returning the results of a database query to the client.

A Servlet can handle multiple requests concurrently and be used to develop high performance system

Managing state information on top of the stateless HTTP, e.g. for an online shopping cart system which manages shopping carts for many concurrent customers and maps every request to the right customer.

Q: - Why is HttpServlet declared abstract?

The HttpServlet class is declared abstract because the default implementations of the main service methods do nothing and must be overridden.

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.

Page 12: java_interview_q&a.pdf

JAVA TOP QUESTIONS www.futurepathfinder.com

Q: - How to display validation errors on jsp page?

<html:errors/> tag displays all the errors. <html:errors/> iterates over ActionErrors request attribute.

For more updates of job/placement paper/interview question just join us with facebook at www.facebook.com/groups/futurepathfinder

Disclaimer: All the matters in this document is true to our knowledge.And we are not responsible for any mistake and misprint in document.