Interview Questions and Answers - Order By Rating Ans. When you declare a member/variable as volatile, you are forcing threads to read values from main memory instead of thread memory.
When you declare as atomic, the read and update/write operations are performed as a single unit. A lock is acquired during atomic operation. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 2 Companies Q162. serialization and deserialization of singleton class Core Java
Ans. The problem with serialized singleton class is that whenever we deserialize it, it will create a new instance of the class. To overcome this scenario all we need to do is to provide the implementation of readResolve() method. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  singleton  serialization Asked in 1 Companies Q163. Can a double value be cast to a byte ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q164. How do you convert List to Array ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q165. Explain briefly about Queue Interface ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  queue This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  strictfp Q167. What is the Main Advantage of the native Key Word? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  native keyword Q168. What is doCallRealMethod() method used for ? PowerMock
Ans. When we Mock an object and then make a reference to any method using mocked object reference , java never makes a call to that method and looks for mocked value to be returned or null if none specified. But If we want that to be overridden and want java to make actual method call upon using mocked object reference, this method can be used. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  junit  mocking  java unit testing  Mockito Q169. What does the following code
MockitoAnnotations.initMocks(this); Mockito
Ans. Initializes objects annotated with Mockito annotations Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  mocking  java mocking frameworks  Mockito Q170. Why is Java platform independent ? Core Java
Ans. Platform independent language means once compiled you can execute the program on any platform (OS). Java is platform independent. Because the Java compiler converts the source code to bytecode, which is Intermediate Language. Bytecode can be executed on any platform (OS) using JVM( Java Virtual Machine). Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q171. What is the difference between the 'A' and "A" in Java ? Core Java
Ans. 'A' is a character whereas "A" is a String. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  C++ vs Java Q173. Does Hashtable in Java use stack operation ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q174. Differences between class not found exception and noclassdef found error ? Core Java
Ans. ClassNotFoundException is an exception that occurs when we try to load a class at run time using Class.forName() or loadClass() methods and mentioned classes are not found in the classpath.
NoClassDefFoundError is an error that occurs when a particular class is present at compile time, but was missing at run time. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exception handling  ClassNotFoundException  NoClassDefFoundError Asked in 1 Companies This question was recently asked at 'Amber Road'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q176. What is type script ? What are the advantages of typescript ? How is it different than javascript ? TypeScript
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Typescript vs Javascript Q177. What is the use of final String when Strings are immutable ? Core Java
This question was recently asked at 'Cyient'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string Asked in 1 Companies Q178. How can we check class file format in java ? Core Java
This question was recently asked at 'Jagan Institute of Management Studies (JIMS)'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q179. Why string pool concept has been introduced in string ? Core Java
Ans. Memory Sharing and Optimal memory utilization. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  String Pool Asked in 1 Companies Q180. What will the following code print upon executing main method of Main class
public class BaseClass {
BaseClass(){
this(2);
System.out.println("Hello I am in Base Class Constructor");
}
BaseClass(int i){
System.out.println("Hello I am in Base Class int argument Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Hello I am in Base Class int argument Constructor
Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q181. What will the following code print upon executing main method of Main class
public class BaseClass {
BaseClass(){
this(2);
System.out.println("Hello I am in Base Class Constructor");
}
BaseClass(int i){
System.out.println("Hello I am in Base Class int argument Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
super(1);
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Hello I am in Base Class int argument Constructor
Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q182. Why line 4 in this code gives error saying "Cannot be referenced from a static context" ?
public class OuterClass {
public static void main(String[] args){
InnerClass innerClass = new InnerClass();
}
class InnerClass {
}
} Core Java
Ans. InnerClass is a non static inner class and hence can only be instantiated using instance of the outer class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inner class Q183. What will the following code print upon executing main method of Main class ?
public class BaseClass {
BaseClass(int x){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
super(1);
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q184. What will the following code print upon executing main method of Main class ?
public class BaseClass {
BaseClass(int x){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Compilation error as there is no default constructor available in BaseClass. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q185. What will the following code print upon executing main method of Main class ?
public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
super();
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
}
Core Java
Ans. There will be compilation error within constructor of Derived Class as "super must be the first statement in constructor body". Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q186. What will the following print upon executing main method of Main class ?
public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q187. Will it print the message in Base Class constructor if we execute main method of Main class ? why ?
public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Yes.
When the Derived class constructor is initialized , a no argument super will be called intrinsically. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q188. Isnt the use of HashTable and ConcurrentHashMap the same, i.e providing synchronized map collection ? Core Java
Ans. Both provide the thread safety but the actual difference come when talk about performance. CHM gives best performance when no of writer threads are less in number. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  synchronized collections  hashtable  ConcurrentHashMap Asked in 1 Companies Q189. Can we use try within catch block ? Core Java
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q190. Is java fully platform independent ? Core Java
Ans. yes, Java is a class-based and object-oriented programming language. It is a platform-independent language i.e. the compiled code can be run on any java supporting platform. It runs on the logic of “Write once, run anywhere”. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies