SlideShare a Scribd company logo
java interview Questions
Here's some more java questions:
1) Junior java developer
a) Basic ocjp (former scjp) questions:
– What does static,final mean,purposes;
– How many accesibilitymodifiers 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 managementin 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):
http://centraladvisor.com/programming-2/java/java-developer-interview
Bogdan 08-1-2012 10:34 AM
Java interview questions and answers
Explain the importance of DriverManager.
The basic service to manage setof JDBC drivers.
What are the methods in Object?
clone,equals,wait,finalize, getClass,hashCode,notify, notifyAll, toString
Define a nested class.
If all the methods ofa inner class is static then it is a nested class.
What is garbage collection?
Reclaiming the unused memoryby the invalid objects.Garbage collector is res ponsible for this process
Difference betweenLinkedList and ArrayList.
LinkedListare meantfor sequential accessing.
ArrayList are meantfor random accessing.
Define a package.
Packages provides wide namespace abilityand allows to group setof 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 ofthe inner class can only be accessed via the instance ofthe 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.Ifyou expose all the methods ofa 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’tinstantiate the math class.
Pankaj 12-5-2011 03:10 AM
Java interview questions and answers
Define Locale.
A Locale objectrepresents 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 thatyou 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 aboutthe fields,methods and constructors ofloaded classes.
Can you tell me range of byte?
128 to 127
How to invoke externalprocess 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 clientside representation ofthe 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 objectrepresenting 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 itgetgarbage collected.
Define mutable object and immutable object.
The value of Mutable object is changeable.
Ex., StringBuffer
The value of an immutable objectcan'tbe 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 betweenstring and stringbuffer object.
String is an immutable object.
StringBuffer is a mutable object.
Define daemon thread.
Daemon thread are the threads which can run withoutuser intervention.
The JVM can exit when there are daemon thread by killing them abruptly.
Define a DatabaseMetaData.
It represents comprehensive information aboutthe database as a whole.
Jitu 12-5-2011 03:08 AM
Java interview
Explain preemptive scheduling and time slicing.
In preemptive scheduling,the highestpriority 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 oftime and then reenters the pool of ready tasks.
Explain the different scopes for Java variables.
3 scopes ofJava variables are defined below:
Instance
Initialized to defaultvalues at the time of creation of object, and remain accessible as long as the objectaccessible.
Local
Defined within a method and remain accessbile onlyduring the course of method excecution and fall out of scope When the method fin
execution.
Static
Static variables are the class level variables.
Static variables are initialized when the class is loaded in JVM for the firsttime and remain there as long as the class remains loaded.
Static variables are not tied to any particular objectinstance.
Akash 11-23-2011 02:26 AM
Java interview questions and answers
Explain the purpose of finalization.
It provides an unreachable objectthe opportunity to perform any cleanup processing before the objectis garbage collected.
Explain the importance of daemon thread.
Daemon thread is a low priority thread.
It runs intermittentlyin 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 objector class.
Synchronized statements
They are similar to synchronized methods.
A synchronized statementcan only be executed after a thread has acquired the lock for the object or class referenced in the synchroni
statement.
Nitin 11-23-2011 01:31 AM
Java interview questions and answers
What are the way of using thread?
Can be implemented byusing runnable interface
By inheriting from the Thread class.
Difference betweena constructor and a method.
Constructor
A constructor is a member function ofa class thatis used to create objects ofthat 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 implementan interface Serializable,pass the instance to the ObjectOutputStrea
which is connected to a fileoutputstream.This will save the objectto 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 onlybe accessed within the same class,within its subclasses,and within classes ofthe sam e packa
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,butnotfrom
outside this package.
Private
Private methods and fields can onlybe accessed within the same class.
Private methods and fields are notvisible 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 ofthe class.
They are always invoked without reference to a particular instance ofa class.
Restrictions ofusing static methods:
It can only call other static methods.
It mustonly access static data.
It cannotreference to the current objectusing 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 ofthe objectbeing inserted.
You can use it when you want a collection with no duplicates and you don’tcare about order when you iterate through it.
Explain the importance of TreeSet.
It is a setimplementation 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 specificallyinformed abouttransforming 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 implicitcasting.
This type of casting is not permitted in all kinds of transformations and maynotwork for all scenarios.
Example
int a = 6000;
long b = a; //Implicitcasting
Explain reflection API
Reflection is the process ofintrospecting the features and state of a class atruntime and dynamicallymanipulate atrun time.
This is supported using Reflection APIwith built-in classes like Class,Method, Fields,Constructors etc.
Example:Using Java Reflection API we can get the class name, byusing 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 ofa class.
Types:
-Public : accessible to all classes
-Protected : accessible to the classes within the same package and anysubclasses.
-Private : accessible onlyto 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 globallyaccessible and hence can create collisions in namespace.
What is the Java API?
It a large collection of software components thatprovide 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 thatare 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 betweenthe boolean & operator and the && operator.
When boolean & operator is evaluated, both operands are evaluated
&& operator is a shortcut operator.
When && operator is evaluated, the first operand is evaluated.
When firstoperand returns a value of true then the second operand is evaluated.
When firstoperand evaluates to false,the evaluation of the second operand is skipped.
Nadeem 11-22-2011 03:40 AM
Java interview questions
Does Java supportpointers?
Java doesn'tsupportthe usage ofpointers.Improper handling ofpointers leads to memoryleaks which is whypointer concept hasn't fo
place in Java.
Swing and Awt
AWT are heavy-weight componenets.
Swings are light-weightcomponents and this is reason whyswing works faster than AWT.
Pass by reference and passbyvalue
Pass By Reference is the passing the address itselfrather than passing the value.
PassbyValue is passing a copy of the value to be passed.
Rakesh S 11-4-2011 01:26 AM
Java interview questions
Abstract class
It mustbe extended or subclassed.
It acts as a template.
It may contain static data.
A class maybe declared abstracteven if it has no abstractmethodsand this prevents itfrom being instantiated.
Annie 11-4-2011 01:21 AM
Java interview questions and answers - April 18, 2011
What is an abstract method?
An abstractmethod is a method which doesn’thave a body, justdeclared 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 oftime and reenters the pool of ready tasks.
What are Wrapper Classes?
Wrapper Classes allow to access primitives as objects.
What is List interface?
Listis an ordered collection ofobjects.
Can you explain transient variables in java?
They are the variables thatcannot be serialized.
What is synchronization?
Synchronization ensures onlyone thread to access a shared resource,thus controls the access ofmultiple 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 thatimplements 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’tcreate a
new instance on change of value.
How can you force garbage collection?
It is not possible to force GC. We can justrequestitby 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 bydescribing all the attributes of objects and the methods.
What is an Object?
An objectis the members ofa class.It is the basic unitof 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 objectusing "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 notavailable.
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 ofobjects.
What are access modifiers?
Access modifiers determine ifa method or a data variable can be accessed byanother method in another class.
Explain the impact of private constructor.
Private constructor prevents a class from being explicitlyinstantiated by callers.
What is an exception?
An exception is an abnormal condition thatarises in a code sequence atrun 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
implementthe 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 e xample,
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 thatconverts the program outputto a particular geographic,political,or cultural region
Is main a keyword in Java?
No, main is nota keyword in Java.
What is the most important feature of Java?
Platform independencymakes Java a premium language.
What is a JVM?
JVM is Java Virtual Machine which is a run time environmentfor the compiled java class files.
Does Java support multiple inheritances?
No, Java doesn'tsupportmultiple inheritances.
What is the base class of all classes?
java.lang.Object
Can a class be declared as protected?
A class can'tbe 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 withoutbeing inherited is ofno use.
Java interview questions and answers - April 22,
2011
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'thave any declaration inside butstill enforces a mechanism.
What is an abstract method?
An abstractmethod is a method whose implementation is deferred to a subclass.
When can an object reference be cast to an interface reference?
An objectreference 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 eightprimitive types are byte, char, short,int, long, float, double,and boolean.
Difference between a public and a non-public class.
A public class maybe accessed outside ofits package.A non-public class maynotbe accessed outside ofits
package.
Which Java operator is right associative?
The = operator is right associative.
What is a transient variable?
Transientvariable is a variable that may not be serialized.

