Core Java Interview Questions

SHARE:

Core Java: Basics of Java Interview Questions


Image result for Core Java Interview Questions


1) What is difference between JDK,JRE and JVM?
JVM
JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the runtime environment in which java bytecode can be executed. It is a specification.
JVMs are available for many hardware and software platforms (so JVM is platform dependent).
JRE
JRE stands for Java Runtime Environment. It is the implementation of JVM.
JDK
JDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools.


2) How many types of memory areas are allocated by JVM?
Many types:
  1. Class(Method) Area
  2. Heap
  3. Stack
  4. Program Counter Register
  5. Native Method Stack


3) What is JIT compiler?
Just-In-Time(JIT) compiler:It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.


4) What is platform?
A platform is basically the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides software-based platform.


5) What is the main difference between Java platform and other platforms?
The Java platform differs from most other platforms in the sense that it's a software-based platform that runs on top of other hardware-based platforms.It has two components:
  1. Runtime Environment
  2. API(Application Programming Interface)


6) What gives Java its 'write once and run anywhere' nature?
The bytecode. Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platform specific and hence can be fed to any platform.


7) What is classloader?
The classloader is a subsystem of JVM that is used to load classes and interfaces.There are many types of classloaders e.g. Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc.


8) Is Empty .java file name a valid source file name?
Yes, save your java file by .java only, compile it by javac .java and run by java yourclassname Let's take a simple example:
1.    //save by .java only  
2.    class A{  
3.    public static void main(String args[]){  
4.    System.out.println("Hello java");  
5.    }  
6.    }  
7.    //compile by javac .java  
8.    //run by     java A  
compile it by javac .java
run it by java A


9) Is delete,next,main,exit or null keyword in java?
No.


10) If I don't provide any arguments on the command line, then the String array of Main method will be empty or null?
It is empty. But not null.


11) What if I write static public void instead of public static void?
Program compiles and runs properly.


12) What is the default value of the local variables?
The local variables are not initialized to any default value, neither primitives nor object references.


Core Java - OOPs Concepts: Initial OOPs Interview Questions
There is given more than 50 OOPs (Object-Oriented Programming and System) interview questions. But they have been categorized in many sections such as constructor interview questions, static interview questions, Inheritance Interview questions, Abstraction interview question, Polymorphism interview questions etc. for better understanding.


13) What is difference between object oriented programming language and object based programming language?
Object based programming languages follow all the features of OOPs except Inheritance. Examples of object based programming languages are JavaScript, VBScript etc.
14) What will be the initial value of an object reference which is defined as an instance variable?
The object references are all initialized to null in Java.


Core Java - OOPs Concepts: Constructor Interview Questions


15) What is constructor?
  • Constructor is just like a method that is used to initialize the state of an object. It is invoked at the time of object creation.


16) What is the purpose of default constructor?


17) Does constructor return any value?
Ans:yes, that is current instance (You cannot use return type yet it returns a value).                       


18)Is constructor inherited?
No, constructor is not inherited.


19) Can you make a constructor final?
No, constructor can't be final.


Core Java - OOPs Concepts: static keyword Interview Questions


20) What is static variable?
  • static variable is used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc.
  • static variable gets memory only once in class area at the time of class loading.


21) What is static method?
  • A static method belongs to the class rather than object of a class.
  • A static method can be invoked without the need for creating an instance of a class.
  • static method can access static data member and can change the value of it.


22) Why main method is static?
because object is not required to call static method if It were non-static method,jvm creats object first then call main() method that will lead to the problem of extra memory allocation.                       


23) What is static block?
  • Is used to initialize the static data member.
  • It is excuted before main method at the time of classloading.


24) Can we execute a program without main() method?
Ans) Yes, one of the way is static block.                       


25) What if the static modifier is removed from the signature of the main method?
Program compiles. But at runtime throws an error "NoSuchMethodError".


26) What is difference between static (class) method and instance method?
static or class method
instance method
1)A method i.e. declared as static is known as static method.
A method i.e. not declared as static is known as instance method.
2)Object is not required to call static method.
Object is required to call instance methods.
3)Non-static (instance) members cannot be accessed in static context (static method, static block and static nested class) directly.
static and non-static variables both can be accessed in instance methods.
4)For example: public static int cube(int n){ return n*n*n;}
For example: public void msg(){...}.


Core Java - OOPs Concepts: Inheritance Interview Questions


27) What is this in java?
It is a keyword that that refers to the current object.                       


28)What is Inheritance?
Inheritance is a mechanism in which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship. It is used for Code Resusability and Method Overriding.


29) Which class is the superclass for every class.
Object class.


30) Why multiple inheritance is not supported in java?


31) What is composition?
Holding the reference of the other class within some other class is known as composition.


32) What is difference between aggregation and composition?
Aggregation represents weak relationship whereas composition represents strong relationship. For example: bike has an indicator (aggregation) but bike has an engine (compostion).
33) Why Java does not support pointers?
Pointer is a variable that refers to the memory address. They are not used in java because they are unsafe(unsecured) and complex to understand.


34) What is super in java?
It is a keyword that refers to the immediate parent class object.                       


35) Can you use this() and super() both in a constructor?
No. Because super() or this() must be the first statement.


36)What is object cloning?
The object cloning is used to create the exact copy of an object.                        


Core Java - OOPs Concepts: Method Overloading Interview Questions


37) What is method overloading?
If a class have multiple methods by same name but different parameters, it is known as Method Overloading. It increases the readability of the program.                       


38) Why method overloading is not possible by changing the return type in java?


39) Can we overload main() method?
Yes, You can have many main() methods in a class by overloading the main method.


Core Java - OOPs Concepts: Method Overriding Interview Questions


40) What is method overriding:
If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. It is used for runtime polymorphism and to provide the specific implementation of the method.                       


41) Can we override static method?
No, you can't override the static method because they are the part of class not object.


42) Why we cannot override static method?
It is because the static method is the part of class and it is bound with class whereas instance method is bound with object and static gets memory in class area and instance gets memory in heap.


43) Can we override the overloaded method?
Yes.


44) Difference between method Overloading and Overriding.
Method Overloading
Method Overriding
1) Method overloading increases the readability of the program.
Method overriding provides the specific implementation of the method that is already provided by its super class.
2) method overlaoding is occurs within the class.
Method overriding occurs in two classes that have IS-A relationship.
3) In this case, parameter must be different.
In this case, parameter must be same.
45) Can you have virtual functions in Java?
Yes, all functions in Java are virtual by default.


46) What is covariant return type?
Now, since java5, it is possible to override any method by changing the return type if the return type of the subclass overriding method is subclass type. It is known as covariant return type.                        


Core Java - OOPs Concepts: final keyword Interview Questions


47) What is final variable?
If you make any variable as final, you cannot change the value of final variable(It will be constant).                        


48) What is final method?
Final methods can't be overriden.                       


49) What is final class?
Final class can't be inherited.                        


50) What is blank final variable?
A final variable, not initalized at the time of declaration, is known as blank final variable.                       


51) Can we intialize blank final variable?
Yes, only in constructor if it is non-static. If it is static blank final variable, it can be initialized only in the static block.                       


52) Can you declare the main method as final?
Yes, such as, public static final void main(String[] args){}.

Core Java - OOPs : Polymorphism Interview Questions


53) What is Runtime Polymorphism?
Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time.
In this process, an overridden method is called through the reference variable of a super class. The determination of the method to be called is based on the object being referred to by the reference variable.


54) Can you achieve Runtime Polymorphism by data members?
No.


55) What is the difference between static binding and dynamic binding?
In case of static binding type of object is determined at compile time whereas in dynamic binding type of object is determined at runtime.


Core Java - OOPs Concepts : Abstraction Interview Questions


56) What is abstraction?
Abstraction is a process of hiding the implementation details and showing only functionality to the user.
Abstraction lets you focus on what the object does instead of how it does it.


57) What is the difference between abstraction and encapsulation?
Abstraction hides the implementation details whereas encapsulation wraps code and data into a single unit.


58) What is abstract class?
A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated.


59) Can there be any abstract method without abstract class?
No, if there is any abstract method in a class, that class must be abstract.


60) Can you use abstract and final both with a method?
No, because abstract method needs to be overridden whereas you can't override final method.


61) Is it possible to instantiate the abstract class?
No, abstract class can never be instantiated.


62) What is interface?
Interface is a blueprint of a class that have static constants and abstract methods.It can be used to achieve fully abstraction and multiple inheritance.


63) Can you declare an interface method static?
No, because methods of an interface is abstract by default, and static and abstract keywords can't be used together.


64) Can an Interface be final?
No, because its implementation is provided by another class.


65) What is marker interface?
An interface that have no data member and method is known as a marker interface.For example Serializable, Cloneable etc.


66) What is difference between abstract class and interface?
Abstract class
Interface
1)An abstract class can have method body (non-abstract methods).
Interface have only abstract methods.
2)An abstract class can have instance variables.
An interface cannot have instance variables.
3)An abstract class can have constructor.
Interface cannot have constructor.
4)An abstract class can have static methods.
Interface cannot have static methods.
5)You can extends one abstract class.
You can implement multiple interfaces.


67) Can we define private and protected modifiers for variables in interfaces?
No, they are implicitly public.


68) When can an object reference be cast to an interface reference?
An object reference can be cast to an interface reference when the object implements the referenced interface.


Core Java - OOPs Concepts : Package Interview Questions


69) What is package?
A package is a group of similar type of classes interfaces and sub-packages. It provides access protection and removes naming collision.


70) Do I need to import java.lang package any time? Why ?
No. It is by default loaded internally by the JVM.


71) Can I import same package/class twice? Will the JVM load the package twice at runtime?
One can import the same package or same class multiple times. Neither compiler nor JVM complains about it.But the JVM will internally load the class only once no matter how many times you import the same class.


72) What is static import ?
By static import, we can access the static members of a class directly, there is no to qualify it with the class name.

Java : Exception Handling Interview Questions
There is given a list of exception handling interview questions with answers. If you know any exception handling interview question, kindly post it in the comment section.


73) What is Exception Handling?
Exception Handling is a mechanism to handle runtime errors.It is mainly used to handle checked exceptions.


74) What is difference between Checked Exception and Unchecked Exception?
1)Checked Exception
The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e.g.IOException,SQLException etc. Checked exceptions are checked at compile-time.
2)Unchecked Exception
The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException,NullPointerException etc. Unchecked exceptions are not checked at compile-time.


75) What is the base class for Error and Exception?
Throwable.


76) Is it necessary that each try block must be followed by a catch block?
It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.


77) What is finally block?


78) Can finally block be used without catch?


79) Is there any case when finally will not be executed?
finally block will not be executed if program exits(either by calling System.exit() or by causing a fatal error that causes the process to abort).                       


80) What is difference between throw and throws?
throw keyword
throws keyword
1)throw is used to explicitly throw an exception.
throws is used to declare an exception.
2)checked exceptions can not be propagated with throw only.
checked exception can be propagated with throws.
3)throw is followed by an instance.
throws is followed by class.
4)throw is used within the method.
throws is used with the method signature.
5)You cannot throw multiple exception
You can declare multiple exception e.g. public void method()throws IOException,SQLException.


81) Can an exception be rethrown?
Yes.


82) Can subclass overriding method declare an exception if parent class method doesn't throw an exception ?
Yes but only unchecked exception not checked.


83) What is exception propagation ?
Forwarding the exception object to the invoking method is known as exception propagation.




Java: String Handling Interview Questions
There is given a list of string handling interview questions with short and pointed answers. If you know any string handling interview question, kindly post it in the comment section.


84) What is the meaning of immutable in terms of String?
The simple meaning of immutable is unmodifiable or unchangeable. Once string object has been created, its value can't be changed.


85) Why string objects are immutable in java?
Because java uses the concept of string literal. Suppose there are 5 reference variables,all referes to one object "sachin".If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java.


86) How many ways we can create the string object?
There are two ways to create the string object, by string literal and by new keyword.


87) How many objects will be created in the following code?
1.    String s1="Welcome";  
2.    String s2="Welcome";  
3.    String s3="Welcome";  
Only one object.


88) Why java uses the concept of string literal?
To make Java more memory efficient (because no new objects are created if it exists already in string constant pool).


89)How many objects will be created in the following code?
1.    String s = new String("Welcome");  
Two objects, one in string constant pool and other in non-pool(heap).


90) What is the basic difference between string and stringbuffer object?
String is an immutable object. StringBuffer is a mutable object.


91) What is the difference between StringBuffer and StringBuilder ?
StringBuffer is synchronized whereas StringBuilder is not synchronized.


92) How can we create immutable class in java ?
We can create immutable class as the String class by defining final class and


93) What is the purpose of toString() method in java ?
The toString() method returns the string representation of any object. If you print any object, java compiler internally invokes the toString() method on the object. So overriding the toString() method, returns the desired output, it can be the state of an object etc. depends on your implementation.


Core Java : Nested classes and Interfaces Interview Questions


94)What is nested class?
A class which is declared inside another class is known as nested class. There are 4 types of nested class member inner class, local inner class, annonymous inner class and static nested class.


95) Is there any difference between nested classes and inner classes?
Yes, inner classes are non-static nested classes i.e. inner classes are the part of nested classes.


96) Can we access the non-final local variable, inside the local inner class?
No, local variable must be constant if you want to access it in local inner class.


97) What is nested interface ?
Any interface i.e. declared inside the interface or class, is known as nested interface. It is static by default.


98) Can a class have an interface?
Yes, it is known as nested interface.


99) Can an Interface have a class?
Yes, they are static implicitely.

Garbage Collection Interview Questions


117) What is Garbage Collection?
Garbage collection is a process of reclaiming the runtime unused objects.It is performed for memory management.
118) What is gc()?
gc() is a daemon thread.gc() method is defined in System class that is used to send request to JVM to perform garbage collection.
119) What is the purpose of finalize() method?
finalize() method is invoked just before the object is garbage collected.It is used to perform cleanup processing.
120) Can an unrefrenced objects be refrenced again?
Yes.
121)What kind of thread is the Garbage collector thread?
Daemon thread.
122)What is difference between final, finally and finalize?
final: final is a keyword, final can be variable, method or class.You, can't change the value of final variable, can't override final method, can't inherit final class.
finally: finally block is used in exception handling. finally block is always executed.
finalize():finalize() method is used in garbage collection.finalize() method is invoked just before the object is garbage collected.The finalize() method can be used to perform any cleanup processing.


123)What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java runtime system.
124)How will you invoke any external process in Java?
By Runtime.getRuntime().exec(?) method.


I/O Interview Questions


125)What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
126)What an I/O filter?
An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.


Serialization Interview Questions


127) What is serialization?
Serialization is a process of writing the state of an object into a byte stream.It is mainly used to travel object's state on the network.
128) What is Deserialization?
Deserialization is the process of reconstructing the object from the serialized state.It is the reverse operation of serialization.
129) What is transient keyword?
If you define any data member as transient,it will not be serialized.                       
130)What is Externalizable?
Externalizable interface is used to write the state of an object into a byte stream in compressed format.It is not a marker interface.
131)What is the difference between Serializalble and Externalizable interface?
Serializable is a marker interface but Externalizable is not a marker interface.When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process.


Networking Interview Questions


132)How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?
By InetAddress.getByName("192.18.97.39").getHostName() where 192.18.97.39 is the IP address.


Reflection Interview Questions


133) What is reflection?
Reflection is the process of examining or modifying the runtime behaviour of a class at runtime.It is used in:
  • IDE (Integreted Development Environment) e.g. Eclipse, MyEclipse, NetBeans.
  • Debugger
  • Test Tools etc.
134) Can you access the private method from outside the class?
Yes, by changing the runtime behaviour of a class if the class is not secured.

Miscellaneous Interview Questions


148)What are wrapper classes?
Wrapper classes are classes that allow primitive types to be accessed as objects.
149)What is a native method?
A native method is a method that is implemented in a language other than Java.
150)What is the purpose of the System class?
The purpose of the System class is to provide access to system resources.
151)What comes to mind when someone mentions a shallow copy in Java?
Object cloning.
152)What is singleton class?
Singleton class means that any given time only one instance of the class is present, in one JVM.


AWT and SWING Interview Questions


