Proxy > Gmail Facebook Yahoo!

Java interview questions and answers



What is an abstract method?

An abstract method is a method which doesn’t have a body, just declared with modifier abstract.

Explain the use of the finally block.

Finally block is a block which always executes. The block executes even when an exception is occurred. The block won't execute only when the user calls System.exit()

What is the initial state of a thread?

It is in a ready state.

What is time slicing?

In time slicing, the task continues its execution for a predefined period of time and reenters the pool of ready tasks.

What are Wrapper Classes?

Wrapper Classes allow to access primitives as objects.

What is List interface?

List is an ordered collection of objects.

Can you explain transient variables in java?

They are the variables that cannot be serialized.

What is synchronization?

Synchronization ensures only one thread to access a shared resource, thus controls the access of multiple threads to shared resources.

What is serialization?

Serialization helps to convert the state of an object into a byte stream.

What is HashMap and Map?

Map is Interface and Hashmap is class that implements that.

Explain the usage of serialization.

Objects are serialized when need to be sent over network.
They are serialized when the state of an object is to be saved.

How are Observer and Observable used?

The observable class represents an observable object.
The object to be observed can be represented by sub-classing observable class.
When there is a change in an observable instance, an application calling the Observable's notifyObservers method causes all of its observers to be notified of the change by a call to their update method.

Difference between Swing and Awt.

AWT are heavy-weight components. Swings are light-weight components. Thus, swing works faster than AWT.

Define inner class in Java

Class that is nested within a class is called as inner class. The inner class can access private members of the outer class. It is mainly used to implement data structure and some time called as a helper class.

Differences between constructors and methods.

A constructor is used to create objects of a class. A method is an ordinary member in a class.
Constructor does not have a return type. A method should have a return type.
Constructor name is the name of the class. A method name should not be the name of the class
Constructor is invoked at the time of creation of the class. Method needs to be invoked in another method by using the dot operator.
Constructor can not have ‘return’ statement. All methods that return non-void return type should have ‘return’ statement.

Define Method overriding. Explain its uses.

Method overriding is the process of writing functionality for methods with same signature and return type, both in super class and subclass The uses of method overriding:
Time to invest method signature is reduced
Different functionality in both super class and sub class by sharing same signature
The functionality can be enhanced
The behavior can be replaced in the sub class

What is the purpose of the File class?

The File class provides access to the files and directories of a local file system.

What is StringBuffer class?

StringBuffer class is same as String class with the exception that it is mutable. It allows change and doesn’t create a new instance on change of value.

How can you force garbage collection?

It is not possible to force GC. We can just request it by calling System.gc().

Is it possible an exception to be rethrown?

Yes, an exception can be rethrown.

What is the return type of a program’s main() method?

A program’s main() method has a void return type.

Which package is always imported by default?

The java.lang package is always imported by default.

Java interview questions and answers - April 19, 2011

What is a Class?

A class implements the behavior of member objects by describing all the attributes of objects and the methods.

What is an Object?

An object is the members of a class. It is the basic unit of a system. It has attributes, behavior and identity.

Explain the use of "instanceOf" keyword.

"instanceOf" keyword is used to check the type of object.

How do you refer to a current instance of object?

You can refer the current instance of object using "this" keyword.

What is the use of JAVAP tool?

JAVAP is used to disassemble compiled Java files. This option is useful when original source code is not available.

In which package is the applet class located?

Applet classes are located in "java.applet" package.

Java array vs. ArrayList class.

ArrayList is a dynamic array that can grow depending on demand whereas Java arrays are fixed length.

Explain Enumeration Interface.

It defines the methods using which we can enumerate the elements in a collection of objects.

What are access modifiers?

Access modifiers determine if a method or a data variable can be accessed by another method in another class.

Explain the impact of private constructor.

Private constructor prevents a class from being explicitly instantiated by callers.

What is an exception?

An exception is an abnormal condition that arises in a code sequence at run time

What are ways to create threads?

There are two ways to create a thread:
extend the java.lang.Thread class
implement the java.lang.Runnable interface

How can we stop a thread programmatically?

thread.stop;

What are daemon threads?

Daemon threads are designed to run in background. An example of such thread is garbage collector thread.

What are the different types of locks in JDBC?

There are four types of major locks in JDBC:
Exclusive locks
Shared locks
Read locks
Update locks

What are Servlets?

Servlets are program that run under web server environments.

What are the different ways to maintain state between requests?

There are four different ways:
URL rewriting
Cookies
Hidden fields
Sessions

What are wrapper classes?

In Java we have classes for each primitive data types. These classes are called as wrapper class. For example, Integer, Character, Double etc.

What are checked exceptions?

There are exceptions that are forced to catch by Java compiler, e.g IOException. Those exceptions are called checked exceptions.

What is the Locale class?

Locale class is a class that converts the program output to a particular geographic, political, or cultural region

Is main a keyword in Java?

No, main is not a keyword in Java.

What is the most important feature of Java?

Platform independency makes Java a premium language.

What is a JVM?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

Does Java support multiple inheritances?

No, Java doesn't support multiple inheritances.

What is the base class of all classes?

java.lang.Object

Can a class be declared as protected?

A class can't be declared as protected. Only methods can be declared as protected.

Can an abstract class be declared final?

No, since it is obvious that an abstract class without being inherited is of no use.

Can we declare a variable as abstract?

Variables can't be declared as abstract. Only classes and methods can be declared as abstract.

Define Marker Interface.

An Interface which doesn't have any declaration inside but still enforces a mechanism.

What is an abstract method?

An abstract method is a method whose implementation is deferred to a subclass.

When can an object reference be cast to an interface reference?

An object reference is cast to an interface reference when the object implements the referenced interface.

Which class is extended by all other classes?

The Object class is extended by all other classes.

What is the return type of a program's main() method?

void.

What are the eight primitive Java types?

The eight primitive types are byte, char, short, int, long, float, double, and boolean.

Difference between a public and a non-public class.

A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

Which Java operator is right associative?

The = operator is right associative.

What is a transient variable?

Transient variable is a variable that may not be serialized.


Responses

0 Respones to "Java interview questions and answers"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar