What is JVM? Explain its roles and functions.
Explain why Java is called as Platform independent language. Explain how Java
executable executes on any platform where JVM is available................... Read answer
Explain the features of Java class. Explain Fields, Methods, and Access Levels.
What are accessors and mutator methods in a Java class? Explain with example
for each.
Explain the importance of 'this' reference. Write a code to depicts the use of
'this' reference
Explain static variables and static methods in Java. Provide an example to
explain them.................. Read answer
What is a constructor? Explain the differences between methods and constructor.
Differences between constructors and methods.
Write code to depict the use of constructor..................... Read answer
What is instance members? Explain with an example
What is instance variable? Explain with an example
What is instance method? Explain with an example
What is static member? Explain with an example
What is static variable? Explain with an example...................... Read answer
What are Java packages? Explain the importance of Java packages.
Steps for creating a package in Java
Explain the packages access specifier, i.e. private, protected, public,
default.............
Read answer
Explain Java Garbage collector. Why garbage collection? Brief explanation of
Garbage collection algorithms.
Explain the importance of finalizers in Java. Write code to depict the uses of
finalizers in Java............... Read answer
Explain the importance of 'super' keyword in Java. Write code to depict the uses
of 'super' keyword - The keyword ‘super’ is used for referring parent class
instance.................... Read answer
Define Method overloading. Explain its uses. Provide a code sample to explain
the uses of Method overloading
Define Method overriding. Explain its uses. Provide a code sample to explain
the uses of Method overloading
Difference between overloading and overriding....................... Read
answer
Describe Java string class. Explain methods of Java string class. Explain the
characteristics of StringBuffer class - String Class: The String class is
immutable, The contents of the String object can not be changed, String class
is final class. That implies it can not have sub classes......................
Read answer
What is Java inner class? Explain the types of inner classes, i.e. Static member
classes, Member classes, Local classes, Anonymous classes
Need of inner class in context with adapter classes
Explain few Wrapper Classes Methods............... Read answer
What is Swing? Explain the need of Swing.
Write some important features of Swing.
Describe Java Swing class hierarchy.
Explain the need of Layout manager........... Read answer
Explain different layout manager in Java. - A layout manager organizes the
objects in a container, Different layouts are used to organize or to arrange
objects.............
Read answer
Explain the need of Exception handling.
Explain the Exceptions categories, i.e. checked and unchecked exceptions.
Provide the general form of Exception handling constructs with explanation
What is user defined Exception? Explain with an example............ Read answer
What is Multithreading? Explain the life cycle of a thread.
Explain how to use thread class for Multithreading in Java. Explain with an
example.
What is Runnable interface? Explain how to use Runnable interface for
Multithreading.
What are the methods of thread class in java? Explain them
Can your explain thread priorities?.............. Read answer
Explain the use of Streams.
Difference between Stream classes and Reader writer classes
Explain and demonstrate the use of File, RandomAccessFile classes.
Explain the use of Reader and Writer classes..............
Read answer
What is socket? Explain the features of socket.
Explain the characteristics of Java socket class.
Explain ServerSocket class with an example
Explain InetAddress class with an example
Explain DatagramSocket class with an example
Explain DatagramPacket class with an example............. Read answer
Purposes of JDBC API
Describe 4 types of JDBC drivers and their characteristics with usages.
State the functionalities of important classes in JDBC packages.
Explain how to use JDBC statement to execute SQL queries. Show in an example
Explain how to use Prepared Statement to execute parameterized queries. Show in
an example
What is JDBC Callable Statement?
What is batch updates in JDBC? Explain with an example......................
Read answer
1) Junior java developer a) Basic ocjp (former scjp) questions: – What does static, final mean, purposes; – How many accesibility modifiers exist? Please describe them. – Why do you need a main method? – How many constructors can you have? – Define overwriting and overloading – Give java API implementations for overwriting and overloading – Describe the String class – unique properties – StringBuilder vs StringBuffer – Collections : please describe, give some examples and compare them to eachother – ArrayList vs Vector – HashMap vs HashTable – What’s a tree – What’s a map – Multithreading: describe the management in java – What’s a semaphone? – How many states are there for threads? – Describe the usage for synchronized word (2) – Serialization in java – a descrition and usage – Garbage collection in java – description and usage – Can you guarantee the garbage collection process? b) Simple design pattern questions: – Singleton please describe main features and coding – Factory please describe main features and coding – Have you used others? please describe them
2) Intermediate and Senior level – depending on rate of good responses, additional questions to 1):
If all the methods of a inner class is static then it is a nested class.
What is garbage collection?
Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process
Difference between LinkedList and ArrayList.
LinkedList are meant for sequential accessing.
ArrayList are meant for random accessing.
Define a package.
Packages provides wide namespace ability and allows to group set of classes into a single unit.
Raj 12-5-2011 03:10 AM
Java interview questions and answers
Explain the significance of ListIterator.
Using ListIterator you can iterate back and forth.
Can you explain inner class.
If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.
Can you explain the meaning of aggregation and composition
Aggregation - It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its
reference, then it is called aggregation.
Composition - Holding the reference of the other class within some other class is known as composition.
Is it possible to instantiate the Math class?
You can’t instantiate the math class.
Pankaj 12-5-2011 03:10 AM
Java interview questions and answers
Define Locale.
A Locale object represents a specific geographical, political, or cultural region.
How will you load a specific locale?
By using ResourceBundle.getBundle(…);
Is JVM a compiler or an interpreter?
Interpreter
Can you explain the usages of Class.forName()?
It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).
Inq adds a question: Expain the reason for each keyword of
public static void main(String args[])
Akash 12-5-2011 03:10 AM
Java interview questions and answers
Define reflection.
Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes.
Can you tell me range of byte?
128 to 127
How to invoke external process in Java.
Runtime.getRuntime().exec(….)
What is the best way to findout the time/memory consuming process?
By using profiler
Rakesh 12-5-2011 03:09 AM
Java interview questions and answers
What is skeleton and stub? Explain their purposes.
Stub is a client side representation of the server, which takes care of communicating with the remote server.
What kind of thread is the Garbage collector thread?
Daemon thread
Explain the purpose of Void class.
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
Nitin 12-5-2011 03:09 AM
Java interview questions and answers
Explain the importance of finalize method.
Finalize method cleans up some resources before it get garbage collected.
Define mutable object and immutable object.
The value of Mutable object is changeable. Ex., StringBuffer
The value of an immutable object can't be changed
Ex., String, Integer, Float
What are the base class for Error and Exception?
Throwable
Dharam 12-5-2011 03:09 AM
Java interview questions and answers
Difference between string and stringbuffer object.
String is an immutable object.
StringBuffer is a mutable object.
Define daemon thread.
Daemon thread are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.
Define a DatabaseMetaData.
It represents comprehensive information about the database as a whole.
Jitu 12-5-2011 03:08 AM
Java interview
Explain preemptive scheduling and time slicing.
In preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence.
In time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks.
Explain the different scopes for Java variables.
3 scopes of Java variables are defined below:
Instance
Initialized to default values at the time of creation of object, and remain accessible as long as the object accessible.
Local
Defined within a method and remain accessbile only during the course of method excecution and fall out of scope When the method finishes
execution.
Static
Static variables are the class level variables. Static variables are initialized when the class is loaded in JVM for the first time and remain there as long as the class remains loaded. Static variables are not tied to any particular object instance.
Akash 11-23-2011 02:26 AM
Java interview questions and answers
Explain the purpose of finalization.
It provides an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
Explain the importance of daemon thread.
Daemon thread is a low priority thread. It runs intermittently in the back ground doing the garbage collection operation for the java runtime system.
A daemon thread is created using setDaemon method.
Synchronized methods and synchronized statements.
Synchronized methods
Methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class.
Synchronized statements
They are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
Nitin 11-23-2011 01:31 AM
Java interview questions and answers
What are the way of using thread?
Can be implemented by using runnable interface By inheriting from the Thread class.
Difference between a constructor and a method.
Constructor
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself. It has no return type, and is invoked using the new operator.
Method
A method is an ordinary member function of a class. It has its own name, a return type, and is invoked using the dot operator.
Explain how to serialize an object to a file.
The class whose instances are to be serialized should implement an interface Serializable, pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.
Naveen 11-23-2011 01:25 AM
Java questions and answers
Access Specifiers in Java.
Public- public classes, methods, and fields can be accessed from everywhere.
Protected-
Protected methods and fields can only be accessed within the same class, within its subclasses, and within classes of the same package.
Default(no specifier)
Such a class, method, or field will be accessible from inside the same package to which the class, method, or field belongs, but not from outside this package.
Private
Private methods and fields can only be accessed within the same class. Private methods and fields are not visible within subclasses They are not inherited by subclasses.
Explain static methods.
Static methods are declared with the keyword static as modifier. They are called Static because they affect a class as a whole, not a particular instance of the class. They are always invoked without reference to a particular instance of a class.
Restrictions of using static methods:
It can only call other static methods. It must only access static data. It cannot reference to the current object using keywords super or this.
Priya 11-23-2011 12:55 AM
Java interview questions
Can you tell me the main Implementations of the Set interface?
HashSet TreeSet LinkedHashSet EnumSet
Explain the importance of HashSet.
It is an unsorted, unordered Set. It uses the hashcode of the object being inserted. You can use it when you want a collection with no duplicates and you don’t care about order when you iterate through it.
Explain the importance of TreeSet.
It is a set implementation keeping the elements in sorted order. The elements are sorted according to the natural order of elements or by the comparator provided at creation time.
Tina 11-23-2011 12:46 AM
Java interview questions and answers
Define native method.
A native method is implemented in a language other than Java.
Explain explicit casting.
In Explicit casting, the complier are specifically informed about transforming the object.
Example
long a = 890.20;
int b = (int) a; //Explicit casting
Explain implicit casting.
Assigning one entity to another without any transformation guidance to the compiler is implicit casting. This type of casting is not permitted in all kinds of transformations and may not work for all scenarios.
Example
int a = 6000;
long b = a; //Implicit casting
Explain reflection API
Reflection is the process of introspecting the features and state of a class at runtime and dynamically manipulate at run time. This is supported using Reflection API with built-in classes like Class, Method, Fields, Constructors etc.
Example: Using Java Reflection API we can get the class name, by using the getName method.
Rajeev 11-22-2011 04:07 AM
Java interview questions and answers
Explain the importance of Java Virtual Machine (JVM).
It converts .java file into .class file by using Compiler and Interpreter reads byte codes.
Explain the different types of access modifiers in Java.
They determine the type of access to the member of a class.
Types:
-Public : accessible to all classes -Protected : accessible to the classes within the same package and any subclasses. -Private : accessible only to the class to which they belong -Default : accessible to the class to which they belong and to subclasses within the same package
Why there are no global variables in Java?
Global variables are globally accessible and hence can create collisions in namespace.
What is the Java API?
It a large collection of software components that provide capabilities, such as graphical user interface (GUI) widgets.
Rajeev 11-22-2011 03:48 AM
Java interview questions and answers
Explain StringTokenizer.
It is utility class that are used to break up string.
Example:
StringTokenizer str = new StringTokenizer(“Welcome”);
while (str.hasMoreTokens()) {
System.out.println(st.nextToken());
}
Nadeem 11-22-2011 03:42 AM
Java interview questions and answers
Difference between the boolean & operator and the && operator.
When boolean & operator is evaluated, both operands are evaluated && operator is a short cut operator.
When && operator is evaluated, the first operand is evaluated. When first operand returns a value of true then the second operand is evaluated. When first operand evaluates to false, the evaluation of the second operand is skipped.
Nadeem 11-22-2011 03:40 AM
Java interview questions
Does Java support pointers?
Java doesn't support the usage of pointers. Improper handling of pointers leads to memory leaks which is why pointer concept hasn't found place in Java.
Swing and Awt
AWT are heavy-weight componenets. Swings are light-weight components and this is reason why swing works faster than AWT.
Pass by reference and passby value
Pass By Reference is the passing the address itself rather than passing the value. Passby Value is passing a copy of the value to be passed.
Rakesh S 11-4-2011 01:26 AM
Java interview questions
Abstract class
It must be extended or subclassed. It acts as a template. It may contain static data. A class may be declared abstract even if it has no abstract methodsand this prevents it from being instantiated.
Annie 11-4-2011 01:21 AM
Java interview questions and answers - April 18, 2011
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.
Java interview questions and answers - April 20, 2011
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.
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
Java interview questions and answers - April 21, 2011
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.