153)Which containers use a border layout as their default layout?
The Window, Frame and Dialog classes use a border layout as their default layout.
154)Which containers use a FlowLayout as their default layout?
The Panel and Applet classes use the FlowLayout as their default layout.
155)What are peerless components?
The peerless components are called light weight components.
156)is the difference between a Scrollbar and a ScrollPane?
A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.
157)What is a lightweight component?
Lightweight components are the one which doesn?t go with the native call to obtain the graphical units. They share their parent component graphical units to render them. For example, Swing components.
158)What is a heavyweight component?
For every paint call, there will be a native call to get the graphical units.For Example, AWT.
159)What is an applet?
An applet is a small java program that runs inside the browser and generates dynamic contents.
160)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.


Internationalization Interview Questions


161)What is Locale?
A Locale object represents a specific geographical, political, or cultural region.
162)How will you load a specific locale?
By ResourceBundle.getBundle(?) method.


Java Bean Interview Questions


163)What is a JavaBean?
are reusable software components written in the Java programming language, designed to be manipulated visually by a software development environment, like JBuilder or VisualAge for Java.


RMI Interview Questions


164)Can RMI and Corba based applications interact?
Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.

Java Multithreading Interview Questions
Multithreading and Synchronization is considered as the typical chapter in java programming. In game development company, mulithreading related interview questions are asked mostly. A list of frequently asked java multithreading interview questions are given below.


1) What is multithreading?
Multithreading is a process of executing multiple threads simultaneously. Its main advantage is:
  • Threads share the same address space.
  • Thread is lightweight.
  • Cost of communication between process is low.


2) What is thread?
A thread is a lightweight subprocess.It is a separate path of execution.It is called separate path of execution because each thread runs in a separate stack frame.


3)What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.


4) What does join() method?
The join() method waits for a thread to die. In other words, it causes the currently running threads to stop executing until the thread it joins with completes its task.


5) What is difference between wait() and sleep() method?
wait()
sleep()
1) The wait() method is defined in Object class.
The sleep() method is defined in Thread class.
2) wait() method releases the lock.
The sleep() method doesn't releases the lock.


6) Is it possible to start a thread twice?
No, there is no possibility to start a thread twice. If we does, it throws an exception.


7) Can we call the run() method instead of start()?
yes, but it will not work as a thread rather it will work as a normal object so there will not be context-switching between the threads.


8) What about the daemon threads?
The daemon threads are basically the low priority threads that provides the background support to the user threads. It provides services to the user threads.


9)Can we make the user thread as daemon thread if thread is started?
No, if you do so, it will throw IllegalThreadStateException


10)What is shutdown hook?
The shutdown hook is basically a thread i.e. invoked implicitely before JVM shuts down. So we can use it perform clean up resource.


11)When should we interrupt a thread?
We should interrupt a thread if we want to break out the sleep or wait state of a thread.


12) What is synchronization?
Synchronization is the capabilility of control the access of multiple threads to any shared resource.It is used:


  1. To prevent thread interference.
  2. To prevent consistency problem.


13) What is the purpose of Synchronized block?
  • Synchronized block is used to lock an object for any shared resource.
  • Scope of synchronized block is smaller than the method.


14)Can Java object be locked down for exclusive use by a given thread?
Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it.


15) What is static synchronization?
If you make any static method as synchronized, the lock will be on the class not on object.                        


16)What is the difference between notify() and notifyAll()?
The notify() is used to unblock one waiting thread whereas notifyAll() method is used to unblock all the threads in waiting state.


17)What is deadlock?
Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread.

Java Collections Interview Questions
In java, collection interview questions are mostly asked by the interviewers. Here is the list of mostly asked collections interview questions with answers.


1) What is the difference between ArrayList and Vector?
No.
ArrayList
Vector
1)
ArrayList is not synchronized.
Vector is synchronized.
2)
ArrayList is not a legacy class.
Vector is a legacy class.
3)
ArrayList increases its size by 50% of the array size.
Vector increases its size by doubling the array size.


2) What is the difference between ArrayList and LinkedList?
No.
ArrayList
LinkedList
1)
ArrayList uses a dynamic array.
LinkedList uses doubly linked list.
2)
ArrayList is not efficient for manipulation because a lot of shifting is required.
LinkedList is efficient for manipulation.
3)
ArrayList is better to store and fetch data.
LinkedList is better to manipulate data.


3) What is the difference between Iterator and ListIterator?
Iterator traverses the elements in forward direction only whereas ListIterator traverses the elements in forward and backward direction.
No.
Iterator
ListIterator
1)
Iterator traverses the elements in forward direction only.
ListIterator traverses the elements in backward and forward directions both.
2)
Iterator can be used in List, Set and Queue.
ListIterator can be used in List only.


4) What is the difference between Iterator and Enumeration?
No.
Iterator
Enumeration
1)
Iterator can traverse legacy and non-legacy elements.
Enumeration can traverse only legacy elements.
2)
Iterator is fail-fast.
Enumeration is not fail-fast.
3)
Iterator is slower than Enumeration.
Enumeration is faster than Iterator.


5) What is the difference between List and Set?
List can contain duplicate elements whereas Set contains only unique elements.


6) What is the difference between HashSet and TreeSet?
HashSet maintains no order whereas TreeSet maintains ascending order.


7) What is the difference between Set and Map?
Set contains values only whereas Map contains key and values both.


8) What is the difference between HashSet and HashMap?
HashSet contains only values whereas HashMap contains entry(key,value). HashSet can be iterated but HashMap need to convert into Set to be iterated.


9) What is the difference between HashMap and TreeMap?
HashMap maintains no order but TreeMap maintains ascending order.


10) What is the difference between HashMap and Hashtable?
No.
HashMap
Hashtable
1)
HashMap is not synchronized.
Hashtable is synchronized.
2)
HashMap can contain one null key and multiple null values.
Hashtable cannot contain any null key or null value.


11) What is the difference between Collection and Collections?
Collection is an interface whereas Collections is a class. Collection interface provides normal functionality of data structure to List, Set and Queue. But, Collections class is to sort and synchronize collection elements.


12) What is the difference between Comparable and Comparator?
No.
Comparable
Comparator
1)
Comparable provides only one sort of sequence.
Comparator provides multiple sort of sequences.
2)
It provides one method named compareTo().
It provides one method named compare().
3)
It is found in java.lang package.
it is found in java.util package.
4)
If we implement Comparable interface, actual class is modified.
Actual class is not modified.


13) What is the advantage of Properties file?
If you change the value in properties file, you don't need to recompile the java class. So, it makes the application easy to manage.


14) What does the hashCode() method?
The hashCode() method returns a hash code value (an integer number).
The hashCode() method returns the same integer number, if two keys (by calling equals() method) are same.
But, it is possible that two hash code numbers can have different or same keys.


15) Why we override equals() method?
The equals method is used to check whether two objects are same or not. It needs to be overridden if we want to check the objects based on property.
For example, Employee is a class that has 3 data members: id, name and salary. But, we want to check the equality of employee object on the basis of salary. Then, we need to override the equals() method.


16) How to synchronize List, Set and Map elements?
Yes, Collections class provides methods to make List, Set or Map elements as synchronized:
public static List synchronizedList(List l){}
public static Set synchronizedSet(Set s){}
public static SortedSet synchronizedSortedSet(SortedSet s){}
public static Map synchronizedMap(Map m){}
public static SortedMap synchronizedSortedMap(SortedMap m){}


17) What is the advantage of generic collection?
If we use generic class, we don't need typecasting. It is typesafe and checked at compile time.


18) What is hash-collision in Hashtable and how it is handled in Java?
Two different keys with the same hash value is known as hash-collision. Two different entries will be kept in a single hash bucket to avoid the collision.


19) What is the Dictionary class?
The Dictionary class provides the capability to store key-value pairs.


20) What is the default size of load factor in hashing based collection?
The default size of load factor is 0.75. The default capacity is computed as initial capacity * load factor. For example, 16 * 0.75 = 12. So, 12 is the default capacity of Map.

JDBC Interview Questions
A list of frequently asked jdbc interview questions with answers are given below.


1) What is JDBC?
JDBC is a Java API that is used to connect and execute query to the database. JDBC API uses jdbc drivers to connects to the database.


