Interview Questions and Answers - Order By Newest Q1461. How is it possible to use concat on string objects in Java, based on the fact that string is immutable? Core Java
Ans. It's possible because internally java first reserves the memory for the new concatenated string and then copy that over. So after concatenation, there are 2 strings in memory, the original one and the concatenated one and then the reference is moved to the concatenated string. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1462. Difference between static and dynamic memory allocation ? 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   Q1463. Why Arrays are considered as data structures whereas ArrayList isn't ? 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   Q1464. Are Arrays a data structure or a collection class ? 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   Q1465. Which Java version supports Interface Default methods ? Core Java
Ans. Java 1.8 or Java 8 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  default methods   interface default methods   java 8  java 8 features Q1466. Tell something about Sleep method. Core Java
This question was recently asked at 'IBM'.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  Thread  sleep  multithreading Asked in 1 Companies Basic Q1467. Diff between Runtime.getRunTime().gc() and System.gc() Core Java
This question was recently asked at 'CIGNEX Datamatics'.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 Q1468. How to run jar file using command prompt Core Java
This question was recently asked at 'CIGNEX Datamatics'.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  jar  running jar using command line  cron entry   setting java app as cron Asked in 1 Companies Q1469. Can we call a static method using reference currently pointing to null. Core Java
Ans. yes, we can.
exa: public class Java{
public static void main(String... args) {
JAva j= null;
j.greeting(); // call with null reference
}
public static void greeting() {
System.out.println("Hello World");
}
} // output: Hello World Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  static methods   static Asked in 1 Companies Q1470. Which memory segment holds the byte code ? Core Java
Ans. Code Segment Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Memory Management  Code Memory Segment  Code Segment Memory  Code Segment Q1471. Is this array declaration correct ? If not , Why ?
String[] strArray = new String[]; Core Java
Ans. No, We haven't specified the size of array to be initialized. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays  array initialization Q1472. Is this array initialization correct ? If Yes, What will be the size of array ?
String[] strArray = new String[]{"Buggy","Bread"}; Core Java
Ans. Yes, size of the array will be 2. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays  array initialization Q1473. Is this array initialization correct ? If Yes, What will be the size of array ?
String[] strArray = new String[3]{"Buggy","Bread"}; Core Java
Ans. No. It will result in error saying "Cannot define dimension expressions when an array initializer is provided" Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays  array initialization Q1474. Is this code valid
String[] strArray = new String[2];
strArray.length = 5; Core Java
Ans. It will give compile time error saying "The final field array.length cannot be assigned"
Arrays once initialized cannot be resized. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays  array initialization Q1475. What is the problem with this code
String[] strArray = new String[2];
strArray[0] = 5; Core Java
Ans. We are trying to add an integer element to an array of String. Will give compile time error. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays Q1476. Will this give compile time error ?
Object[] strArray = new String[2];
strArray[0] = 5; Core Java
Ans. No. But It will throw ArrayStoreException at runtime. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ArrayStoreException  arraysAns. Assigning a value of one type to a variable of another type is known as Type Casting.
Example :
int x = 10;
byte y = (byte)x;
In Java, type casting is classified into two types, Widening Casting(Implicit) widening-type-conversion and Narrowing Casting (Explicitly done) narrowing-type-conversion.
Widening or Automatic type converion - Automatic Type casting take place when,the two types are compatible and the target type is larger than the source type
Example :
public class Test {
public static void main(String[] args) {
int i = 100;
long l = i; //no explicit type casting required
float f = l;//no explicit type casting required
System.out.println("Int value " i);
System.out.println("Long value " l);
System.out.println("Float value " f);
}
}
Narrowing or Explicit type conversion - When you are assigning a larger type value to a variable of smaller type, then you need to perform explicit type casting.
Example :
public class Test{
public static void main(String[] args) {
double d = 100.04;
long l = (long)d; //explicit type casting required
int i = (int)l;//explicit type casting required
System.out.println("Double value " d);
System.out.println("Long value " l);
System.out.println("Int value " i);
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  typecasting  type casting Asked in 23 Companies Q1478. What is the biggest Design problem in Java ? 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   Q1479. Write a java program to find the maximum profit in day trading Core Java
This question was recently asked at 'Capital One'.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 Q1480. What are basic functions of OOPS ? Core Java
This question was recently asked at 'Zillious'.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 Q1481. Where to use interface and abstract class ? Core Java
This question was recently asked at 'Exterro,Equator Business Solutions'.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 2 Companies Q1482. Does Java SE has Immutable collections ? Core Java
Ans. Yes wef from Java 9 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java 9  java9  immutable  immutability collections Q1483. Can you write immutable class without final? Core Java
Ans. By making the constructor private Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q1484. 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 Q1485. 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 Q1486. 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 Q1487. 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 Q1488. 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 Q1489. 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 Q1490. 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