Escolar Documentos
Profissional Documentos
Cultura Documentos
Core Java interview questions and answers for freshers and experienced candidates. These interview questions and answers on Core Java will help you strengthen your techn
prepare for the interviews and quickly revise the concepts. Many candidates appear for the interview for one role - many of the them give the right answers to the questions ask
one who provides the best answer with a perfect presentation is the one who wins the interview race. The set of Core java interview questions here ensures that you offer a per
answer to the interview questions posed to you.
Ask a question
Interview Q&A
Videos
Placement papers
HR interview
CV
Cover letter
GD
Aptitude
Current Affairs
Exam
English
Career Q & A
Online test
Jobs
Interview
questions
Java
interview questions
<<Previous Next>>
Java
FAQs
Core Java interview questions - posted on Feb 04, 2014 at 11:40 AM by Nihal Singh
Downloa
d Java/Oracle FAQ
Test Java
skills New
An annotation, in the java programming language is a special form of syntactic metadata that can be added to Java Source
Code.
Test
JDBC skills New
skills New
Java
object, class, method
A statement is parsed and executed each time its call sent to database.
Java
operator
A prepared statement may be parsed once and executed repeatedly with different parameters.
Java
1. Query is parsed
2. Query is compiled.
3. Query is optimized.
4. Query is executed.
- In case of statement, the above four steps are performed every time. And in case of prepared statement the above three
steps are performed once.
variables
Java
overloading
overriding
Java
abstract classes
Java data
types
Java
arrays
Java
exception
Java
events
Java
virtual machine
Employee Information-:
Java input
Employee Id, Name and joining Date.
and output
Code:
Java URL
connections
package com.mytest.jdbc;
import java.sql.CallableStatement;
import java.sql.DriverManager; import java.sql.Connection;
import java.sql.SQLException;
Java
sockets
JNDI
Java
applets
Java AWT
Java
drawing AWT
components
Core java
JDBC
JSP
EJB
J2EE
JNI
Servlets
Struts
Java
threading
J2ME
JMS
Java web
services
RMI
Internatio
nalization
JavaScrip
t
EJB
Architecture
Spring
Q: 4 Using Callable Statement how can you pass OUT Parameters, explain with
example?
Java
Transaction API
JTA
JBOSS
Take the example of Employee, where you want the details of Employee by Id.
Code: Use the same code structure get DB Connection etc.
//getDBUSERByUserId is a stored procedure
String getEmpInfoByEmpIdSql = "{call getEmpInfoByEmpId(?,?,?,?)}";
Java
transaction services,
JTS
Java GUI
Framework interview
callableStatement = dbConnection.prepareCall(getEmpInfoByEmpIdSql);
callableStatement.setInt(1, 377602);
SWT/JFa
ce interview
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.registerOutParameter(3, java.sql.Types.DATE);
MVC and
Jface
JavaServ
er Faces
Hibernate
interview
JavaMail
interview
The life cycle of threads in Java is very similar to the life cycle of processes running in an operating system. During its life cycle
the thread moves from one state to another depending on the operation performed by it or performed on it. A Java thread can
be in one of the following states:
NEW: A thread that is just instantiated is in new state. When a start () method is invoked, the thread moves to the
ready state from which it is automatically moved to runnable state by the thread scheduler.
BLOCKED A thread that is blocked waiting for a monitor lock is in this state. This can also occur when a thread
performs an I/O operation and moves to next (runnable) state.
Tomcat
MIDP
interview
Weblogic
interview
Ant
interview
WAITING A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
Webspher
e interview
TIMED_WAITING (sleeping) A thread that is waiting for another thread to perform an action up to a specified
waiting time is in this state.
Ruby
interview
interview
Aspect
Oriented
Programming
Java
design patterns
Java
localization
}
Subclass Thread. The Thread class itself implements Runnable interface, though it runs method does nothing. An
application can subclass Thread, and provides its own implementation of run, as in the HelloThread example:
public class HelloThread extends Thread {
public void run() {
System.out.println("Hello from a thread!");
}
public static void main(String args[])
{
(new HelloThread()).start();
}
}
Q: 7 Which way a developer should use for creating thread, i.e. Sub classing
Thread or implementing Runnable.
There are two ways of creating Thread in java (i.e. sub classing or implementing Runnable). It is very important to understand
the implication of using these two approaches.
There are two different points about using these two approaches.
By extending the thread class, the derived class itself is a thread object and it gains full control over the thread life
cycle. Implementing the Runnable interface does not give developers any control over the thread itself, as it simply
defines the unit of work that will be executed in a thread.
Another important point is that when extending the Thread class, the derived class cannot extend any other base
classes because Java only allows single inheritance. By implementing the Runnable interface, the class can still
extend other base classes if necessary.
To summarize, if developer needs a full control over the Thread life cycle, sub classing Thread class is a good choice, and if
programs need more flexibility by extending other class developer, should go with implementing Runnable interface.
When a static synchronized method is called, the program obtains the class lock before calling the method. This mechanism is
identical to the case in which method is non-static, it is just a different lock, and this lock is solely for static method.
Apart from the functional relationship between the two locks, they are not operationally related at all.
Only one thread can execute a synchronized static method per class.
Only one thread per instance of the class can execute a non-static synchronized method.
Any number of threads can execute a non-synchronized method static or non-static method.
Static code is loaded before the class is instantiated and stays in memory until the JVM exits as opposed to
instance variable which are loaded and unloaded which is called Dynamic code.
Each class has one copy of each of its static members in memory.
Each instance of the class has access to that single static memory location.
If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the
two objects must produce the same integer result.
It is not required that if two objects are unequal according to the equals(java.lang.Object)method, then calling the
hashCode method on each of the two objects must produce distinct integer results. However, the programmer
should be aware that producing distinct integer results for unequal objects may improve the performance of
hashtables.
obtain element_hash_code of the element by processing the element's data and generating an integer value.
use a simple mod operation to map into the array's range: index = hash(element) = abs(element_hash_code %
array_capacity)
The hashcode collision occurs when the index calculated by hash function results same for two or more elements.
Q. 18 How can you make sure that your singleton class will always return single
instance in multi-threaded environment?
There are three ways to make your class singleton.
Simple way, create private object and do null check, if object is null create the instance otherwise return the same
instance, refer example 1 in previous question. Singleton class created this way will not guarantee that it will work
By creating global static variable of the same class and instantiate it at the time of declaration. The Singleton class
created this will work perfectly in multi-threaded enviornment.
Example:
public class Singleton {
// global instance created and instantiated at the time of declaration.
private static Singleton uniqueObj = new Singleton();
// Private Constructor so that no instance can be created.
private Singleton(){ }
public static Singleton getInstance(){
return uniqueObj;
}
}
Creating class by double checking. This is the best way of creating Singleton class which will work perfectly in
multi-threaded environment also.
public class Singleton {
private static Singleton uniqueObj;
// Private Constructor so that no instance can be created.
private Singleton(){
}
public static Singleton getInstance(){
if(uniqueObj==null){
syncronized(Singleton.class){
if(uniqueObj==null){
uniqueObj = new Singleton();
}
}
}
return uniqueObj;
}
}
Q: 19 Why Singleton pattern is better than creating Singleton class with static
instance?
With Singleton pattern you can create the object when you required, but static instance get created at the time of class loading
i.e. we can lazily instantiate object with singleton pattern.
With Singleton pattern we can use inheritance, for example when we require default behavior of the Singleton class then we
can use that, with static you cannot.
}
}
Output:This is covariant return type
From the above example you can see that the return type of SuperClass get method is SuperClass and the same method get
is overriden in SubClass and whose return type is of Subclass.
So as you can see that the get method overridden has different return type. This feature is known as Covariant return type.
Core Java interview questions - posted on June 27, 2013 at 15:40 PM by Kshipra Singh
7. If you do not want your class to be inherited by any other class. What would
you do?
- Declare your class as final . A class declared as final can't be inherited by any other class.
- However, if it is an abstract class, you can't define your class as final.
13. If a class is declared without any access modifiers, where can the class be
accessed?
- A class declared without any access modifiers is said to have package access.
- Such a class can only be accessed by other classes and interfaces defined within the same package.
19. When should you use ArrayList and when should you use LinkedList?
- If you need to support random access, without inserting or removing elements from anywhere other than the ends, then
ArrayList is a better choice.
- If you add and remove elements from the middle of the list frequently while accessing them sequentially, then LinkedList is
better.
Latest answer: The File class is used to perform the operations on files and directories of the file system of an operating
system. This operating system is the platform for the java application that uses the File class objects............
Read answer
12.What is a StringBuffer class and how does it differs from String class?
Latest answer: StringBuffer is thread safe, where as StringBuilder is not. In other words, StringBuffer class is synchronized
and StringBuilder class is not synchronized..........
Read answer
14.What is an abstract class? | Explain the difference between abstract class and interfaces.
Latest answer: An abstract class defines an abstract concept which cant be instantiated. We cant create object of abstract
class, it can only be inherited. Abstract class normally represents concept with general actions associated with it.................
Read answer
15.What is an interface?
Latest answer: An interface is a set of method definition without implementation. It is a protocol of behavior for a
class.................
Read answer
Core Java Interview questions with answers posted on August 11, 2008, 19:00 pm by Amit Satpute
18.What are Native methods in Java?
Latest answer: Java applications can call code written in C, C++, or assembler. This is sometimes done for performance and
sometimes to access the underlying host operating system or GUI API using the JNI.............
Read answer
Read answer
<<Previous Next>>
More Java related questions
Portal and Portlet
What is a Portlet? Explain its capabilities.
Explain Portal architecture.
What is PortletSession interface?
What is PortletContext interface?
Why portals?..............
Java Authentication and Authorization Service, JAAS
What is Java Authentication and Authorization Service, JAAS?
Features of JAAS.
JAAS infrastructure has two services: authentication and authorization. Explain the two services.
JAAS authentication from your application typically involves the steps. Explain the steps...........
suggestion
When result of quiz is shown , please display the correct answer also . At present correct answer is shown only in case of incorrect answers
.Sometimes , we guess the answer and it's right , so it would be helpful if correct answers are displayed in both cases i.e correct and incorrect
aarsha 07-5-2012 02:39 AM
Core Java Interview questions and answers
What is a Map? What are the implementations of Map?
Map is an interface that provides three collection views, which allows the maps content to be viewed in different forms like set of keys, collection
of values, or set of key-value mappings. It is an object interface that allows the associations between keys and values.
The implementations of Map are as follows:
- HashMap
- HashTable
- TreeMap
- EnumMap
What is javas garbage collected heap?
JVM is also known as Java Virtual Machine. It is the heart of JAVA programming language. JVMs heap stores all the objects that have been
created and ready for execution. When an object is created by new() operator then the memory is being allocated on heap at run time. JAVA is
having the concept of Garbage collection to automatically free the objects when they are no longer referenced by a program. This allows the
programmer not to worry about the freeing of allocated memory.
Home
Copyright 2008 - 2014 CareerRide.com. All rights reserved. Terms of use | Follow us on Facebook!
Bookmark to:
Placement practice test: Java | SAP | .NET | Oracle | Sql Server | QA | Aptitude | Networking | All Skills