2) What is JDBC Driver?
JDBC Driver is a software component that enables java application to interact with the database.There are 4 types of JDBC drivers:
  1. JDBC-ODBC bridge driver
  2. Native-API driver (partially java driver)
  3. Network Protocol driver (fully java driver)
  4. Thin driver (fully java driver)


3) What are the steps to connect to the database in java?
  • Registering the driver class
  • Creating connection
  • Creating statement
  • Executing queries
  • Closing connection


4) What are the JDBC API components?
The java.sql package contains interfaces and classes for JDBC API.
Interfaces:
  • Connection
  • Statement
  • PreparedStatement
  • ResultSet
  • ResultSetMetaData
  • DatabaseMetaData
  • CallableStatement etc.
Classes:
  • DriverManager
  • Blob
  • Clob
  • Types
  • SQLException etc.


5) What are the JDBC statements?
There are 3 JDBC statements.
  1. Statement
  2. PreparedStatement
  3. CallableStatement


6) What is the difference between Statement and PreparedStatement interface?
In case of Statement, query is complied each time whereas in case of PreparedStatement, query is complied only once. So performance of PreparedStatement is better than Statement.


7) How can we execute stored procedures and functions?
By using Callable statement interface, we can execute procedures and functions.


8) What is the role of JDBC DriverManager class?
The DriverManager class manages the registered drivers. It can be used to register and unregister drivers. It provides factory method that returns the instance of Connection.


9) What does the JDBC Connection interface?
The Connection interface maintains a session with the database. It can be used for transaction management. It provides factory methods that returns the instance of Statement, PreparedStatement, CallableStatement and DatabaseMetaData.


10) What does the JDBC ResultSet interface?
The ResultSet object represents a row of a table. It can be used to change the cursor pointer and get the information from the database.


11) What does the JDBC ResultSetMetaData interface?
The ResultSetMetaData interface returns the information of table such as total number of columns, column name, column type etc.


12) What does the JDBC DatabaseMetaData interface?
The DatabaseMetaData interface returns the information of the database such as username, driver name, driver version, number of tables, number of views etc.


13) Which interface is responsible for transaction management in JDBC?
The Connection interface provides methods for transaction management such as commit(), rollback() etc.


14) What is batch processing and how to perform batch processing in JDBC?
By using batch processing technique in JDBC, we can execute multiple queries. It makes the performance fast.


15) How can we store and retrieve images from the database?
By using PreparedStatement interface, we can store and retrieve images.

COMMENTS

BLOGGER: 3
Loading...
Name