More Related Content

PPTX
Java interview questions 1
DOCX
Viva file
PPTX
Java interview questions 2
DOC
Questions of java
PDF
PDF
Java - Basic Concepts
PDF
Object oriented programming
Java interview questions 1
Viva file
Java interview questions 2
Questions of java
Java - Basic Concepts
Object oriented programming

What's hot (19)

PPT
7. Multithreading
PPT
Most Asked Java Interview Question and Answer
PDF
Java questions for interview
PPT
Java tutorials
DOCX
SQL Interview Questions For Experienced
PPTX
oops concept in java | object oriented programming in java
DOCX
Java Interview Questions For Freshers
PDF
Java Faqs useful for freshers and experienced
PDF
Packages
PPT
Unit 3 Java
DOCX
Core java notes with examples
PDF
Object Oriented Programming using JAVA Notes
DOC
Java interview questions
PPTX
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
PDF
Access modifiers
PPT
Java oops and fundamentals
PPT
Object Oriented Programming with Java
PPTX
OOPs in Java
PPT
Core Java interview questions-ppt
7. Multithreading
Most Asked Java Interview Question and Answer
Java questions for interview
Java tutorials
SQL Interview Questions For Experienced
oops concept in java | object oriented programming in java
Java Interview Questions For Freshers
Java Faqs useful for freshers and experienced
Packages
Unit 3 Java
Core java notes with examples
Object Oriented Programming using JAVA Notes
Java interview questions
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Access modifiers
Java oops and fundamentals
Object Oriented Programming with Java
OOPs in Java
Core Java interview questions-ppt
Ad

Similar to Java interview questions (20)

PDF
Java Interview Questions
PPT
Java interview-questions-and-answers
PDF
__ Java Technical round questions .pdf soo
PDF
Java interview question
PDF
Top 100 Java Interview Questions with Detailed Answers
DOC
Core java interview questions1
PDF
50+ java interview questions
DOC
Core java questions
DOC
Core java questions
PPTX
Java J2EE Interview Questions Part-1
PPTX
Java J2EE Interview Questions Part-1
DOCX
Jist of Java
DOCX
JAVA CONCEPTS AND PRACTICES
DOCX
Core java questions
PPTX
25 java interview questions
PDF
Core java interview faq
PDF
Asked Java Interview Questions for fresher
PPTX
Java_Interview Qns
PDF
Java apptitude-questions-part-2
DOCX
Java questions for viva
Java Interview Questions
Java interview-questions-and-answers
__ Java Technical round questions .pdf soo
Java interview question
Top 100 Java Interview Questions with Detailed Answers
Core java interview questions1
50+ java interview questions
Core java questions
Core java questions
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1
Jist of Java
JAVA CONCEPTS AND PRACTICES
Core java questions
25 java interview questions
Core java interview faq
Asked Java Interview Questions for fresher
Java_Interview Qns
Java apptitude-questions-part-2
Java questions for viva
Ad

Recently uploaded (20)

PDF
Roadmap Map-digital Banking feature MB,IB,AB
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
PDF
WRN_Investor_Presentation_August 2025.pdf
PDF
A Brief Introduction About Julia Allison
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
PPTX
HR Introduction Slide (1).pptx on hr intro
PDF
Chapter 5_Foreign Exchange Market in .pdf
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PDF
DOC-20250806-WA0002._20250806_112011_0000.pdf
PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
PPTX
Probability Distribution, binomial distribution, poisson distribution
PPTX
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
PDF
Unit 1 Cost Accounting - Cost sheet
PDF
IFRS Notes in your pocket for study all the time
PPTX
Principles of Marketing, Industrial, Consumers,
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
PDF
MSPs in 10 Words - Created by US MSP Network
DOCX
Business Management - unit 1 and 2
Roadmap Map-digital Banking feature MB,IB,AB
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
WRN_Investor_Presentation_August 2025.pdf
A Brief Introduction About Julia Allison
Belch_12e_PPT_Ch18_Accessible_university.pptx
HR Introduction Slide (1).pptx on hr intro
Chapter 5_Foreign Exchange Market in .pdf
340036916-American-Literature-Literary-Period-Overview.ppt
DOC-20250806-WA0002._20250806_112011_0000.pdf
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
Probability Distribution, binomial distribution, poisson distribution
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
Unit 1 Cost Accounting - Cost sheet
IFRS Notes in your pocket for study all the time
Principles of Marketing, Industrial, Consumers,
Power and position in leadershipDOC-20250808-WA0011..pdf
MSPs in 10 Words - Created by US MSP Network
Business Management - unit 1 and 2

Java interview questions

  • 1. java interview Questions Here's some more java questions: 1) Junior java developer a) Basic ocjp (former scjp) questions: – What does static,final mean,purposes; – How many accesibilitymodifiers 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 managementin 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): http://centraladvisor.com/programming-2/java/java-developer-interview Bogdan 08-1-2012 10:34 AM Java interview questions and answers Explain the importance of DriverManager. The basic service to manage setof JDBC drivers. What are the methods in Object? clone,equals,wait,finalize, getClass,hashCode,notify, notifyAll, toString Define a nested class. If all the methods ofa inner class is static then it is a nested class. What is garbage collection? Reclaiming the unused memoryby the invalid objects.Garbage collector is res ponsible for this process
  • 2. Difference betweenLinkedList and ArrayList. LinkedListare meantfor sequential accessing. ArrayList are meantfor random accessing. Define a package. Packages provides wide namespace abilityand allows to group setof 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 ofthe inner class can only be accessed via the instance ofthe 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.Ifyou expose all the methods ofa 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’tinstantiate the math class. Pankaj 12-5-2011 03:10 AM Java interview questions and answers Define Locale. A Locale objectrepresents 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
  • 3. Can you explain the usages of Class.forName()? It loads the class into the ClassLoader.It returns the Class.Using thatyou 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 aboutthe fields,methods and constructors ofloaded classes. Can you tell me range of byte? 128 to 127 How to invoke externalprocess 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 clientside representation ofthe server, which takes care of communicating with the remote server. What kind of thread is the Garbage collector thread? Daemon thread
  • 4. Explain the purpose of Void class. The Void class is an uninstantiable placeholder class to hold a reference to the Class objectrepresenting 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 itgetgarbage collected. Define mutable object and immutable object. The value of Mutable object is changeable. Ex., StringBuffer The value of an immutable objectcan'tbe 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 betweenstring and stringbuffer object. String is an immutable object. StringBuffer is a mutable object. Define daemon thread. Daemon thread are the threads which can run withoutuser intervention. The JVM can exit when there are daemon thread by killing them abruptly. Define a DatabaseMetaData. It represents comprehensive information aboutthe database as a whole. Jitu 12-5-2011 03:08 AM Java interview Explain preemptive scheduling and time slicing.
  • 5. In preemptive scheduling,the highestpriority 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 oftime and then reenters the pool of ready tasks. Explain the different scopes for Java variables. 3 scopes ofJava variables are defined below: Instance Initialized to defaultvalues at the time of creation of object, and remain accessible as long as the objectaccessible. Local Defined within a method and remain accessbile onlyduring the course of method excecution and fall out of scope When the method fin execution. Static Static variables are the class level variables. Static variables are initialized when the class is loaded in JVM for the firsttime and remain there as long as the class remains loaded. Static variables are not tied to any particular objectinstance. Akash 11-23-2011 02:26 AM Java interview questions and answers Explain the purpose of finalization. It provides an unreachable objectthe opportunity to perform any cleanup processing before the objectis garbage collected. Explain the importance of daemon thread. Daemon thread is a low priority thread. It runs intermittentlyin 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 objector class. Synchronized statements They are similar to synchronized methods. A synchronized statementcan only be executed after a thread has acquired the lock for the object or class referenced in the synchroni
  • 6. statement. Nitin 11-23-2011 01:31 AM Java interview questions and answers What are the way of using thread? Can be implemented byusing runnable interface By inheriting from the Thread class. Difference betweena constructor and a method. Constructor A constructor is a member function ofa class thatis used to create objects ofthat 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 implementan interface Serializable,pass the instance to the ObjectOutputStrea which is connected to a fileoutputstream.This will save the objectto 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 onlybe accessed within the same class,within its subclasses,and within classes ofthe sam e packa 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,butnotfrom outside this package. Private Private methods and fields can onlybe accessed within the same class. Private methods and fields are notvisible within subclasses They are not inherited by subclasses.
  • 7. 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 ofthe class. They are always invoked without reference to a particular instance ofa class. Restrictions ofusing static methods: It can only call other static methods. It mustonly access static data. It cannotreference to the current objectusing 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 ofthe objectbeing inserted. You can use it when you want a collection with no duplicates and you don’tcare about order when you iterate through it. Explain the importance of TreeSet. It is a setimplementation 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 specificallyinformed abouttransforming the object. Example long a = 890.20; int b = (int) a; //Explicit casting
  • 8. Explain implicit casting. Assigning one entity to another without any transformation guidance to the compiler is implicitcasting. This type of casting is not permitted in all kinds of transformations and maynotwork for all scenarios. Example int a = 6000; long b = a; //Implicitcasting Explain reflection API Reflection is the process ofintrospecting the features and state of a class atruntime and dynamicallymanipulate atrun time. This is supported using Reflection APIwith built-in classes like Class,Method, Fields,Constructors etc. Example:Using Java Reflection API we can get the class name, byusing 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 ofa class. Types: -Public : accessible to all classes -Protected : accessible to the classes within the same package and anysubclasses. -Private : accessible onlyto 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 globallyaccessible and hence can create collisions in namespace. What is the Java API? It a large collection of software components thatprovide 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 thatare used to break up string.
  • 9. 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 betweenthe boolean & operator and the && operator. When boolean & operator is evaluated, both operands are evaluated && operator is a shortcut operator. When && operator is evaluated, the first operand is evaluated. When firstoperand returns a value of true then the second operand is evaluated. When firstoperand evaluates to false,the evaluation of the second operand is skipped. Nadeem 11-22-2011 03:40 AM Java interview questions Does Java supportpointers? Java doesn'tsupportthe usage ofpointers.Improper handling ofpointers leads to memoryleaks which is whypointer concept hasn't fo place in Java. Swing and Awt AWT are heavy-weight componenets. Swings are light-weightcomponents and this is reason whyswing works faster than AWT. Pass by reference and passbyvalue Pass By Reference is the passing the address itselfrather than passing the value. PassbyValue is passing a copy of the value to be passed. Rakesh S 11-4-2011 01:26 AM Java interview questions Abstract class It mustbe extended or subclassed. It acts as a template. It may contain static data. A class maybe declared abstracteven if it has no abstractmethodsand this prevents itfrom being instantiated.
  • 10. Annie 11-4-2011 01:21 AM Java interview questions and answers - April 18, 2011 What is an abstract method? An abstractmethod is a method which doesn’thave a body, justdeclared 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 oftime and reenters the pool of ready tasks. What are Wrapper Classes? Wrapper Classes allow to access primitives as objects. What is List interface? Listis an ordered collection ofobjects. Can you explain transient variables in java? They are the variables thatcannot be serialized. What is synchronization? Synchronization ensures onlyone thread to access a shared resource,thus controls the access ofmultiple 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?
  • 11. Map is Interface and Hashmap is class thatimplements 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’tcreate a new instance on change of value. How can you force garbage collection? It is not possible to force GC. We can justrequestitby 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 bydescribing all the attributes of objects and the methods. What is an Object? An objectis the members ofa class.It is the basic unitof 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 objectusing "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 notavailable. In which package is the applet class located?
  • 12. 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 ofobjects. What are access modifiers? Access modifiers determine ifa method or a data variable can be accessed byanother method in another class. Explain the impact of private constructor. Private constructor prevents a class from being explicitlyinstantiated by callers. What is an exception? An exception is an abnormal condition thatarises in a code sequence atrun 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 implementthe 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
  • 13. 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 e xample, 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 thatconverts the program outputto a particular geographic,political,or cultural region Is main a keyword in Java? No, main is nota keyword in Java. What is the most important feature of Java? Platform independencymakes Java a premium language. What is a JVM? JVM is Java Virtual Machine which is a run time environmentfor the compiled java class files. Does Java support multiple inheritances? No, Java doesn'tsupportmultiple inheritances. What is the base class of all classes? java.lang.Object Can a class be declared as protected?
  • 14. A class can'tbe 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 withoutbeing inherited is ofno use. Java interview questions and answers - April 22, 2011 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'thave any declaration inside butstill enforces a mechanism. What is an abstract method? An abstractmethod is a method whose implementation is deferred to a subclass. When can an object reference be cast to an interface reference? An objectreference 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 eightprimitive types are byte, char, short,int, long, float, double,and boolean. Difference between a public and a non-public class. A public class maybe accessed outside ofits package.A non-public class maynotbe accessed outside ofits package. Which Java operator is right associative? The = operator is right associative. What is a transient variable?
  • 15. Transientvariable is a variable that may not be serialized.