11th,2,12th,20,12th Chemistry,5,12th Computer Science,7,12th Physics,1,5th Sem CSE,1,AAI ATC,2,Android,18,Banking,1,Blogger,41,Books,5,BTech,17,CBSE,22,CSE,4,ECE,3,Electronics,1,English,2,ESE,1,Ethical Hacking,61,Exams,5,Games,9,GATE,1,GATE ECE,1,Government Jobs,1,GS,1,How To,27,IBPS PO,1,Information,52,Internet,24,IPU,8,JEE,8,JEE Mains,8,Jobs,1,Linux,65,News,18,Notes,23,Physics,3,Placement,10,PO,1,Poetry,3,RRB,1,SEO,11,Softwares,38,SSC,2,SSC CGL,1,SSC GS,2,Tips and Tricks,46,UPSC,1,Windows,46,
ltr
item
SolutionRider- One Stop Solution for Notes, Exams Prep, Jobs & Technical Blogs.: Core Java Interview Questions
Core Java Interview Questions
Best Java Interview Questiona nd Answers ..... java interview questions pdf java interview questions for experienced java interview questions for 4 years experience java interview questions indiabix java interview questions on collections java interview questions for 2 years experience java interview questions geeksforgeeks java interview questions for testers java interview questions for selenium java interview questions journaldev java interview questions java interview questions for freshers java interview questions and answers java interview questions and answers for freshers java interview questions and answers for experienced java interview questions and answers for 5 years experience java interview questions and answers pdf free download java interview questions and answers for 2 years experience java interview questions and answers for freshers technical pdf java interview questions and answers for freshers pdf 2017 java interview questions advanced java interview questions app java interview questions book java interview questions book pdf java interview questions basic java interview questions by durga sir java interview questions blogspot java interview questions best site java interview questions by shivprasad koirala pdf java interview questions by durga java interview questions blog java interview questions beginners java interview questions collections java interview questions coding java interview questions core java interview questions career guru java interview questions careercup java interview questions code geeks java interview questions collection framework java interview questions constructor java interview questions citigroup java interview questions career ride c java interview questions answers c java interview questions pdf c c++ java interview questions with answers pdf c cpp java interview questions c java dbms interview questions c c++ core java interview questions c c++ java technical interview questions c c++ java .net interview questions java interview questions durgasoft java interview questions download java interview questions download pdf java interview questions dzone java interview questions doc java interview questions difficult java interview questions developersbook java interview questions design patterns java interview questions deloitte java interview questions data structures samsung r&d java interview questions hp r&d java interview questions hp r&d bangalore java interview questions java interview questions experienced java interview questions experienced professionals java interview questions edureka java interview questions ebook java interview questions exception handling java interview questions exposed pdf java interview questions exam java interview questions experience 3 years java interview questions experience 2 years java interview questions experienced 2 years e&y java interview questions ecommerce interview questions java java interview questions for experienced candidates java interview questions for experienced pdf java interview questions for 8 years experience java interview questions for freshers 2017 java interview questions and answers f java interview questions guru99 java interview questions glassdoor java interview questions github java interview questions goldman sachs java interview questions gfg java interview questions generics java interview questions google java interview questions geekinterview java interview questions garbage collection java interview questions hcl java interview questions hibernate java interview questions howtodoinjava java interview questions hard java interview questions hcl experienced java interview questions hashmap java interview questions hibernate spring java interview questions hashcode java interview questions hashmap hashtable java interview questions high level java interview questions in pdf java interview questions in javatpoint java interview questions infosys java interview questions in hindi java interview questions in tcs java interview questions in capgemini java interview questions in oracle java interview questions in selenium java interview questions in wipro java interview questions javatpoint java interview questions javarevisited java interview questions java67 java interview questions java java interview questions java hungry java interview questions java2novice java interview questions java success java interview questions javamadesoeasy java interview questions java4s j core java interview questions jpmorgan java interview questions java interview questions koirala pdf java interview questions arun kumar pdf java interview questions on keywords java interview questions by kvr java interview questions arul kumar java interview questions pdf arul kumar java interview questions on final keyword java interview questions on this keyword java interview questions by arun kumar java interview questions on static keyword java interview questions list java interview questions latest java interview questions logical java interview questions latest 2017 java interview questions linked list java interview questions lulu pdf java interview questions linkedin java interview questions latest 2015 java interview questions list set java interview questions london l&t java interview questions l&t java interview questions for experienced l&t infotech java interview questions for experienced l&t infotech core java interview questions java interview questions mcq java interview questions multiple choice java interview questions multithreading java interview questions morgan stanley java interview questions mindtree java interview questions mp3 java interview questions mid level java interview questions memory management java interview questions map java interview questions microsoft javacodegeeks.co m/2014/04/java-interview-questions-and-answers.html java interview questions and answers pdf java interview questions and answers for freshers pdf free download model n java interview questions interview questions in java java interview questions on multithreading java interview questions on exception handling java interview questions on oops java interview questions on strings java interview questions on threads java interview questions on inheritance java interview questions on static java interview questions on abstraction java interview questions on spring java io interview questions big o java interview questions basics of java interview questions and answers basics of java interview questions and answers pdf list of java interview questions pdf of java interview questions and answers for freshers collection of java interview questions list of java interview questions and answers features of java interview questions instanceof java interview questions java interview questions programs java interview questions pdf for freshers java interview questions pdf 2017 java interview questions pdf download free java interview questions practice java interview questions ppt java interview questions pdf tutorialspoint java interview questions problem solving java interview questions pdf book java interview questions quora java interview questions quiz java interview questions quizlet java interview questions qa java interview questions questions core java interview questions questions java interview questions related to selenium java interview questions related to collections java interview questions related to android java interview questions recursion java interview questions revisited java interview questions reverse string java interview questions related to string java interview questions reddit java interview questions related to thread java interview questions roseindia r systems java interview questions r nageswara rao java interview questions r nageswara rao core java interview questions java interview questions spring java interview questions sanfoundry java interview questions string java interview questions selenium java interview questions senior java interview questions static java interview questions spring jdbc java interview questions shivprasad koirala pdf java interview questions stack overflow java interview questions spring mvc java interview questions tutorialspoint java interview questions tcs java interview questions test java interview questions tricky java interview questions threads java interview questions topic wise java interview questions tough java interview questions technical java interview questions tpoint java interview questions telephonic java t interview questions javatpoint interview questions spring interview questions javatpoint java interview questions udemy java interview questions usa java interview questions uk java interview questions youtube java interview questions for us companies java interview questions on util package infosys java interview questions usa java interview questions in uhg java interview questions asked in usa java interview questions checked and unchecked exceptions java interview questions video java interview questions verizon java interview questions volatile java interview questions vmware java interview questions vector core java interview questions video java interview questions on variables java interview questions in virtusa core java interview questions vibrant publishers pdf java interview questions static variable c++ vs java interview questions java interview questions with answers java interview questions with answers pdf java interview questions with examples java interview questions with answers pdf free download java interview questions wipro java interview questions with answers for experienced java interview questions websites java interview questions with programs java interview questions web services java interview questions with options selenium with java interview questions selenium with java interview questions and answers ajax with java interview questions cucumber with java interview questions oops with java interview questions flex with java interview questions android with java interview questions json with java interview questions selenium webdriver with java interview questions web services with java interview questions java interview questions xml java interview questions xoriant java xml interview questions and answers xebia java interview questions xavient java interview questions xerago java interview questions xchanging java interview questions xerox java interview questions xslt java interview questions xyz+java+interview questions java interview questions yahoo answers java interview questions 3 years experience java interview questions 2 years experience java interview questions 5 years experience java interview questions 4 years experience java interview questions 10 years experience java interview questions 1 year experience core java interview questions youtube java interview questions 3 years experience pdf java interview questions zycus java interview questions in zoho java interview questions new zealand zensar java interview questions zoho corp java interview questions zycus infotech java interview questions zensar technologies java interview questions a to z java interview questions zensar interview questions java experienced java interview questions trackid=sp-006 0 3 years java interview questions java interview questions 115 java interview questions 133 java interview questions 100 java interview questions 15 java interview questions 1 years experience pdf java interview questions 1 year experienced java interview questions 10 years java interview questions for 1.5 years experience java 1+ interview questions and answers 1 year java interview questions 1 year experience java interview questions java 1+ experience interview questions 1 year experienced java interview questions 1 year experience java interview questions and answers pdf 1 year experience core java interview questions and answers 1 year experienced java developer interview questions and answers java interview questions 2017 java interview questions 201 java interview questions 2016 java interview questions 2015 java interview questions 2014 java interview questions for 2.5 years experience hcl java interview questions 2014 2+ java interview questions 2+ exp java interview questions java 2+ experience interview questions pdf core java 2+ interview questions java 2 ee interview questions java 2 novice interview questions java struts2 interview questions java interview questions 3 years experience tcs java interview questions 360 java interview questions 3 years experience pdf download java interview questions 3-5 years java interview questions for 3 years experience in hcl java interview questions for 3+ experience java interview questions for 3 years experience and answer java interview questions for 3 to 4 years experience 3+ java interview questions 3+ java interview questions and answers java 3+ interview questions pdf 3 years experience java interview questions 3 years experience java interview questions and answers 3 years exp java interview questions 3 to 5 years java interview questions java interview questions 4 years java interview questions 4 years experience pdf java interview questions 4+ java interview questions for 4+ experience java interview questions for 4-5 years experience java interview questions for 4 years exp java interview questions for 3 4 years experience core java interview questions for 4 years experienced java collections interview questions for 4 years experience java interview questions and answers for 4 years experience pdf 4+ java interview questions 4 years java interview questions pdf for java interview questions and answers programs for java interview questions book for java interview questions and answers for loop java interview questions java interview questions 5 year experience java interview questions 5 years experience pdf java interview questions 500 java interview questions 50 java interview questions for 5+ java interview questions for 5+ exp java interview questions top 50 java j2ee interview questions 5 years experience 5+ java interview questions java 5 interview questions and answers for experienced java 5 interview questions and answers 5+ years java interview questions top 5 java interview questions java 5 features interview questions java 5 concurrency interview questions java 5 collections interview questions core java 5 interview questions java 5 generics interview questions java interview questions 6 years java interview questions for 6+ java interview questions for 6 months experience java interview questions for 6 years exp java interview questions for 6+ experience java 67 interview questions java 6 interview questions and answers for experienced core java interview questions for 6 years experienced java interview questions and answers for 6 years experience pdf java 6 interview questions and answers pdf java 6 interview questions java 6 interview questions generics 6+ years java interview questions java 6 features interview questions core java 6 interview questions java 6 collections interview questions java 6 thread interview questions 6+ years java j2ee interview questions java interview questions 7 years experience java j2ee interview questions 7 years experience java interview questions for 7 years experience pdf core java interview questions for 7 years experienced java interview questions and answers for 7 years experienced 700 java interview questions java telephonic interview questions for 7 years experience java collection interview questions for 7 years experience advanced java interview questions for 7 years experience oracle java interview questions for 7 years experience java 7 interview questions java 7 interview questions pdf 7+ years java interview questions java 7 features interview questions core java 7 interview questions java 7 collection interview questions java 7 concurrency interview questions java 7 multithreading interview questions java 7 and 8 interview questions java ee 7 interview questions java interview questions 8 years experience java interview questions for 8 yrs experience java interview questions java 8 java interview questions for 8 experienced core java interview questions for 8+ years java 8 interview questions and answers java 8 interview questions pdf java interview questions and answers for 8 years experienced java collections interview questions for 8 years experience java 8 interview questions and answers for experienced java 8 interview questions java 8 interview questions and answers pdf 8 years java interview questions java 8 features interview questions core java 8 interview questions java 8 stream interview questions java 8 advanced interview questions java interview questions 9 years experience java interview questions for 9 years java j2ee interview questions for 9 years experience java interview questions and answers for 9 years experience java interview questions and answers for 9 years experienced core java interview questions and answers for 9 years experience 9 years java interview questions 9 years experience java interview questions Core Java: Basics of Java Interview Questions 1) What is difference between JDK,JRE and JVM? JVM JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the runtime environment in which java bytecode can be executed. It is a specification. JVMs are available for many hardware and software platforms (so JVM is platform dependent). JRE JRE stands for Java Runtime Environment. It is the implementation of JVM. JDK JDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools. 2) How many types of memory areas are allocated by JVM? Many types: Class(Method) Area Heap Stack Program Counter Register Native Method Stack 3) What is JIT compiler? Just-In-Time(JIT) compiler:It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU. 4) What is platform? A platform is basically the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides software-based platform. 5) What is the main difference between Java platform and other platforms? The Java platform differs from most other platforms in the sense that it's a software-based platform that runs on top of other hardware-based platforms.It has two components: Runtime Environment API(Application Programming Interface) 6) What gives Java its 'write once and run anywhere' nature? The bytecode. Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platform specific and hence can be fed to any platform. 7) What is classloader? The classloader is a subsystem of JVM that is used to load classes and interfaces.There are many types of classloaders e.g. Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc. 8) Is Empty .java file name a valid source file name? Yes, save your java file by .java only, compile it by javac .java and run by java yourclassname Let's take a simple example: 1. //save by .java only 2. class A{ 3. public static void main(String args[]){ 4. System.out.println("Hello java"); 5. } 6. } 7. //compile by javac .java 8. //run by java A compile it by javac .java run it by java A 9) Is delete,next,main,exit or null keyword in java? No. 10) If I don't provide any arguments on the command line, then the String array of Main method will be empty or null? It is empty. But not null. 11) What if I write static public void instead of public static void? Program compiles and runs properly. 12) What is the default value of the local variables? The local variables are not initialized to any default value, neither primitives nor object references. Core Java - OOPs Concepts: Initial OOPs Interview Questions There is given more than 50 OOPs (Object-Oriented Programming and System) interview questions. But they have been categorized in many sections such as constructor interview questions, static interview questions, Inheritance Interview questions, Abstraction interview question, Polymorphism interview questions etc. for better understanding. 13) What is difference between object oriented programming language and object based programming language? Object based programming languages follow all the features of OOPs except Inheritance. Examples of object based programming languages are JavaScript, VBScript etc. 14) What will be the initial value of an object reference which is defined as an instance variable? The object references are all initialized to null in Java. Core Java - OOPs Concepts: Constructor Interview Questions 15) What is constructor? Constructor is just like a method that is used to initialize the state of an object. It is invoked at the time of object creation. 16) What is the purpose of default constructor? The default constructor provides the default values to the objects. The java compiler creates a default constructor only if there is no constructor in the class. 17) Does constructor return any value? Ans:yes, that is current instance (You cannot use return type yet it returns a value). 18)Is constructor inherited? No, constructor is not inherited. 19) Can you make a constructor final? No, constructor can't be final. Core Java - OOPs Concepts: static keyword Interview Questions 20) What is static variable? static variable is used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc. static variable gets memory only once in class area at the time of class loading. 21) What is static method? A static method belongs to the class rather than object of a class. A static method can be invoked without the need for creating an instance of a class. static method can access static data member and can change the value of it. 22) Why main method is static? because object is not required to call static method if It were non-static method,jvm creats object first then call main() method that will lead to the problem of extra memory allocation. 23) What is static block? Is used to initialize the static data member. It is excuted before main method at the time of classloading. 24) Can we execute a program without main() method? Ans) Yes, one of the way is static block. 25) What if the static modifier is removed from the signature of the main method? Program compiles. But at runtime throws an error "NoSuchMethodError". 26) What is difference between static (class) method and instance method? static or class method instance method 1)A method i.e. declared as static is known as static method. A method i.e. not declared as static is known as instance method. 2)Object is not required to call static method. Object is required to call instance methods. 3)Non-static (instance) members cannot be accessed in static context (static method, static block and static nested class) directly. static and non-static variables both can be accessed in instance methods. 4)For example: public static int cube(int n){ return n*n*n;} For example: public void msg(){...}. Core Java - OOPs Concepts: Inheritance Interview Questions 27) What is this in java? It is a keyword that that refers to the current object. 28)What is Inheritance? Inheritance is a mechanism in which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship. It is used for Code Resusability and Method Overriding. 29) Which class is the superclass for every class. Object class. 30) Why multiple inheritance is not supported in java? To reduce the complexity and simplify the language, multiple inheritance is not supported in java in case of class. 31) What is composition? Holding the reference of the other class within some other class is known as composition. 32) What is difference between aggregation and composition? Aggregation represents weak relationship whereas composition represents strong relationship. For example: bike has an indicator (aggregation) but bike has an engine (compostion). 33) Why Java does not support pointers? Pointer is a variable that refers to the memory address. They are not used in java because they are unsafe(unsecured) and complex to understand. 34) What is super in java? It is a keyword that refers to the immediate parent class object. 35) Can you use this() and super() both in a constructor? No. Because super() or this() must be the first statement. 36)What is object cloning? The object cloning is used to create the exact copy of an object. Core Java - OOPs Concepts: Method Overloading Interview Questions 37) What is method overloading? If a class have multiple methods by same name but different parameters, it is known as Method Overloading. It increases the readability of the program. 38) Why method overloading is not possible by changing the return type in java? Becauseof ambiguity. 39) Can we overload main() method? Yes, You can have many main() methods in a class by overloading the main method. Core Java - OOPs Concepts: Method Overriding Interview Questions 40) What is method overriding: If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. It is used for runtime polymorphism and to provide the specific implementation of the method. 41) Can we override static method? No, you can't override the static method because they are the part of class not object. 42) Why we cannot override static method? It is because the static method is the part of class and it is bound with class whereas instance method is bound with object and static gets memory in class area and instance gets memory in heap. 43) Can we override the overloaded method? Yes. 44) Difference between method Overloading and Overriding. Method Overloading Method Overriding 1) Method overloading increases the readability of the program. Method overriding provides the specific implementation of the method that is already provided by its super class. 2) method overlaoding is occurs within the class. Method overriding occurs in two classes that have IS-A relationship. 3) In this case, parameter must be different. In this case, parameter must be same. 45) Can you have virtual functions in Java? Yes, all functions in Java are virtual by default. 46) What is covariant return type? Now, since java5, it is possible to override any method by changing the return type if the return type of the subclass overriding method is subclass type. It is known as covariant return type. Core Java - OOPs Concepts: final keyword Interview Questions 47) What is final variable? If you make any variable as final, you cannot change the value of final variable(It will be constant). 48) What is final method? Final methods can't be overriden. 49) What is final class? Final class can't be inherited. 50) What is blank final variable? A final variable, not initalized at the time of declaration, is known as blank final variable. 51) Can we intialize blank final variable? Yes, only in constructor if it is non-static. If it is static blank final variable, it can be initialized only in the static block. 52) Can you declare the main method as final? Yes, such as, public static final void main(String[] args){}. Core Java - OOPs : Polymorphism Interview Questions 53) What is Runtime Polymorphism? Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a super class. The determination of the method to be called is based on the object being referred to by the reference variable. 54) Can you achieve Runtime Polymorphism by data members? No. 55) What is the difference between static binding and dynamic binding? In case of static binding type of object is determined at compile time whereas in dynamic binding type of object is determined at runtime. Core Java - OOPs Concepts : Abstraction Interview Questions 56) What is abstraction? Abstraction is a process of hiding the implementation details and showing only functionality to the user. Abstraction lets you focus on what the object does instead of how it does it. 57) What is the difference between abstraction and encapsulation? Abstraction hides the implementation details whereas encapsulation wraps code and data into a single unit. 58) What is abstract class? A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated. 59) Can there be any abstract method without abstract class? No, if there is any abstract method in a class, that class must be abstract. 60) Can you use abstract and final both with a method? No, because abstract method needs to be overridden whereas you can't override final method. 61) Is it possible to instantiate the abstract class? No, abstract class can never be instantiated. 62) What is interface? Interface is a blueprint of a class that have static constants and abstract methods.It can be used to achieve fully abstraction and multiple inheritance. 63) Can you declare an interface method static? No, because methods of an interface is abstract by default, and static and abstract keywords can't be used together. 64) Can an Interface be final? No, because its implementation is provided by another class. 65) What is marker interface? An interface that have no data member and method is known as a marker interface.For example Serializable, Cloneable etc. 66) What is difference between abstract class and interface? Abstract class Interface 1)An abstract class can have method body (non-abstract methods). Interface have only abstract methods. 2)An abstract class can have instance variables. An interface cannot have instance variables. 3)An abstract class can have constructor. Interface cannot have constructor. 4)An abstract class can have static methods. Interface cannot have static methods. 5)You can extends one abstract class. You can implement multiple interfaces. 67) Can we define private and protected modifiers for variables in interfaces? No, they are implicitly public. 68) When can an object reference be cast to an interface reference? An object reference can be cast to an interface reference when the object implements the referenced interface. Core Java - OOPs Concepts : Package Interview Questions 69) What is package? A package is a group of similar type of classes interfaces and sub-packages. It provides access protection and removes naming collision. 70) Do I need to import java.lang package any time? Why ? No. It is by default loaded internally by the JVM. 71) Can I import same package/class twice? Will the JVM load the package twice at runtime? One can import the same package or same class multiple times. Neither compiler nor JVM complains about it.But the JVM will internally load the class only once no matter how many times you import the same class. 72) What is static import ? By static import, we can access the static members of a class directly, there is no to qualify it with the class name. Java : Exception Handling Interview Questions There is given a list of exception handling interview questions with answers. If you know any exception handling interview question, kindly post it in the comment section. 73) What is Exception Handling? Exception Handling is a mechanism to handle runtime errors.It is mainly used to handle checked exceptions. 74) What is difference between Checked Exception and Unchecked Exception? 1)Checked Exception The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e.g.IOException,SQLException etc. Checked exceptions are checked at compile-time. 2)Unchecked Exception The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException,NullPointerException etc. Unchecked exceptions are not checked at compile-time. 75) What is the base class for Error and Exception? Throwable. 76) Is it necessary that each try block must be followed by a catch block? It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method. 77) What is finally block? finally block is a block that is always executed. 78) Can finally block be used without catch? Yes, by try block. finally must be followed by either try or catch. 79) Is there any case when finally will not be executed? finally block will not be executed if program exits(either by calling System.exit() or by causing a fatal error that causes the process to abort). 80) What is difference between throw and throws? throw keyword throws keyword 1)throw is used to explicitly throw an exception. throws is used to declare an exception. 2)checked exceptions can not be propagated with throw only. checked exception can be propagated with throws. 3)throw is followed by an instance. throws is followed by class. 4)throw is used within the method. throws is used with the method signature. 5)You cannot throw multiple exception You can declare multiple exception e.g. public void method()throws IOException,SQLException. 81) Can an exception be rethrown? Yes. 82) Can subclass overriding method declare an exception if parent class method doesn't throw an exception ? Yes but only unchecked exception not checked. 83) What is exception propagation ? Forwarding the exception object to the invoking method is known as exception propagation. Java: String Handling Interview Questions There is given a list of string handling interview questions with short and pointed answers. If you know any string handling interview question, kindly post it in the comment section. 84) What is the meaning of immutable in terms of String? The simple meaning of immutable is unmodifiable or unchangeable. Once string object has been created, its value can't be changed. 85) Why string objects are immutable in java? Because java uses the concept of string literal. Suppose there are 5 reference variables,all referes to one object "sachin".If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java. 86) How many ways we can create the string object? There are two ways to create the string object, by string literal and by new keyword. 87) How many objects will be created in the following code? 1. String s1="Welcome"; 2. String s2="Welcome"; 3. String s3="Welcome"; Only one object. 88) Why java uses the concept of string literal? To make Java more memory efficient (because no new objects are created if it exists already in string constant pool). 89)How many objects will be created in the following code? 1. String s = new String("Welcome"); Two objects, one in string constant pool and other in non-pool(heap). 90) What is the basic difference between string and stringbuffer object? String is an immutable object. StringBuffer is a mutable object. 91) What is the difference between StringBuffer and StringBuilder ? StringBuffer is synchronized whereas StringBuilder is not synchronized. 92) How can we create immutable class in java ? We can create immutable class as the String class by defining final class and 93) What is the purpose of toString() method in java ? The toString() method returns the string representation of any object. If you print any object, java compiler internally invokes the toString() method on the object. So overriding the toString() method, returns the desired output, it can be the state of an object etc. depends on your implementation. Core Java : Nested classes and Interfaces Interview Questions 94)What is nested class? A class which is declared inside another class is known as nested class. There are 4 types of nested class member inner class, local inner class, annonymous inner class and static nested class. 95) Is there any difference between nested classes and inner classes? Yes, inner classes are non-static nested classes i.e. inner classes are the part of nested classes. 96) Can we access the non-final local variable, inside the local inner class? No, local variable must be constant if you want to access it in local inner class. 97) What is nested interface ? Any interface i.e. declared inside the interface or class, is known as nested interface. It is static by default. 98) Can a class have an interface? Yes, it is known as nested interface. 99) Can an Interface have a class? Yes, they are static implicitely. Garbage Collection Interview Questions 117) What is Garbage Collection? Garbage collection is a process of reclaiming the runtime unused objects.It is performed for memory management. 118) What is gc()? gc() is a daemon thread.gc() method is defined in System class that is used to send request to JVM to perform garbage collection. 119) What is the purpose of finalize() method? finalize() method is invoked just before the object is garbage collected.It is used to perform cleanup processing. 120) Can an unrefrenced objects be refrenced again? Yes. 121)What kind of thread is the Garbage collector thread? Daemon thread. 122)What is difference between final, finally and finalize? final: final is a keyword, final can be variable, method or class.You, can't change the value of final variable, can't override final method, can't inherit final class. finally: finally block is used in exception handling. finally block is always executed. finalize():finalize() method is used in garbage collection.finalize() method is invoked just before the object is garbage collected.The finalize() method can be used to perform any cleanup processing. 123)What is the purpose of the Runtime class? The purpose of the Runtime class is to provide access to the Java runtime system. 124)How will you invoke any external process in Java? By Runtime.getRuntime().exec(?) method. I/O Interview Questions 125)What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy? The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented. 126)What an I/O filter? An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another. Serialization Interview Questions 127) What is serialization? Serialization is a process of writing the state of an object into a byte stream.It is mainly used to travel object's state on the network. 128) What is Deserialization? Deserialization is the process of reconstructing the object from the serialized state.It is the reverse operation of serialization. 129) What is transient keyword? If you define any data member as transient,it will not be serialized. 130)What is Externalizable? Externalizable interface is used to write the state of an object into a byte stream in compressed format.It is not a marker interface. 131)What is the difference between Serializalble and Externalizable interface? Serializable is a marker interface but Externalizable is not a marker interface.When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process. Networking Interview Questions 132)How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com? By InetAddress.getByName("192.18.97.39").getHostName() where 192.18.97.39 is the IP address. Reflection Interview Questions 133) What is reflection? Reflection is the process of examining or modifying the runtime behaviour of a class at runtime.It is used in: IDE (Integreted Development Environment) e.g. Eclipse, MyEclipse, NetBeans. Debugger Test Tools etc. 134) Can you access the private method from outside the class? Yes, by changing the runtime behaviour of a class if the class is not secured. Miscellaneous Interview Questions 148)What are wrapper classes? Wrapper classes are classes that allow primitive types to be accessed as objects. 149)What is a native method? A native method is a method that is implemented in a language other than Java. 150)What is the purpose of the System class? The purpose of the System class is to provide access to system resources. 151)What comes to mind when someone mentions a shallow copy in Java? Object cloning. 152)What is singleton class? Singleton class means that any given time only one instance of the class is present, in one JVM. AWT and SWING Interview Questions 153)Which containers use a border layout as their default layout? The Window, Frame and Dialog classes use a border layout as their default layout. 154)Which containers use a FlowLayout as their default layout? The Panel and Applet classes use the FlowLayout as their default layout. 155)What are peerless components? The peerless components are called light weight components. 156)is the difference between a Scrollbar and a ScrollPane? A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling. 157)What is a lightweight component? Lightweight components are the one which doesn?t go with the native call to obtain the graphical units. They share their parent component graphical units to render them. For example, Swing components. 158)What is a heavyweight component? For every paint call, there will be a native call to get the graphical units.For Example, AWT. 159)What is an applet? An applet is a small java program that runs inside the browser and generates dynamic contents. 160)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. Internationalization Interview Questions 161)What is Locale? A Locale object represents a specific geographical, political, or cultural region. 162)How will you load a specific locale? By ResourceBundle.getBundle(?) method. Java Bean Interview Questions 163)What is a JavaBean? are reusable software components written in the Java programming language, designed to be manipulated visually by a software development environment, like JBuilder or VisualAge for Java. RMI Interview Questions 164)Can RMI and Corba based applications interact? Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP. Java Multithreading Interview Questions Multithreading and Synchronization is considered as the typical chapter in java programming. In game development company, mulithreading related interview questions are asked mostly. A list of frequently asked java multithreading interview questions are given below. 1) What is multithreading? Multithreading is a process of executing multiple threads simultaneously. Its main advantage is: Threads share the same address space. Thread is lightweight. Cost of communication between process is low. 2) What is thread? A thread is a lightweight subprocess.It is a separate path of execution.It is called separate path of execution because each thread runs in a separate stack frame. 3)What is the difference between preemptive scheduling and time slicing? Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors. 4) What does join() method? The join() method waits for a thread to die. In other words, it causes the currently running threads to stop executing until the thread it joins with completes its task. 5) What is difference between wait() and sleep() method? wait() sleep() 1) The wait() method is defined in Object class. The sleep() method is defined in Thread class. 2) wait() method releases the lock. The sleep() method doesn't releases the lock. 6) Is it possible to start a thread twice? No, there is no possibility to start a thread twice. If we does, it throws an exception. 7) Can we call the run() method instead of start()? yes, but it will not work as a thread rather it will work as a normal object so there will not be context-switching between the threads. 8) What about the daemon threads? The daemon threads are basically the low priority threads that provides the background support to the user threads. It provides services to the user threads. 9)Can we make the user thread as daemon thread if thread is started? No, if you do so, it will throw IllegalThreadStateException 10)What is shutdown hook? The shutdown hook is basically a thread i.e. invoked implicitely before JVM shuts down. So we can use it perform clean up resource. 11)When should we interrupt a thread? We should interrupt a thread if we want to break out the sleep or wait state of a thread. 12) What is synchronization? Synchronization is the capabilility of control the access of multiple threads to any shared resource.It is used: To prevent thread interference. To prevent consistency problem. 13) What is the purpose of Synchronized block? Synchronized block is used to lock an object for any shared resource. Scope of synchronized block is smaller than the method. 14)Can Java object be locked down for exclusive use by a given thread? Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it. 15) What is static synchronization? If you make any static method as synchronized, the lock will be on the class not on object. 16)What is the difference between notify() and notifyAll()? The notify() is used to unblock one waiting thread whereas notifyAll() method is used to unblock all the threads in waiting state. 17)What is deadlock? Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread. Java Collections Interview Questions In java, collection interview questions are mostly asked by the interviewers. Here is the list of mostly asked collections interview questions with answers. 1) What is the difference between ArrayList and Vector? No. ArrayList Vector 1) ArrayList is not synchronized. Vector is synchronized. 2) ArrayList is not a legacy class. Vector is a legacy class. 3) ArrayList increases its size by 50% of the array size. Vector increases its size by doubling the array size. 2) What is the difference between ArrayList and LinkedList? No. ArrayList LinkedList 1) ArrayList uses a dynamic array. LinkedList uses doubly linked list. 2) ArrayList is not efficient for manipulation because a lot of shifting is required. LinkedList is efficient for manipulation. 3) ArrayList is better to store and fetch data. LinkedList is better to manipulate data. 3) What is the difference between Iterator and ListIterator? Iterator traverses the elements in forward direction only whereas ListIterator traverses the elements in forward and backward direction. No. Iterator ListIterator 1) Iterator traverses the elements in forward direction only. ListIterator traverses the elements in backward and forward directions both. 2) Iterator can be used in List, Set and Queue. ListIterator can be used in List only. 4) What is the difference between Iterator and Enumeration? No. Iterator Enumeration 1) Iterator can traverse legacy and non-legacy elements. Enumeration can traverse only legacy elements. 2) Iterator is fail-fast. Enumeration is not fail-fast. 3) Iterator is slower than Enumeration. Enumeration is faster than Iterator. 5) What is the difference between List and Set? List can contain duplicate elements whereas Set contains only unique elements. 6) What is the difference between HashSet and TreeSet? HashSet maintains no order whereas TreeSet maintains ascending order. 7) What is the difference between Set and Map? Set contains values only whereas Map contains key and values both. 8) What is the difference between HashSet and HashMap? HashSet contains only values whereas HashMap contains entry(key,value). HashSet can be iterated but HashMap need to convert into Set to be iterated. 9) What is the difference between HashMap and TreeMap? HashMap maintains no order but TreeMap maintains ascending order. 10) What is the difference between HashMap and Hashtable? No. HashMap Hashtable 1) HashMap is not synchronized. Hashtable is synchronized. 2) HashMap can contain one null key and multiple null values. Hashtable cannot contain any null key or null value. 11) What is the difference between Collection and Collections? Collection is an interface whereas Collections is a class. Collection interface provides normal functionality of data structure to List, Set and Queue. But, Collections class is to sort and synchronize collection elements. 12) What is the difference between Comparable and Comparator? No. Comparable Comparator 1) Comparable provides only one sort of sequence. Comparator provides multiple sort of sequences. 2) It provides one method named compareTo(). It provides one method named compare(). 3) It is found in java.lang package. it is found in java.util package. 4) If we implement Comparable interface, actual class is modified. Actual class is not modified. 13) What is the advantage of Properties file? If you change the value in properties file, you don't need to recompile the java class. So, it makes the application easy to manage. 14) What does the hashCode() method? The hashCode() method returns a hash code value (an integer number). The hashCode() method returns the same integer number, if two keys (by calling equals() method) are same. But, it is possible that two hash code numbers can have different or same keys. 15) Why we override equals() method? The equals method is used to check whether two objects are same or not. It needs to be overridden if we want to check the objects based on property. For example, Employee is a class that has 3 data members: id, name and salary. But, we want to check the equality of employee object on the basis of salary. Then, we need to override the equals() method. 16) How to synchronize List, Set and Map elements? Yes, Collections class provides methods to make List, Set or Map elements as synchronized: public static List synchronizedList(List l){} public static Set synchronizedSet(Set s){} public static SortedSet synchronizedSortedSet(SortedSet s){} public static Map synchronizedMap(Map m){} public static SortedMap synchronizedSortedMap(SortedMap m){} 17) What is the advantage of generic collection? If we use generic class, we don't need typecasting. It is typesafe and checked at compile time. 18) What is hash-collision in Hashtable and how it is handled in Java? Two different keys with the same hash value is known as hash-collision. Two different entries will be kept in a single hash bucket to avoid the collision. 19) What is the Dictionary class? The Dictionary class provides the capability to store key-value pairs. 20) What is the default size of load factor in hashing based collection? The default size of load factor is 0.75. The default capacity is computed as initial capacity * load factor. For example, 16 * 0.75 = 12. So, 12 is the default capacity of Map. JDBC Interview Questions A list of frequently asked jdbc interview questions with answers are given below. 1) What is JDBC? JDBC is a Java API that is used to connect and execute query to the database. JDBC API uses jdbc drivers to connects to the database. 2) What is JDBC Driver? JDBC Driver is a software component that enables java application to interact with the database.There are 4 types of JDBC drivers: JDBC-ODBC bridge driver Native-API driver (partially java driver) Network Protocol driver (fully java driver) Thin driver (fully java driver) 3) What are the steps to connect to the database in java? Registering the driver class Creating connection Creating statement Executing queries Closing connection 4) What are the JDBC API components? The java.sql package contains interfaces and classes for JDBC API. Interfaces: Connection Statement PreparedStatement ResultSet ResultSetMetaData DatabaseMetaData CallableStatement etc. Classes: DriverManager Blob Clob Types SQLException etc. 5) What are the JDBC statements? There are 3 JDBC statements. Statement PreparedStatement CallableStatement 6) What is the difference between Statement and PreparedStatement interface? In case of Statement, query is complied each time whereas in case of PreparedStatement, query is complied only once. So performance of PreparedStatement is better than Statement. 7) How can we execute stored procedures and functions? By using Callable statement interface, we can execute procedures and functions. 8) What is the role of JDBC DriverManager class? The DriverManager class manages the registered drivers. It can be used to register and unregister drivers. It provides factory method that returns the instance of Connection. 9) What does the JDBC Connection interface? The Connection interface maintains a session with the database. It can be used for transaction management. It provides factory methods that returns the instance of Statement, PreparedStatement, CallableStatement and DatabaseMetaData. 10) What does the JDBC ResultSet interface? The ResultSet object represents a row of a table. It can be used to change the cursor pointer and get the information from the database. 11) What does the JDBC ResultSetMetaData interface? The ResultSetMetaData interface returns the information of table such as total number of columns, column name, column type etc. 12) What does the JDBC DatabaseMetaData interface? The DatabaseMetaData interface returns the information of the database such as username, driver name, driver version, number of tables, number of views etc. 13) Which interface is responsible for transaction management in JDBC? The Connection interface provides methods for transaction management such as commit(), rollback() etc. 14) What is batch processing and how to perform batch processing in JDBC? By using batch processing technique in JDBC, we can execute multiple queries. It makes the performance fast. 15) How can we store and retrieve images from the database? By using PreparedStatement interface, we can store and retrieve images.
http://www.techgig.com/files/photo_1451291787_temp.jpg
SolutionRider- One Stop Solution for Notes, Exams Prep, Jobs & Technical Blogs.
https://thesolutionrider.blogspot.com/2017/11/core-java-interview-questions.html
https://thesolutionrider.blogspot.com/
https://thesolutionrider.blogspot.com/
https://thesolutionrider.blogspot.com/2017/11/core-java-interview-questions.html
true
6820083649286484786
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy